Skip to content

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

ParameterTypeDescription
textstringText to synthesize
languagestringLanguage code (e.g., zh-cn, en, ja, ko, etc.)
voicestringVoice name
ratestringSpeed adjustment: 0 or +number% or -number% (percentage offset from normal speed)
ostypestringOperating system: win32, mac, or linux
extrastringAdditional 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, it

Response Format

Returns JSON:

json
{
    "code": 0,
    "msg": "ok",
    "data": "https://example.com/audio.mp3"
}

Field Descriptions:

FieldDescription
codeStatus code: 0 for success, >0 for failure
msgStatus message: ok on success, error reason on failure
dataOn 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:

  1. URL: A full URL starting with http — the software will download the audio file automatically
  2. Base64 data: Audio data encoded as Base64, starting with data:audio
  3. Hex-encoded audio: A JSON object containing an audio field with hex-encoded audio data

Using It in pyVideoTrans

Step 1: Configure the API Address

  1. Open the software and go to Menu → TTS Settings → Custom TTS API
  2. Enter your endpoint address in the API Address field
  3. If you have additional parameters, enter them in the extra field

Step 2: Test the Connection

  1. Click the Test button
  2. If it returns success, the configuration is correct
  3. Save the settings

Step 3: Start Dubbing

  1. Return to the main interface
  2. Select Custom TTS API from the Voice Channel dropdown
  3. Choose the target language and voice
  4. 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:// or https://
  • 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

IssueSolution
API URL errorCheck the address format
Connection refusedMake sure the API service is running
Response format errorVerify the JSON matches the protocol
Cannot download audioCheck that the returned URL is accessible