Skip to main content

Custom ASR

Implement a custom provider when none of the built-in ASR engines meet your requirements. This guide covers the component class, transcript events, and credentials configuration.
Create Custom ASR with SkillsRasa MCP Tools includes AI Skills to scaffold and audit your custom ASR component with your IDE copilot. Run rasa tools init in your project root to install the agent skills.
You can implement your own custom ASR component as a Python class to integrate with any third-party speech recognition service. A custom ASR component must subclass the ASREngine class from rasa.core.channels.voice_stream.asr.asr_engine. Your custom ASR component receives audio as RasaAudioBytes in the format selected for the channel. Convert it if your provider expects a different encoding.

Required Methods

Your custom ASR component must provide the following methods:
  • name(): Return the engine name.
  • open_websocket_connection(): Establish a WebSocket connection to your ASR service.
  • from_config_dict(config, format, rasa_language, additional_languages): Create an engine from channel configuration.
  • signal_audio_done(): Signal that audio input has ended.
  • engine_event_to_asr_event(event): Convert provider messages to ASREvent objects.
  • get_default_config(rasa_language): Return defaults for the assistant language.
Override rasa_audio_bytes_to_engine_bytes() if the provider needs a different audio format. Its default implementation returns the audio bytes as-is.

Optional Methods

You may also override these methods as needed:
  • send_keep_alive(): Send keep-alive messages to maintain the connection. The default implementation is only a pass statement.
  • close_connection(): Add provider-specific cleanup when needed. The base implementation flushes buffered audio and closes the WebSocket.

ASR Events

Your engine_event_to_asr_event method should return appropriate ASREvent objects:
  • UserIsSpeaking(transcript): For interim/partial transcripts while the user is speaking
  • NewTranscript(transcript): For final transcripts when the user has finished speaking
See Configure a custom ASR component for the credentials configuration.

Example Implementation

This example shows the integration points. Replace the WebSocket URL, request parameters, and event parsing with the protocol used by your provider.
custom_asr.py
This structure allows you to integrate any speech recognition service with Rasa’s voice capabilities while maintaining compatibility with the existing voice stream infrastructure.

Configure a custom ASR component

To use a custom ASR component, configure its module path and settings in your credentials.yml file. The configuration should contain the module path of your custom class and any required configuration parameters. The module path follows the format path.to.module.ClassName. For example, a class MyASR in addons/custom_asr.py has module path addons.custom_asr.MyASR.

Custom ASR Configuration Example

credentials.yml
Set the MY_ASR_API_KEY environment variable before starting Rasa. The example reads this variable when it opens the provider connection.