tortoise-tts README

The project's README from github.com/neonbjb/tortoise-tts. As one markdown file: README.md.

TorToiSe

Tortoise is a text-to-speech program built with the following priorities:

  1. Strong multi-voice capabilities.
  2. Highly realistic prosody and intonation.

This repo contains all the code needed to run Tortoise TTS in inference mode.

Manuscript: https://arxiv.org/abs/2305.07243

Hugging Face space

A live demo is hosted on Hugging Face Spaces. If you'd like to avoid a queue, please duplicate the Space and add a GPU. Please note that CPU-only spaces do not work for this demo.

https://huggingface.co/spaces/Manmay/tortoise-tts

Install via pip

pip install tortoise-tts

If you would like to install the latest development version, you can also install it directly from the git repository:

pip install git+https://github.com/neonbjb/tortoise-tts

What's in a name?

I'm naming my speech-related repos after Mojave desert flora and fauna. Tortoise is a bit tongue in cheek: this model is insanely slow. It leverages both an autoregressive decoder and a diffusion decoder; both known for their low sampling rates. On a K80, expect to generate a medium sized sentence every 2 minutes.

well..... not so slow anymore now we can get a 0.25-0.3 RTF on 4GB vram and with streaming we can get < 500 ms latency !!!

Demos

See this page for a large list of example outputs.

A cool application of Tortoise + GPT-3 (not affiliated with this repository): https://twitter.com/lexman_ai. Unfortunately, this project seems no longer to be active.

Usage guide

Local installation

If you want to use this on your own computer, you must have an NVIDIA GPU.

[!TIP] On Windows, I highly recommend using the Conda installation method. I have been told that if you do not do this, you will spend a lot of time chasing dependency problems.

First, install miniconda: https://docs.conda.io/en/latest/miniconda.html

Then run the following commands, using anaconda prompt as the terminal (or any other terminal configured to work with conda)

This will:

  1. create conda environment with minimal dependencies specified
  2. activate the environment
  3. install pytorch with the command provided here: https://pytorch.org/get-started/locally/
  4. clone tortoise-tts
  5. change the current directory to tortoise-tts
  6. run tortoise python setup install script
conda create --name tortoise python=3.9 numba inflect
conda activate tortoise
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
conda install transformers=4.29.2
git clone https://github.com/neonbjb/tortoise-tts.git
cd tortoise-tts
python setup.py install

Optionally, pytorch can be installed in the base environment, so that other conda environments can use it too. To do this, simply send the conda install pytorch... line before activating the tortoise environment.

[!NOTE]
When you want to use tortoise-tts, you will always have to ensure the tortoise conda environment is activated.

If you are on windows, you may also need to install pysoundfile: conda install -c conda-forge pysoundfile

Docker

An easy way to hit the ground running and a good jumping off point depending on your use case.

git clone https://github.com/neonbjb/tortoise-tts.git
cd tortoise-tts

docker build . -t tts

docker run --gpus all \
    -e TORTOISE_MODELS_DIR=/models \
    -v /mnt/user/data/tortoise_tts/models:/models \
    -v /mnt/user/data/tortoise_tts/results:/results \
    -v /mnt/user/data/.cache/huggingface:/root/.cache/huggingface \
    -v /root:/work \
    -it tts

This gives you an interactive terminal in an environment that's ready to do some tts. Now you can explore the different interfaces that tortoise exposes for tts.

For example:

cd app
conda activate tortoise
time python tortoise/do_tts.py \
    --output_path /results \
    --preset ultra_fast \
    --voice geralt \
    --text "Time flies like an arrow; fruit flies like a bananna."

Apple Silicon

On macOS 13+ with M1/M2 chips you need to install the nighly version of PyTorch, as stated in the official page you can do:

pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu

Be sure to do that after you activate the environment. If you don't use conda the commands would look like this:

python3.10 -m venv .venv
source .venv/bin/activate
pip install numba inflect psutil
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu
pip install transformers
git clone https://github.com/neonbjb/tortoise-tts.git
cd tortoise-tts
pip install .

Be aware that DeepSpeed is disabled on Apple Silicon since it does not work. The flag --use_deepspeed is ignored. You may need to prepend PYTORCH_ENABLE_MPS_FALLBACK=1 to the commands below to make them work since MPS does not support all the operations in Pytorch.

do_tts.py

This script allows you to speak a single phrase with one or more voices.

python tortoise/do_tts.py --text "I'm going to speak this" --voice random --preset fast

do socket streaming

python tortoise/socket_server.py 

will listen at port 5000

faster inference read.py

This script provides tools for reading large amounts of text.

python tortoise/read_fast.py --textfile <your text to be read> --voice random

read.py

This script provides tools for reading large amounts of text.

