开源语音合成模型SparkTTS使用

一、环境配置

复制代码
git clone https://github.com/SparkAudio/Spark-TTS.git

pip install -r requirements.txt

二、模型下载

从modelscope进行下载,pip install modelscope

创建一个download.py

复制代码
import torch

from modelscope import snapshot_download

snapshot_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" || exit

source 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中看到对于这些参数的说明,但是这几个参数要一起加才能用,否则会报错

相关推荐
是上好佳佳佳呀1 分钟前
【前端(十二)】JavaScript 函数与对象笔记
前端·javascript·笔记
无忧.芙桃2 分钟前
C++IO库的超详细讲解
开发语言·c++
朗迹 - 张伟9 分钟前
用AI开发QT——Qt与Trae开发环境搭建
开发语言·qt·策略模式
雨辰AI12 分钟前
从 MySQL 迁移至人大金仓 V9 完整改造指南|分页 / 函数 / 语法兼容全部解决
java·开发语言·数据库·后端·mysql·政务
你真的快乐吗16 分钟前
@fuxishi/svg-icon:一个 Vue 3 svg本地图标+iconify图标组件库,让图标管理不再头疼
前端·vue.js·typescript
MATLAB代码顾问18 分钟前
改进鲸鱼优化算法(IWOA)求解柔性作业车间调度问题(FJSP)——附MATLAB代码
开发语言·算法·matlab
Rkgua22 分钟前
ESModule和Commonjs模块的区别
前端·javascript
江南十四行22 分钟前
ReAct Agent 基本理论与项目实战(二)
前端·react.js·前端框架
用户6000718191028 分钟前
【翻译】React 如何乱序流式输出 UI,却仍保持最终顺序
前端
阿里嘎多学长36 分钟前
2026-05-03 GitHub 热点项目精选
开发语言·程序员·github·代码托管