Enhance your app with our audio-in, audio-out API, enabling seamless, natural conversations with your PlayAI agent. Transform your user experience with the power of voice.
https://api.play.ai/api/v1/websocket-auth
with Authorization: Bearer <your_api_key>
and X-User-Id: <your_user_id>
headerswebSocketUrls
field containing the WebSocket URL according to the desired modelsnake_case
, e.g., {"text":"Hello World","voice":"...","output_format":"mp3"}
play-showcase
repository
and run the tts-websocket
app locally.
https://api.play.ai/api/v1/tts/websocket-auth
endpoint with the following headers:
api_key
and user_id
from your PlayAI account.
The response will contain a JSON object with a webSocketUrls
field that you can use to connect to the WebSocket server according to the desired model.
webSocketUrls[<desired model>]
to your WebSocket client to establish a connection, such as in the following example:
snake_case
.
Here’s an example:
request_id
(optional): A unique identifier for the request, useful for correlating responses (see more details below).text
(required): The text to be converted to speech.voice
(required): The voice ID or URL to use for synthesis.output_format
(optional): The desired audio format (default is “mp3”).temperature
(optional): Controls the randomness of the generated speech (0.0 to 1.0).speed
(optional): The speed of the generated speech (0.5 to 2.0).{"type":"start","request_id":<request_id>}
to acknowledge the request.{"type":"end","request_id":<request_id>}
to indicate the end of the audio stream.request_id
is the unique identifier you provided in the TTS command, or null
if you didn’t provide one.{"type":"end","request_id":<request id>}
) is received.
It then creates an audio URL and plays the audio using the Web Audio API.