语言合成模型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变量中的内容为使用的模型存放在什么地址。

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

相关推荐
光影少年2 分钟前
angular生态及学习路线
前端·学习·angular.js
汇能感知2 小时前
光谱相机的探测器阵列
经验分享·笔记·科技
CHHC18802 小时前
vSIM / SoftSIM笔记
笔记
逆小舟4 小时前
【C/C++】指针
c语言·c++·笔记·学习
武文斌774 小时前
项目学习总结:LVGL图形参数动态变化、开发板的GDB调试、sqlite3移植、MQTT协议、心跳包
linux·开发语言·网络·arm开发·数据库·嵌入式硬件·学习
递归不收敛5 小时前
吴恩达机器学习课程(PyTorch适配)学习笔记:1.3 特征工程与模型优化
pytorch·学习·机器学习
kunge1v55 小时前
学习爬虫第四天:多任务爬虫
爬虫·python·学习·beautifulsoup
哲Zheᗜe༘5 小时前
了解学习MySQL数据库基础
数据库·学习·mysql
peter67687 小时前
pandas学习小结
学习·pandas
机器视觉知识推荐、就业指导7 小时前
STM32 外设驱动模块【含代码】:SG90 舵机模块
stm32·单片机·嵌入式硬件·学习