New in 3.19From Rasa Pro 3.19, you can stream conversation audio to your Rasa
assistant from your own mobile or web app over a plain WebSocket.
Configure Rasa Assistant
Use the built-in channelwebsockets_voice to configure your Rasa assistant.
Create or edit the credentials.yml file at the root of your assistant
directory to add the websockets_voice channel. Here’s an example:
credentials.yml
-
server_url(required): The domain at which the Rasa server is available. Do not include the protocol (ws://orwss://). For example, if your server is deployed onhttps://example.ngrok.app,server_urlshould beexample.ngrok.app. -
asr(required): Configuration for Automatic Speech Recognition. See Speech Integrations for the list of ASR engines Rasa integrates with. -
tts(required): Configuration for Text-To-Speech. See Speech Integrations for the list of TTS engines Rasa integrates with. -
interruptions(optional): Configuration for interruption handling. This lets the assistant detect when a user speaks over it and respond more naturally. See Interruption Handling for more information. -
silence_timeout(optional): Number of seconds of silence after which the current user turn is closed. Set this when you want the assistant to react to a pause in speech.
rasa run. Your app needs a URL that can reach the Rasa
server. For development, you can expose your local server with tools like
ngrok or
Cloudflare Tunnel.
Bot URLs for developmentVisit this section to learn how to generate
the required bot URL when testing the channel on your local machine.
Connecting Your App
Your app connects to the WebSocket endpoint exposed by the channel:GET request to /webhooks/websockets_voice/ returns {"status": "ok"},
which you can use as a health check.
Audio Format
Audio is exchanged in both directions as Linear PCM (L16), 24 kHz, mono, 16-bit. Rasa supports 24 kHz natively, so no server-side transcoding is required. Your app must capture and play back audio at this sample rate.WebSocket Protocol
The client and server exchange JSON text frames. Audio payloads are base64-encoded PCM data.Client to Server
Send captured audio:Server to Client
Synthesized assistant audio to play back:custom response. The channel sends it as data rather than speaking it, so
your app can act on it silently (for example, to refresh an expired token):
Playback Markers
The server tags bot audio with markers so it can track what the client has actually played. When your app finishes playing a chunk of audio, send the matchingmarker frame back. Rasa uses these acknowledgements to know when
the assistant has stopped speaking and, for example, when it is safe to end
the call after a goodbye message. An app that ignores markers still plays
audio, but the assistant cannot reliably tell when playback has finished.
Sending and Receiving Messages
When a user speaks, your app streams the audio frames to Rasa. The configured ASR engine converts speech to text, and Rasa interprets the message like any other channel. The assistant responds with text, the configured TTS engine converts it to speech, and the audio streams back to your app.domain.yml
Only text and audio are supported. Images, attachments, and buttons cannot be
used with voice stream channels. Custom (
custom) responses are delivered to
the client as data frames instead of being spoken.Passing Client Data to Actions
Your app can attach per-user data when it opens the WebSocket, and that data is carried into every user turn. There are two ways to send it:- The
Authorizationheader on the WebSocket upgrade request, available under theauthorizationkey. - Any query argument on the connection URL, except
language.
extra field of the call metadata.
A custom action can read them from the
latest message or from the session_started_metadata slot:
actions.py
extra field only forwards these values to your assistant. It does not
authenticate the WebSocket connection, and returning a token here does not
restrict who can connect. Enforce access control in your custom actions or in
front of the Rasa server. Client-supplied values are confined to extra, so
they cannot overwrite call parameters such as call_id.
The language query argument is reserved: it sets the language of the call
rather than being forwarded in extra.
Call Metadata
Metadata about the call can be accessed through thesession_started_metadata
slot at the beginning of the conversation. The following fields are available:
A custom
action_session_start can be used to store this information to a slot.