vast.aiでVOICEVOXを使ってttsする

 

CPUではキツいので、GPUでTTSを行う。

例のごとくvast.ai様にGPUレンタルしにいく。

 

 

このテンプレートを使う。

 

Cloudflaredを使ってhttpsで接続できるようにする。

バックグラウンドで起動させておく。

root@ubuntu:~# cloudflared --url http://localhost:50021  &

 

エンター押したら通常のコマンドに戻った。 んで、発行されたURLがこれ。 https://commonly-productions-agreement-roller.trycloudflare.com

 

GPU版のdockerを起動するには以下。


docker run --rm --gpus all -p 50021:50021 voicevox/voicevox_engine:nvidia-latest

 

起動しました。

 

ローカルからcurlで投げる。下記にvoicevox_engineのapi仕様書がある。

https://voicevox.github.io/voicevox_engine/api/

こちらも参考にする。

https://github.com/VOICEVOX/voicevox_engine

 

 

まずは、読み上げさせたい

 

クエリー生成:synthesis投げる前にやるやつ。

curl -s \
    -X POST \
    "https://commonly-productions-agreement-roller.trycloudflare.com/audio_query?speaker=4"\
    --get --data-urlencode text@text.txt \
    > query.json

 

synthesis:音声合成

curl -s \
    -H "Content-Type: application/json" \
    -X POST \
    -d @query.json \
    "https://commonly-productions-agreement-roller.trycloudflare.com/synthesis?speaker=1" \
    > audio.wav

 

短い文章だとうまくいきますが、長いと500エラーとなります。

調査のためにdockerのログを確認する。この内容については[synthesisで長めのtextだとエラーが出る]で後述します。

docker logs [コンテナーid] > docker.logs 2>&1

辞書作成

Azureってのがうまく発音できなかったので辞書登録して読めるようにしてやる。

curl -s "https://commonly-productions-agreement-roller.trycloudflare.com/user_dict_word"
{"detail":"Method Not Allowed"}%                                                        
takumi@ ~/Documents/src/private_src/daily/2025-03-02/books-tts$ curl -s "https://commonly-productions-agreement-roller.trycloudflare.com/user_dict"
{"edfbb7ae-ac2a-4e30-a567-8f79774d788f":{"surface":"Azure","priority":5,"context_id":1348,"part_of_speech":"名詞","part_of_speech_detail_1":"固有名詞","part_of_speech_detail_2":"一般","part_of_speech_detail_3":"*","inflectional_type":"*","inflectional_form":"*","stem":"*","yomi":"アジュール","pronunciation":"アジュール","accent_type":1,"mora_count":4,"accent_associative_rule":"*"}}%   

 

 

作成確認

自分で作成した辞書を念のため確認

curl -s "https://commonly-productions-agreement-roller.trycloudflare.com/user_dict_word"
{"detail":"Method Not Allowed"}%                                                        
takumi@ ~/Documents/src/private_src/daily/2025-03-02/books-tts$ curl -s "https://commonly-productions-agreement-roller.trycloudflare.com/user_dict"
{"edfbb7ae-ac2a-4e30-a567-8f79774d788f":{"surface":"Azure","priority":5,"context_id":1348,"part_of_speech":"名詞","part_of_speech_detail_1":"固有名詞","part_of_speech_detail_2":"一般","part_of_speech_detail_3":"*","inflectional_type":"*","inflectional_form":"*","stem":"*","yomi":"アジュール","pronunciation":"アジュール","accent_type":1,"mora_count":4,"accent_associative_rule":"*"}}%   

 

 

synthesisで長めのtextだとエラーが出る

エラー内容
INFO:     172.17.0.1:33816 - "POST /synthesis?speaker=1 HTTP/1.1" 500 Internal Server Error<br>INFO:     172.17.0.1:33230 - "POST /audio_query?speaker=1&text=%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB+%E3%80%8CAzure+%E3%82%B9%E3%83%88%E3%83%AC%E3%83%BC%E3%82%B8%E3%81%AE%E9%AD%85%E5%8A%9B%E3%82%92%E6%8E%A2%E3%82%8B%E3%80%8D HTTP/1.1" 200 OK<br>INFO:     172.17.0.1:37264 - "POST /synthesis?speaker=1 HTTP/1.1" 200 OK<br>INFO:     172.17.0.1:51418 - "POST /audio_query?speaker=1&text=xxx0A HTTP/1.1" 200 OK<br>2025-03-02T14:29:46.057873Z  WARN onnxruntime::onnxruntime: "Non-zero status code returned while running MatMul node. Name:'MatMul_417' Status Message: /onnxruntime_src/onnxruntime/core/framework/bfc_arena.cc:342 void* onnxruntime::BFCArena::AllocateRawInternal(size_t, bool) Failed to allocate memory for requested buffer of size 10634353152n"<br>Traceback (most recent call last):<br>  File "/home/user/.local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__<br>    await self.app(scope, receive, _send)<br>  File "/home/user/.local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__<br>    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)<br>  File "/home/user/.local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app<br>    raise exc<br>  File "/home/user/.local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app<br>    await app(scope, receive, sender)

 

多分これが関係してそう。

https://github.com/VOICEVOX/voicevox_engine/issues/1506

流れを見ていると、どうも長めのtextを投げることがよくなさそう。エディタ?(多分GUIのこと)も短めでリクエスト投げて使うようだ。

それにしてもここのissuesは勉強になるなぁ。。これが本当のツヨツヨというやつか・・・と思ったりした。