Integrate into Website and Apps
To integrate your agent into your website or mobile app, use this endpoint. You can send and receive audio in real time, which allows for seamless and natural conversations.
This integration has four parts:
- Create a widget agent in Synthflow.
- Request a short-lived websocket session URL with your API key.
- Stream microphone audio to the websocket and play back agent audio from websocket messages.
- Wrap the connection, recording, and playback logic in your own client application.
Step 1. Create a widget agent
In your Synthflow dashboard, create an agent of the type widget. For more details on how to do that, see Create an agent.
Step 2. Request a session
Make a GET request to the following endpoint:
It will return a response of the form:
You can then use this session URL to connect to the websocket.
Step 3. Send and receive events
At a high level, the websocket contract works like this:
- Your client sends raw PCM16 microphone audio at 48 kHz.
- Your client also sends a JSON readiness event when it is prepared to receive speech.
- Synthflow returns raw PCM16 agent audio at 16 kHz.
- Synthflow also returns JSON status events, including the signal that the agent is ready.
Send events
You can send two types of messages through the websocket:
- Binary messages containing the user’s speech (raw PCM16 audio, sample rate of 48000).
- JSON messages (
{ "type": "status_client_ready" }) to signal that you are ready for the agent to start speaking.
Receive events
You will receive two types of messages:
- Binary messages containing the agent’s speech (raw PC16 audio, sample rate 16000).
- JSON messages (
{ "type": "status_agent_ready" }) that signal that the agent is ready to start receiving audio.
Writing a client
To use the websocket connection in a webpage, follow these steps:
The sample implementation is split into three responsibilities:
- audio output playback
- microphone recording and PCM conversion
- websocket lifecycle management