python tortoise/read.py --textfile <your text to be read> --voice random

This will break up the textfile into sentences, and then convert them to speech one at a time. It will output a series of spoken clips as they are generated. Once all the clips are generated, it will combine them into a single file and output that as well.

Sometimes Tortoise screws up an output. You can re-generate any bad clips by re-running read.py with the --regenerate argument.

API

Tortoise can be used programmatically, like so:

reference_clips = [utils.audio.load_audio(p, 22050) for p in clips_paths]
tts = api.TextToSpeech()
pcm_audio = tts.tts_with_preset("your text here", voice_samples=reference_clips, preset='fast')

To use deepspeed:

reference_clips = [utils.audio.load_audio(p, 22050) for p in clips_paths]
tts = api.TextToSpeech(use_deepspeed=True)
pcm_audio = tts.tts_with_preset("your text here", voice_samples=reference_clips, preset='fast')

To use kv cache:

reference_clips = [utils.audio.load_audio(p, 22050) for p in clips_paths]
tts = api.TextToSpeech(kv_cache=True)
pcm_audio = tts.tts_with_preset("your text here", voice_samples=reference_clips, preset='fast')

To run model in float16:

reference_clips = [utils.audio.load_audio(p, 22050) for p in clips_paths]
tts = api.TextToSpeech(half=True)
pcm_audio = tts.tts_with_preset("your text here", voice_samples=reference_clips, preset='fast')

for Faster runs use all three:

reference_clips = [utils.audio.load_audio(p, 22050) for p in clips_paths]
tts = api.TextToSpeech(use_deepspeed=True, kv_cache=True, half=True)
pcm_audio = tts.tts_with_preset("your text here", voice_samples=reference_clips, preset='fast')

Acknowledgements

This project has garnered more praise than I expected. I am standing on the shoulders of giants, though, and I want to credit a few of the amazing folks in the community that have helped make this happen:

Notice

Tortoise was built entirely by the author (James Betker) using their own hardware. Their employer was not involved in any facet of Tortoise's development.

License

Tortoise TTS is licensed under the Apache 2.0 license.

If you use this repo or the ideas therein for your research, please cite it! A bibtex entree can be found in the right pane on GitHub.

tortoise-tts (neonbjb/tortoise-tts)

Searching Database…

这是什么东西?Tortoise 是一个以质量为重心的文字转语音系统:它支持多种音色,韵律和语调都非常逼真。这个仓库包含以推理模式运行它所需的一切。
我到底该怎么用它——它是一个库、一套脚本,还是一项服务?它是一个 Python 程序,提供了几种使用方式:dotts.py 可以用一个或多个音色朗读单句,read.py 能把文本文件转成音频,还有一个监听 5000 端口的 socket 流式脚本,此外也提供 Python API 供编程调用。
我在本地怎么把它跑起来?推荐的方式是用 Conda:先安装 miniconda,创建并激活 tortoise 环境,安装 PyTorch,然后克隆仓库并运行它的安装脚本。官方也提供了 Docker 镜像,以及直接从 git 仓库进行 pip install 的方式。
生成音频会很慢吗?过去确实很慢,项目那个半开玩笑的名字也承认了这一点:模型同时使用了自回归解码器和扩散解码器,而这两者都以采样率低著称。在老旧的 K80 上,一句中等长度的句子大约要两分钟;如今配合流式输出的方案已经快得多了。
它在 Apple Silicon 的 Mac 上能用吗?可以,在搭载 M1/M2 的 macOS 13 及以上版本上可用:激活环境后安装 nightly 版 PyTorch,如果遇到缺少算子的情况,在命令前加上 PYTORCHENABLEMPSFALLBACK=1。DeepSpeed 在 Apple Silicon 上无法运行,它的相关参数会被忽略。
我可以免费在自己的项目里使用它吗?它采用 Apache 2.0 许可证。如果你在研究中使用了这个仓库或它的思路,作者希望你引用它——GitHub 页面右侧栏里有现成的 BibTeX 条目。
它为什么叫 Tortoise(乌龟)?作者给语音相关的仓库都用莫哈韦沙漠的动植物命名,这个名字也是自嘲:模型慢得离谱,因为它的两个解码器采样率都很低。
在 Windows 上安装有什么坑吗?有——作者强烈建议在 Windows 上用 Conda 方式安装,否则你可能会花大量时间排查依赖问题。另外可能还需要安装 pysoundfile(conda install -c conda-forge pysoundfile),而且每次使用前都要记得激活 tortoise 环境。
What are similar projects?OmniVoice, Speech, AuK, bark, ChatTTS, dia, csm, TTS
Creator
neonbjb
Size
54.2 MB
Stars
14.9K
Updated
CommitNov 19
Age
4y
Commits · 90 Days