当前位置: 首页 > news >正文

开源语音合成模型SparkTTS使用

一、环境配置

git clone https://github.com/SparkAudio/Spark-TTS.git
pip install -r requirements.txt

二、模型下载

从modelscope进行下载,pip install modelscope

创建一个download.py

import torchfrom modelscope import snapshot_downloadsnapshot_download("SparkAudio/Spark-TTS-0.5B", local_dir="SparkAudio/Spark-TTS-0.5B")

执行python download.py进行下载。 

三、使用

在example文件夹下能够看到infer脚本文件,

#!/bin/bash# Copyright (c) 2025 SparkAudio
#               2025 Xinsheng Wang (w.xinshawn@gmail.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.# Get the absolute path of the script's directory
script_dir=$(dirname "$(realpath "$0")")# Get the root directory
root_dir=$(dirname "$script_dir")# Set default parameters
device=0
save_dir='example/results'
model_dir="pretrained_models/Spark-TTS-0.5B"
text="身临其境,换新体验。塑造开源语音合成新范式,让智能语音更自然。"
prompt_text="吃燕窝就选燕之屋,本节目由26年专注高品质燕窝的燕之屋冠名播出。豆奶牛奶换着喝,营养更均衡,本节目由豆本豆豆奶特约播出。"
prompt_speech_path="example/prompt_audio.wav"# Change directory to the root directory
cd "$root_dir" || exitsource sparktts/utils/parse_options.sh# Run inference
python -m cli.inference \--text "${text}" \--device "${device}" \--save_dir "${save_dir}" \--model_dir "${model_dir}" \--prompt_text "${prompt_text}" \--prompt_speech_path "${prompt_speech_path}"

运行

bash infer.sh

能够成功合成语音,参数所表示的意思对应如下:

text    需要克隆语音所对应的文本
device    指定显卡编号
save_dir    克隆语音的保存路径
model_dir    大模型的保存路径
prompt_text    样本语音的文本信息
prompt_speech_path    样本语音的保存路径

python -m cli.inference \--text "你好" \--device 0 \--save_dir "result" \--model_dir pretrained_models/Spark-TTS-0.5B \--prompt_text "吃燕窝就选燕之屋,本节目由26年专注高品质燕窝的燕之屋冠名播出。豆奶牛奶换着喝,营养更均衡,本节目由豆本豆豆奶特约播出。" \--prompt_speech_path "example/prompt_audio.wav"

如果想要改变声音的性别,音调,速度,可以在infer.sh中看到对于这些参数的说明,但是这几个参数要一起加才能用,否则会报错

相关文章:

  • 深入理解 React 组件的生命周期:从创建到销毁的全过程
  • Java性能剖析工具箱
  • dbc文件解析CAN报文注意项
  • 四、探索LangChain:连接语言模型与外部世界的桥梁
  • 模板详细介绍
  • TPshop项目-服务器环境部署(部署环境/服务,检查部署环境/服务,上传TPshop项目到服务器,配置文件的更改,安装TPshop)
  • nodejs使用pkg打包文件
  • DeepSeek在数据仓库的10大应用场景
  • 【C】初阶数据结构11 -- 选择排序
  • STM32 时钟树
  • 【fisco bcos】基于ABI调用智能合约
  • Genspark:重新定义AI搜索与代理的全能型工具
  • 黑马商城项目(三)微服务
  • Flutter 常用命令
  • 集成学习基础应用实践
  • [王阳明代数讲义]晏殊几何匹配知识图谱初步
  • 顺序表和链表,时间和空间复杂度--数据结构初阶(1)(C/C++)
  • 第一节:Vben Admin 最新 v5.0初体验
  • 视频监控EasyCVR视频汇聚平台接入海康监控摄像头如何配置http监听功能?
  • 华清远见STM32F103智能小车重磅上线!循迹避障红外遥控WiFi远程控制,0基础小白从入门到单片机软硬件项目实战!
  • 查幽门螺杆菌的这款同位素长期被海外垄断,秦山核电站实现突破
  • 跨越三十年友情,61岁余隆和60岁齐默尔曼在上海再度合作
  • 习近平在第三十五个全国助残日到来之际作出重要指示
  • 李峰已任上海青浦区委常委
  • 选址江南制造总局旧址,上海工业博物馆建设有新进展
  • 上海黄浦江挡潮闸工程建设指挥部成立,组成人员名单公布