Closed7

「Tortoise TTS」を試す

kun432kun432

少し古いのだけど。

GitHubレポジトリ

https://github.com/neonbjb/tortoise-tts

TorToiSe

Tortoiseは、以下の優先事項をもとに構築されたテキスト読み上げプログラムです。

  1. 強力なマルチボイス対応。
  2. 非常にリアルなプロソディ(韻律)とイントネーション。

このリポジトリには、Tortoise TTSを推論モードで実行するために必要なすべてのコードが含まれています。

論文: https://arxiv.org/abs/2305.07243

Hugging Face space

Hugging Face Spacesでライブデモがホストされています。待機列を避けたい場合は、Spaceを複製してGPUを追加してください。なお、CPUのみのSpaceではこのデモは動作しません。

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

名前の由来について

モハベ砂漠の動植物から音声関連リポジトリの名前を付けています。Tortoise(亀)は少し皮肉を込めた命名です:このモデルは非常に遅いのです。自己回帰デコーダー拡散デコーダーの両方を活用しており、どちらもサンプリングレートが低いことで知られています。K80上では、中程度の長さの文を生成するのに2分かかります。

……とはいえ、今では4GBのVRAMでも0.25〜0.3 RTFが実現でき、ストリーミングによって500ms未満の遅延で動作します!

デモ

多数の出力例についてはこのページをご覧ください。

TortoiseとGPT-3のクールな応用例(このリポジトリとは無関係):https://twitter.com/lexman_ai ただし、このプロジェクトは現在アクティブではないようです。

論文はAlphaAxivのまとめを参照

https://www.alphaxiv.org/overview/2305.07243

モデル

https://huggingface.co/jbetker/tortoise-tts-v2

なお、英語以外はサポートされていない。

https://github.com/neonbjb/tortoise-tts/issues/149

kun432kun432

インストールは以下の3つの方法がある

  1. PyPIからpipインストール
  2. レポジトリからpipインストール
  3. ローカルでビルド・インストール
    • Python仮想環境(Apple Siliconにも対応)
    • Docker

condaの利用が強く推奨されているが、自分はcondaをあまり良くわかっていないのと、あまり使いたくない感がある。普通にpipでインストールしてみたら、どうやら内部で使用しているパッケージのビルド時にRustコンパイラが必要、みたいな感じになって、ちょっと構築が面倒に感じたのでDockerにする。

今回はUbuntu−22.04サーバ(RTX4090)を使う。

レポジトリクローン

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

次に、Dockerイメージをビルドするのだが、普通にやると失敗した。

  • tokenizersパッケージの依存関係が解決できなくてビルドがコケる(参考)。
  • scikit-learnのインストールでrc版が選択されてしまうせいかビルドがコケる。

上記を踏まえて、setup.pyを少し修正

setup.py
    install_requires=[
        'tqdm',
        'rotary_embedding_torch',
        'inflect',
        'progressbar',
        'einops',
        'unidecode',
        'scipy',
        'librosa',
        'transformers==4.31.0',
        'tokenizers==0.11.1',    # 0.14.0 → 0.11.1
        'scikit-learn==1.6.1',    # 追加。stable版の最新にした
        'scipy==1.13.1'
        # 'deepspeed==0.8.3',
    ],
docker build . -t tortoise-tts

ビルドできたらコンテナを起動して入る。とりあえず使い捨てで。

docker run --rm --gpus all \
    -e TORTOISE_MODELS_DIR=/models \
    -v ./user_data/models:/models \
    -v ./user_data/results:/results \
    -v $HOME/.cache/huggingface:/root/.cache/huggingface \
    -v .:/work \
    -it tortoise-tts

condaの環境一覧

conda env list
出力

# conda environments:
#
base                 * /root/miniconda
tortoise               /root/miniconda/envs/tortoise

Tortoise TTSの環境は tortoise に構築されているのでアクティベート

conda activate tortoise

/work にクローンしたレポジトリはマウントされているのでここに移動

cd /work

do_tts.py で音声を生成できる。ヘルプを見てみる。

python tortoise/do_tts.py --help
出力
usage: do_tts.py [-h] [--text TEXT] [--voice VOICE] [--preset PRESET]
                 [--use_deepspeed USE_DEEPSPEED] [--kv_cache KV_CACHE] [--half HALF]
                 [--output_path OUTPUT_PATH] [--model_dir MODEL_DIR] [--candidates CANDIDATES]
                 [--seed SEED] [--produce_debug_state PRODUCE_DEBUG_STATE]
                 [--cvvp_amount CVVP_AMOUNT]

optional arguments:
  -h, --help            show this help message and exit
  --text TEXT           Text to speak.
  --voice VOICE         Selects the voice to use for generation. See options in voices/
                        directory (and add your own!) Use the & character to join two voices
                        together. Use a comma to perform inference on multiple voices.
  --preset PRESET       Which voice preset to use.
  --use_deepspeed USE_DEEPSPEED
                        Use deepspeed for speed bump.
  --kv_cache KV_CACHE   If you disable this please wait for a long a time to get the output
  --half HALF           float16(half) precision inference if True it's faster and take less vram
                        and ram
  --output_path OUTPUT_PATH
                        Where to store outputs.
  --model_dir MODEL_DIR
                        Where to find pretrained model checkpoints. Tortoise automatically
                        downloads these to .models, so thisshould only be specified if you have
                        custom checkpoints.
  --candidates CANDIDATES
                        How many output candidates to produce per-voice.
  --seed SEED           Random seed which can be used to reproduce results.
  --produce_debug_state PRODUCE_DEBUG_STATE
                        Whether or not to produce debug_state.pth, which can aid in reproducing
                        problems. Defaults to true.
  --cvvp_amount CVVP_AMOUNT
                        How much the CVVP model should influence the output.Increasing this can
                        in some cases reduce the likelihood of multiple speakers. Defaults to 0
                        (disabled)

READMEのサンプルを実行してみる。

  • 音声はランダムで選択
  • プリセットというのは生成パラメータのプリセット設定の様子
    • ultra_fast / fast / standard / high_quality から選択。詳しくはここ
    • 今回は fast

なお、初回はモデルのダウンロードが行われるので少し時間がかかる。

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

生成されると複数のファイルが生成されていた。

ls -lt results/
出力
total 296
-rw-r--r-- 1 root root 109134 May 19 16:34 random_0_1.wav
-rw-r--r-- 1 root root  91214 May 19 16:34 random_0_2.wav
-rw-r--r-- 1 root root  95822 May 19 16:34 random_0_0.wav

生成されたもの

https://audio.com/kun432/audio/tortoise-tts-sample-random-0-0

https://audio.com/kun432/audio/tortoise-tts-sample-random-0-1

https://audio.com/kun432/audio/tortoise-tts-sample-random-0-2

kun432kun432

外にも

  • ソケット接続を行うストリーミングサーバ・クライアント
  • 長文生成用
  • Pythonで利用

する場合のサンプル等がある。

kun432kun432

まとめ

環境構築で色々ハマったりもして、生成された音声を聞いた感じでも、まあ流石に古くなってしまっている感は否めないのだが、ちょびっとプロンプトエンジニアリング的なことができたり(Advanced Usageに書いてある)、音声クローンがお手軽だったりというところで、時期を考えるとすごいなと感じた。

このスクラップは3ヶ月前にクローズされました