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

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

相关推荐
肌肉娃子3 天前
20260227.spark.Spark 性能刺客:千万别在 for 循环里写 withColumn
spark
西岸行者4 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
starlaky4 天前
Django入门笔记
笔记·django
勇气要爆发4 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
B站计算机毕业设计超人4 天前
计算机毕业设计Django+Vue.js音乐推荐系统 音乐可视化 大数据毕业设计 (源码+文档+PPT+讲解)
大数据·vue.js·hadoop·python·spark·django·课程设计
十月南城4 天前
数据湖技术对比——Iceberg、Hudi、Delta的表格格式与维护策略
大数据·数据库·数据仓库·hive·hadoop·spark
悠哉悠哉愿意4 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发4 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
别催小唐敲代码4 天前
嵌入式学习路线
学习
qianshanxue114 天前
计算机操作的一些笔记标题
笔记