Skip to content

Speech Service Interfaces

Introduction

Speech Service Interfaces:
Provides robot speech functionality through the Speech singleton, including Audio Front-End processing (AFE), Automatic Speech Recognition (ASR), Keyword Wake-up (KWS), and Text-to-Speech (TTS).

PurposePython
Get Speech API Instance
Audio Front-End Processing (AFE)
Acoustic Echo Cancellation (AEC)
Speech Enhancement
Speech Recognition (ASR)
Keyword Wake-up (KWS)
Text-to-Speech (TTS)
Speech Event Callbacks

Singleton Access

Python Interface

Speech.get_instance()

Function Description
Get the Speech singleton instance. There is only one Speech instance per program lifecycle.

Parameter Description

No parameters.

Return Value

TypeDescription
SpeechSpeech API singleton instance.

Example

python
from daystar_api.lowlevel_skills import Speech

speech = Speech.get_instance()

AFE Audio Front-End

Python Interface

speech.enable_afe_engine(enable, block=True, timeout=5)

Function Description
Enable or disable the Audio Front-End (AFE) engine. AFE is the foundational module for speech processing; AEC and speech enhancement require AFE to be enabled first.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

Example

python
speech = Speech.get_instance()
speech.enable_afe_engine(True)

speech.enable_aec(enable, block=True, timeout=5)

Function Description
Enable or disable Acoustic Echo Cancellation (AEC), reducing interference from speaker audio on the microphone.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

Example

python
speech.enable_aec(True)

speech.enable_speech_enhance(enable, block=True, timeout=5)

Function Description
Enable or disable speech enhancement to improve voice quality in noisy environments.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

Example

python
speech.enable_speech_enhance(True)

speech.set_bypass(enable, block=True, timeout=5)

Function Description
Set AFE bypass mode. In bypass mode, audio passes through directly without processing.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable bypass, False to disable bypass.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

speech.mute_clean_mic(enable, block=True, timeout=5)

Function Description
Mute/unmute the clean microphone channel.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to mute, False to unmute.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

ASR Speech Recognition

Python Interface

speech.enable_asr(enable, block=True, timeout=5)

Function Description
Enable or disable Automatic Speech Recognition (ASR). When enabled, speech input is transcribed to text in real-time and delivered via the registered ASR callback.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

Example

python
from daystar_api.lowlevel_skills import Speech

speech = Speech.get_instance()

def on_asr(event):
    if event.is_final:
        print(f"Recognition result: {event.text}")

speech.register_asr_callback(on_asr)
speech.enable_asr(True)

speech.switch_asr_device(device, block=True, timeout=5)

Function Description
Switch the audio input device used by ASR.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
devicestrRequiredTarget audio device name.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

KWS Keyword Wake-up

Python Interface

speech.enable_hexaware(enable, block=True, timeout=5)

Function Description
Enable or disable the Hexaware wake word detection engine.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

speech.enable_kws(enable, block=True, timeout=5)

Function Description
Enable or disable Keyword Spotting (KWS).

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

TTS Text-to-Speech

Python Interface

speech.enable_tts(enable, block=True, timeout=5)

Function Description
Enable or disable the Text-to-Speech (TTS) engine.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
enableboolRequiredTrue to enable, False to disable.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

speech.generate_audio(text, block=True, timeout=30)

Function Description
Convert text to speech and play it. Supports both blocking (waits for playback to finish) and non-blocking (returns an AudioFuture immediately) modes.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
textstrRequiredText content to synthesize and play.
blockboolTrueIf True, blocks until playback completes; if False, returns immediately.
timeoutint30Timeout in seconds.

Return Value

TypeDescription
GenerateAudioResponseWhen block=True, returns the playback result; when block=False, response.future is an AudioFuture — call .get(timeout) to wait for the result.

Example

python
speech = Speech.get_instance()
speech.enable_tts(True)

# Blocking playback
speech.generate_audio("Hello, I am a robot")

# Non-blocking playback
resp = speech.generate_audio("Starting task execution", block=False)
# Do other work...
result = resp.future.get(timeout=10)

speech.stop_playing_tts(timeout=5)

Function Description
Immediately stop the currently playing TTS audio.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

speech.cancel_generate_audio(timeout=5)

Function Description
Cancel the currently running audio generation task.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

speech.switch_tts_device(device, block=True, timeout=5)

Function Description
Switch the audio output device used by TTS.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
devicestrRequiredTarget audio device name.
blockboolTrueIf True, blocks until completion.
timeoutint5Timeout in seconds.

Return Value

TypeDescription
EnableServiceResponsestate.code == 0 indicates success.

Event Callbacks

Python Interface

speech.register_asr_callback(callback)

Function Description
Register an ASR speech recognition result callback. Triggered whenever speech is recognized; event.is_final == True indicates the final recognition result.

Example

python
def on_asr(event):
    if event.is_final:
        print(f"Final result: {event.text}")
    else:
        print(f"Intermediate result: {event.text}")

speech.register_asr_callback(on_asr)

speech.register_hexaware_callback(callback)

Function Description
Register a wake word detection callback; receives HexawareAwakenEvent.


speech.register_kws_message_callback(callback)

Function Description
Register a keyword recognition callback; receives KwsMessageEvent.


speech.register_nlu_format_callback(callback)

Function Description
Register a Natural Language Understanding (NLU) formatted result callback; receives NluFormatEvent.


speech.register_generate_audio_callbacks(progress_cb=None, complete_cb=None)

Function Description
Register progress and completion callbacks for TTS audio generation.

Example

python
def on_progress(event):
    print(f"TTS progress: {event.progress}%")

def on_complete(event):
    print("TTS playback complete")

speech.register_generate_audio_callbacks(
    progress_cb=on_progress,
    complete_cb=on_complete
)