TTS API Quickstart
Learn how to use PlayAI’s Text-to-Speech API for natural conversations
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.
Prerequisites
- Access your credentials (API key and user ID)
- Development environment for your chosen programming language
Steps
Set Up Environment Variables
Add your API key and user ID to your environment variables.
Configure API Access
Create a script with the following authentication setup for your chosen language:
Prepare API Parameters
Define your API payload with these key parameters:
model
: UsePlayDialog
for multi-turn conversation generationtext
: Your input text for speech generationvoice
: URL path to the voice manifestoutput_format
: Choosewav
ormp3
Implement API Call
Create the complete API implementation in your chosen language:
Run and Test
Follow these steps to run your code:
- Save your code as
playdialog_tts.py
- Open terminal in your code directory
- Run:
python3 playdialog_tts.py
- Check for the generated
dialogue.wav
file
Customize and Adapt
Modify your implementation by:
- Updating the input text
- Changing speaker details and voices
- Adjusting output format as needed
- Adding multiple speakers or complex dialogues
Complete Code
Troubleshooting
If you encounter issues, check these common problems:
-
Authentication Issues:
- Verify your API key and user ID
- Confirm the
AUTHORIZATION
header includes “Bearer ” prefix
-
API Endpoint Errors:
- Verify the correct PlayAI’s Dialog 1.0 API endpoint URL
- Confirm the
model
name isPlayDialog
-
Language-Specific Issues:
- JavaScript: Ensure
node-fetch
is installed for Node.js environments - Go: Check for proper error handling and response body closing
- Dart: Verify the
http
package is added to yourpubspec.yaml
- Swift: Make sure you’re running on macOS for file system access
- JavaScript: Ensure