Tortoise 是一個文字轉語音程序,其建構重點如下:
此儲存庫包含在推理模式下執行 Tortoise TTS 所需的所有程式碼。
手稿:https://arxiv.org/abs/2305.07243
Hugging Face Spaces 上舉辦了現場演示。如果您想避免排隊,請複製空間並添加 GPU。請注意,僅 CPU 空間不適用於此演示。
https://huggingface.co/spaces/Manmay/tortoise-tts
pip install tortoise-tts
如果您想安裝最新的開發版本,也可以直接從 git 儲存庫安裝:
pip install git+https://github.com/neonbjb/tortoise-tts
我以莫哈韋沙漠動植物命名我的與語音相關的儲存庫。烏龜有點開玩笑:這個模型慢得要命。它利用自回歸解碼器和擴散解碼器;兩者都以其低採樣率而聞名。在 K80 上,預計每 2 分鐘產生一個中等長度的句子。
好吧......不再那麼慢了,現在我們可以在 4GB vram 上獲得0.25-0.3 RTF ,並且透過串流傳輸,我們可以獲得 < 500 毫秒的延遲!
請參閱此頁面以取得大量範例輸出清單。
Tortoise + GPT-3 的一個很酷的應用程式(不隸屬於此儲存庫):https://twitter.com/lexman_ai。不幸的是,這個項目似乎不再活躍了。
如果你想在自己的電腦上使用它,你必須有 NVIDIA GPU。
提示
在 Windows 上,我強烈建議使用 Conda 安裝方法。有人告訴我,如果您不這樣做,您將花費大量時間來解決依賴性問題。
首先,安裝miniconda:https://docs.conda.io/en/latest/miniconda.html
然後執行以下命令,使用 anaconda 提示符號作為終端(或配置為使用 conda 的任何其他終端)
這將:
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
或者,可以將 pytorch 安裝在基礎環境中,以便其他 conda 環境也可以使用它。為此,只需在啟動 tortoise 環境之前發送conda install pytorch...
行即可。
筆記
當你想要使用 tortoise-tts 時,你必須確保tortoise
conda 環境已啟動。
如果您使用的是 Windows,您可能還需要安裝 pysoundfile: conda install -c conda-forge pysoundfile
這是一種快速上手的簡單方法,也是一個很好的起點,取決於您的用例。
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
這為您提供了一個可以在環境中執行一些 tts 的互動終端。現在您可以探索 tortoise 為 tts 所公開的不同介面。
例如:
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. "
在配備 M1/M2 晶片的 macOS 13+ 上,您需要安裝 PyTorch 的 nightly 版本,如官方頁面所述,您可以執行以下操作:
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu
請務必在啟動環境後執行此操作。如果您不使用 conda,命令將如下所示:
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 .
請注意,Apple Silicon 上的 DeepSpeed 已被停用,因為它不起作用。標誌--use_deepspeed
被忽略。您可能需要在下面的命令前面新增PYTORCH_ENABLE_MPS_FALLBACK=1
才能使其正常運作,因為 MPS 不支援 Pytorch 中的所有操作。
該腳本允許您用一個或多個聲音說出單個短語。
python tortoise/do_tts.py --text " I'm going to speak this " --voice random --preset fast
python tortoise/socket_server.py
將在連接埠 5000 監聽
該腳本提供了用於閱讀大量文字的工具。
python tortoise/read_fast.py --textfile < your text to be read > --voice random
該腳本提供了用於閱讀大量文字的工具。
python tortoise/read.py --textfile < your text to be read > --voice random
這會將文字檔案分解成句子,然後一次一個地將它們轉換為語音。它將在生成時輸出一系列語音剪輯。生成所有剪輯後,它會將它們組合成一個檔案並輸出。
有時烏龜會搞砸輸出。您可以透過使用 --regenerate 參數重新執行read.py
來重新產生任何錯誤的剪輯。
Tortoise 可以透過程式設計方式使用,如下所示:
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' )
要使用 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' )
使用 kv 快取:
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' )
要在 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' )
為了更快的運行,請使用所有三個:
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' )
這個項目獲得的讚譽超出了我的預期。不過,我站在巨人的肩膀上,我想感謝社區中一些令人驚嘆的人,他們幫助實現了這一目標:
Tortoise 完全由作者(James Betker)使用他們自己的硬體構建。他們的雇主沒有參與 Tortoise 開發的任何方面。
Tortoise TTS 根據 Apache 2.0 授權取得許可。
如果您使用此存儲庫或其中的想法進行研究,請引用它! bibtex 主菜可以在 GitHub 的右側窗格中找到。