Use this file to discover all available pages before exploring further.
This guide provides a step-by-step approach to using the PlayAI’s Text-to-Speech API to convert text into natural human-like sounding audio.In this example, we’ll have Dialog 1.0 create a simple audio from the given input text.
Define your API payload with these key parameters:
model: Use PlayDialog for multi-turn conversation
generation
text: Your input text for speech generation
voice: URL path to the voice manifest
output_format: Choose wav or mp3
json_data = { 'model': 'PlayDialog', 'text': "All human wisdom is summed up in these two words: Wait and hope.", 'voice': 's3://voice-cloning-zero-shot/baf1ef41-36b6-428c-9bdf-50ba54682bd8/original/manifest.json', 'outputFormat': 'wav'}
4
Implement API Call
Create the complete API implementation in your chosen language:
response = requests.post('https://api.play.ai/api/v1/tts/stream', headers=headers, json=json_data)if response.status_code == 200: with open('dialogue.wav', 'wb') as f: f.write(response.content) print("Audio file saved as dialogue.wav")else: print(f"Request failed with status code {response.status_code}: {response.text}")
import osimport requestsapi_key = os.getenv("PLAYAI_API_KEY")user_id = os.getenv("PLAYAI_USER_ID")headers = { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json', 'X-USER-ID': user_id}json_data = { 'model': 'PlayDialog', 'text': "All human wisdom is summed up in these two words: Wait and hope.", 'voice': 's3://voice-cloning-zero-shot/baf1ef41-36b6-428c-9bdf-50ba54682bd8/original/manifest.json', 'outputFormat': 'wav'}response = requests.post('https://api.play.ai/api/v1/tts/stream', headers=headers, json=json_data)if response.status_code == 200: with open('dialogue.wav', 'wb') as f: f.write(response.content) print("Audio file saved as dialogue.wav")else: print(f"Request failed with status code {response.status_code}: {response.text}")