我們在「【語音合成技術 - GPT-SoVITS】讓機器說人話的語音生成服務」介紹過如何透過docker啟動webui版的TTS服務器, 但假設我們想自行開發一個TTS服務, 並整合到系統裡面, 通常會需要一個傳輸介面來溝通, 而API就是最簡易的溝通方式, 正巧 ****GPT-SoVITS ****也提供了API介面, 只是在架設時我們要稍微修改一下配置即可。
首先我們為您導覽一下怎麼做?

👉 接下來請你跟我這樣做
下載專案
git clone <https://github.com/RVC-Boss/GPT-SoVITS.git>
cd GPT-SoVITS
切到 fast_inference_ 分支
git checkout fast_inference_
Build Docker Image
./dockerbuild.sh
改docker compose配置
我們會需要加入command來執行api_v3
command:
- python
- api_v3.py
整個compose配置檔送給您:
version: '3.8'
services:
gpt-sovits:
image: breakstring/gpt-sovits:latest # please change the image name and tag base your environment. If the tag contains the word 'elite', such as "latest-elite", it indicates that the image does not include the necessary models such as GPT-SoVITS, UVR5, Damo ASR, etc. You will need to download them yourself and map them into the container.
container_name: gpt-sovits-container
environment:
- is_half=False
- is_share=False
volumes:
- ./output:/workspace/output
- ./logs:/workspace/logs
- ./SoVITS_weights:/workspace/SoVITS_weights
- ./reference:/workspace/reference
command:
- python
- api_v3.py
working_dir: /workspace
ports:
- "9880:9880"
- "9871:9871"
- "9872:9872"
- "9873:9873"
- "9874:9874"
shm_size: 16G
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: "all"
capabilities: [gpu]
stdin_open: true
tty: true
restart: unless-stopped
⭐️ 隱藏細節 - 掛載範例音檔
這邊要請您將一段5-10秒的範例音檔掛載到伺服器, 這樣我們產生tts語音的時候就能夠仿造範例音檔進行輸出。
|- reference
|- sample.wav
接著我們啟動服務
docker compose up -d
試試以下的API
我們在網頁上就能夠播放TTS所產生的音檔。

結語
假設我們想另外開發TTS的系統進行串接時, API就顯得非常重要, 也是最簡單的介接媒介, 因此學會 https://github.com/RVC-Boss/GPT-SoVITS 能夠讓我們更彈性的開發自己的TTS服務系統。