Custom TTS API Channel
What is it?
The custom TTS API channel lets you connect to any third-party TTS service. As long as your API follows the specified protocol format, you can use it in pyVideoTrans.
Use cases:
- You have a self-hosted TTS service
- You're using a third-party TTS relay service
- You need to connect to a specialized speech synthesis endpoint
API Protocol
Request Method
- Method:
POST - Content-Type:
application/x-www-form-urlencoded
Request Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | Text to synthesize |
language | string | Language code (e.g., zh-cn, en, ja, ko, etc.) |
voice | string | Voice name |
rate | string | Speed adjustment: 0 or +number% or -number% (percentage offset from normal speed) |
ostype | string | Operating system: win32, mac, or linux |
extra | string | Additional parameters (configurable in software) |
Supported Language Codes
zh-cn, zh-tw, en, ja, ko, ru, de, fr, tr, th, vi, ar, hi, hu, es, pt, itResponse Format
Returns JSON:
json
{
"code": 0,
"msg": "ok",
"data": "https://example.com/audio.mp3"
}Field Descriptions:
| Field | Description |
|---|---|
code | Status code: 0 for success, >0 for failure |
msg | Status message: ok on success, error reason on failure |
data | On success, the full URL of the MP3 file; empty on failure |
Supported data Formats
The data field in the API response supports the following formats:
- URL: A full URL starting with
http— the software will download the audio file automatically - Base64 data: Audio data encoded as Base64, starting with
data:audio - Hex-encoded audio: A JSON object containing an
audiofield with hex-encoded audio data
Using It in pyVideoTrans
Step 1: Configure the API Address
- Open the software and go to Menu → TTS Settings → Custom TTS API
- Enter your endpoint address in the API Address field
- If you have additional parameters, enter them in the extra field
Step 2: Test the Connection
- Click the Test button
- If it returns success, the configuration is correct
- Save the settings
Step 3: Start Dubbing
- Return to the main interface
- Select
Custom TTS APIfrom the Voice Channel dropdown - Choose the target language and voice
- Start dubbing
Implementation Example
Here's a simple Python Flask implementation:
python
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/tts', methods=['POST'])
def tts():
text = request.form.get('text', '')
language = request.form.get('language', '')
voice = request.form.get('voice', '')
rate = request.form.get('rate', '0')
# Call your TTS service here
# audio_url = your_tts_service(text, voice, rate)
return jsonify({
"code": 0,
"msg": "ok",
"data": audio_url # Return the audio file URL
})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)Important Notes
- The API address must start with
http://orhttps:// - The JSON response must strictly follow the protocol format
- Audio files must be in MP3 format
- If returning a URL, it must be a fully accessible address
- For best performance, deploy the API service locally (e.g., on
127.0.0.1)
Troubleshooting
| Issue | Solution |
|---|---|
| API URL error | Check the address format |
| Connection refused | Make sure the API service is running |
| Response format error | Verify the JSON matches the protocol |
| Cannot download audio | Check that the returned URL is accessible |
