语言合成模型Spark-TTS-0.5B学习笔记

语言合成模型Spark-TTS-0.5B学习笔记

语言合成是通过计算机技术将文字信息转换为自然流畅的语音输出,模拟人类语音。

一、下载Spark-TTS-0.5B项目

下载链接: https://github.com/SparkAudio/Spark-TTS.git

注:需要科学网络。

进入Spark-TTS文件夹,启动命令行窗口。

创建 Conda 环境:

bash 复制代码
conda create -n sparktts -y python=3.12

激活虚拟环境

bash 复制代码
conda activate sparktts

安装依赖

bash 复制代码
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com

显示一个报错

bash 复制代码
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
numba 0.61.0 requires numpy<2.2,>=1.24, but you have numpy 2.2.3 which is incompatible.

这是numpy版本不兼容的问题,强制安装兼容版本即可。

二、预训练模型下载

git指令下载

bash 复制代码
mkdir -p pretrained_models

# Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install

git clone https://huggingface.co/SparkAudio/Spark-TTS-0.5B pretrained_models/Spark-TTS-0.5B

三、启用脚本实现语音克隆

语音克隆:根据参考声音和指定文本,生成参考声音的说话声音(内容为指定文本)。

bash 复制代码
cd example
bash infer.sh

这里的example就是项目中的example目录。

infer.sh是一个脚本。

可以通过修改脚本内的内容,来修改参考声音、指定文本、模型等等。

打开infer.sh,以下为infer.sh内容:

bash 复制代码
# 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}"
    

其中需要关注的点在于:

  1. text变量中的内容,为你想生成的声音,说的是什么内容。
  2. prompt_speech_path变量中的内容,存放的是参考音频的地址
  3. prompt_text变量是,参考音频说话的文本内容是什么。
  4. save_dir变量中的内容为最终生成的声音文件存放在什么地址。
  5. model_dir变量中的内容为使用的模型存放在什么地址。

根据自己的需求进行更改,即可很好地实现声音克隆。

相关推荐
Hhy_110724 分钟前
《C++深度解构02》类和对象(上)——定义规范、内存对齐与 this 指针全解
c语言·开发语言·c++·学习·visual studio
水水不水啊28 分钟前
DeepSeek自带的一些插件的功能介绍
笔记·ai·deepseek·harness·dsh
我爱cope32 分钟前
【计算机网络 | 数据链路层3:MAC 地址是什么?它和 IP 地址有什么区别?】
学习·tcp/ip·计算机网络·智能路由器·数据链路层
电子云与长程纠缠43 分钟前
UE5 Lyra PocketWorld进行3D内容UI预览 - 下
开发语言·学习·游戏·ui·ue5
poiu12346571 小时前
视频离线观看用什么软件方便?2026多场景工具实测对比
学习
爱编程的Zion1 小时前
Jenkins 从 0 到 1 学习笔记
笔记·学习·jenkins
不会代码的小猴1 小时前
2. 了解Qt
开发语言·c++·笔记·qt·算法
hsjiasb10 小时前
FreeRTOS学习(二十七)——任务栈与栈溢出检测
开发语言·stm32·学习·学习笔记·freertos
小弥儿10 小时前
GitHub今日热榜 | 2026-08-16:大模型微调与编码工具扎堆
学习·开源·github
2501_9269783311 小时前
AGI 的四种瓶颈:资源型还是发现型--以及DSH的位置
人工智能·经验分享·笔记·ai写作