Retrieves the result of a specific Text-to-Speech run using the provided run_id.
GET
/
tts-result
/
{run_id}
Get Tts Run Info
Copy
curl --request GET \ --url https://client.camb.ai/apis/tts-result/{run_id} \ --header 'x-api-key: <api-key>'
Copy
"<string>"
This endpoint is the final step in your text-to-speech journey, where you retrieve your completed audio file. Once your task has reached a SUCCESS status and you’ve received a run_id, you can use this endpoint to access your generated audio and incorporate it into your application.
Retrieving your generated audio is straightforward - simply make a GET request to this endpoint with the run_id you received when your task completed. The system will respond by providing your audio in your preferred format.
When using the default raw_bytes output type, the endpoint streams the audio data directly to your application. This approach is ideal when you want to:
Save the audio file to your local system
Process the audio data immediately in your application
Play the audio without storing it permanently
The streaming approach is particularly efficient for handling larger audio files as it processes the data in manageable chunks rather than loading everything into memory at once.
If you prefer to receive a URL pointing to your audio file instead of the raw data, specify output_type=file_url. The response will be a JSON object containing a URL where the audio file can be accessed. This approach is beneficial when:
You need to share the audio file with others
Embed the audio in web content
Handle the download process separately from retrieval
Note that file URLs have an expiration time, so download or use them promptly rather than storing them long-term.
Here’s how to retrieve and save your generated audio using Python:
Copy
import requests# Your API authenticationheaders = { "x-api-key": "your-api-key", # Replace with your actual API key}# The run_id you received when your task completed successfullyrun_id = 12345 # Replace with your actual `run_id`def download_audio_file(run_id, output_filename="generated_speech.flac"): """ Downloads the generated audio file and saves it to the specified location. Args: run_id: The unique identifier for the completed TTS task output_filename: Where to save the audio file (defaults to 'generated_speech.flac') Returns: bool: True if successful, False otherwise """ print(f"Downloading audio for run_id: {run_id}") try: # Make the request with streaming enabled # The 'stream=True' parameter is crucial for handling the audio data efficiently response = requests.get( f"https://client.camb.ai/apis/tts-result/{run_id}", headers=headers, stream=True # This enables processing the response in chunks ) # Check if the request was successful response.raise_for_status() # Save the streaming audio to a file with open(output_filename, "wb") as audio_file: # Process the response in chunks to handle large audio files efficiently # The chunk_size determines how much data to process at once for chunk in response.iter_content(chunk_size=1024): if chunk: # Filter out keep-alive chunks audio_file.write(chunk) print(f"Audio successfully saved to {output_filename}!") return True except requests.exceptions.RequestException as e: print(f"Error downloading audio: {e}") return False# Call the function to download your audiosuccess = download_audio_file(run_id)if success: print("You can now use this audio file in your application!")
If you prefer to receive a URL to the audio file instead:
Copy
import requests# Your API authenticationheaders = { "x-api-key": "your-api-key", # Replace with your actual API key}# The run_id you received when your task completed successfullyrun_id = 12345 # Replace with your actual `run_id`# Request a URL instead of raw bytesparams = { "output_type": "file_url"}# Make the requestresponse = requests.get( f"https://client.camb.ai/apis/tts-result/{run_id}", headers=headers, params=params)# Check if the request was successfulresponse.raise_for_status()# Get the URL from the responseurl_data = response.json()audio_url = url_data.get("output_url")print(f"Your audio is available at: {audio_url}")print("You can now share this URL or use it to embed the audio in your application.")
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.