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. 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 theASREngine 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 toASREventobjects.get_default_config(rasa_language): Return defaults for the assistant language.
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 apassstatement.close_connection(): Add provider-specific cleanup when needed. The base implementation flushes buffered audio and closes the WebSocket.
ASR Events
Yourengine_event_to_asr_event method should return appropriate ASREvent objects:
UserIsSpeaking(transcript): For interim/partial transcripts while the user is speakingNewTranscript(transcript): For final transcripts when the user has finished speaking
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
Configure a custom ASR component
To use a custom ASR component, configure its module path and settings in yourcredentials.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
MY_ASR_API_KEY environment variable before starting Rasa. The example reads this variable when it opens the provider connection.