Transform written content across language barriers with our powerful translated text-to-speech system. This innovative endpoint enables you to seamlessly convert text from one language into spoken audio in another language in a single streamlined process. Whether youβre creating multilingual content, developing educational materials, building accessible applications, or expanding your global reach, this capability allows you to quickly generate localized audio content while maintaining natural pronunciation and intonation specific to the target language.
Once the task is complete, the outputs can be retrieved using these endpoints:
When you submit a request to this endpoint, our system processes your input text through a streamlined workflow:
First, the system creates a dedicated task and returns a unique task_id for tracking.
Your source text is then accurately translated to the target language using advanced neural machine translation models that preserve meaning andn context.
Finally, the translated text is converted into natural-sounding speech using language-specific voice models that capture the appropriate pronunciation and intonation of the target language.
You can monitor the status of your request by polling the /translated-tts/{task_id} endpoint until processing is complete.
Creating Your First Translated Text-to-Speech Request
Letβs examine how to initiate a translated text-to-speech task using Python:
Copy
import requestsimport json# Your API authenticationheaders = { "x-api-key": "your-api-key", # Replace with your actual API key "Content-Type": "application/json"}def create_translated_tts(text, source_language, target_language, voice_id=None): """ Submits a new translated text-to-speech task and returns the task ID for tracking. Parameters: - text: The source text to be translated and converted to speech - source_language: Language id of the input text (e.g., 1 for English) - target_language: Language id for the desired output translation and speech (e.g., 54 for Spanish) - voice_id: Optional specific voice to use for the target language """ try: # Prepare the request body payload = { "text": text, "source_language": source_language, "target_language": target_language } # Add voice_id if specified if voice_id: payload["voice_id"] = voice_id # Submit the request response = requests.post( "https://client.camb.ai/apis/translated-tts", headers=headers, data=json.dumps(payload) ) # Verify the request was successful response.raise_for_status() # Extract the task ID from the response result = response.json() task_id = result.get("task_id") run_id = result.get("run_id") print(f"Translated TTS task submitted successfully! Task ID: {task_id}") print(f"Run ID for retrieving results: {run_id}") return task_id, run_id except requests.exceptions.RequestException as e: print(f"Error submitting translated TTS task: {e}") if hasattr(e, 'response') and e.response is not None: print(f"Response content: {e.response.text}") return None, None# Example usagesource_text = "Welcome to our global product demonstration. We're excited to share these new features with you."task_id, run_id = create_translated_tts( text=source_text, source_language=1, # Language ID (e.g., `1` for English - United States) target_language=88 # Language ID (e.g., `88` for Japanese - Japan))
Monitoring Your Translation and Speech Generation Progress
After submission, your task enters our processing pipeline. You can monitor the progress by polling the status endpoint:
Copy
def check_translated_tts_status(task_id): """ Checks the status of a translated text-to-speech task. Returns the current status and any available result information. Parameters: - task_id: The ID of the task to check """ if not task_id: print("No task ID provided.") return None try: response = requests.get( f"https://client.camb.ai/apis/translated-tts/{task_id}", headers=headers ) # Verify the request was successful response.raise_for_status() # Parse the status information status_data = response.json() print(f"Current status: {status_data['status']}") # If the task is complete, show how to access results if status_data['status'] == "SUCCESS": print("Translation and speech generation completed successfully!") print(f"Use the run_id to retrieve your results.") print(f"- Translation: GET /translation-result/{status_data.get('run_id')}") print(f"- Audio: GET /tts-result/{status_data.get('run_id')}") return status_data except requests.exceptions.RequestException as e: print(f"Error checking task status: {e}") return None# Check the status of your taskstatus_info = check_translated_tts_status(task_id)
Once your task is complete, you can retrieve both the translated text and the generated audio using the provided run_id:
Copy
def get_translation_result(run_id): """ Retrieves the translated text result. Parameters: - run_id: The run ID returned from the initial request """ try: response = requests.get( f"https://client.camb.ai/apis/translation-result/{run_id}", headers=headers ) response.raise_for_status() result = response.json() print(f"Translation successful!") print(f"Translated text: {result.get('translated_text')}") return result except requests.exceptions.RequestException as e: print(f"Error retrieving translation: {e}") return Nonedef get_tts_result(run_id): """ Retrieves the generated audio file. Parameters: - run_id: The run ID returned from the initial request """ try: response = requests.get( f"https://client.camb.ai/apis/tts-result/{run_id}", headers=headers ) response.raise_for_status() result = response.json() print(f"Audio retrieval successful!") print(f"Audio URL: {result.get('audio_url')}") return result except requests.exceptions.RequestException as e: print(f"Error retrieving audio: {e}") return None# Retrieve your resultstranslation = get_translation_result(run_id)audio = get_tts_result(run_id)
To achieve the highest quality results for your multilingual audio content:
Provide Clear Source Text: Ensure your source text is free of grammatical errors, unusual abbreviations, or ambiguous phrases to improve translation accuracy.
Consider Cultural Context: Be mindful of cultural references that may not translate effectively across languages, and adapt your content accordingly.
Use Appropriate Sentence Length: For optimal speech generation, break long, complex sentences into shorter ones, especially for languages that differ structurally from the source.
Our system supports a wide range of language pairs for translation and speech synthesis. The quality and naturalness of speech may vary depending on the specific language combinations. Checkout the /target-languages endpoint for a list of supported languages and /list-voices endpoint for a list of available voices which includes public voices and your own custom voices.
The x-api-key is a custom header required for authenticating requests to our API. Include this header in your request with the appropriate API key value to securely access our endpoints. You can find your API key(s) in the 'API' section of our studio website.
Body
application/json
Parameters for initiating a translation and text-to-speech task, including source text, language preferences, and voice characteristics.