Audio Control Service
About 2085 wordsAbout 7 min
2025-05-29
Provides robot system audio service controller. Through AudioController, you can control robot audio and obtain status via RPC communication.
Interface Definition
AudioController
is a C++ class that encapsulates audio control functionality, mainly used for audio playback control, TTS playback, volume setting and query, etc.
AudioController
Item | Content |
---|---|
Function Name | AudioController |
Function Declaration | AudioController(); |
Function Overview | Initialize audio controller object, construct internal state, allocate resources, etc. |
Notes | Constructs internal state. |
~AudioController
Item | Content |
---|---|
Function Name | ~AudioController |
Function Declaration | ~AudioController(); |
Function Overview | Release audio controller resources, ensure playback stops and clean up underlying resources. |
Notes | Ensure safe resource release. |
Initialize
Item | Content |
---|---|
Function Name | Initialize |
Function Declaration | bool Initialize(); |
Function Overview | Initialize audio control module, prepare playback resources and devices. |
Return Value | true indicates success, false indicates failure. |
Notes | Used in conjunction with Shutdown() . |
Shutdown
Item | Content |
---|---|
Function Name | Shutdown |
Function Declaration | void Shutdown(); |
Function Overview | Close audio controller and release resources. |
Notes | Ensure called before destruction. |
Play
Item | Content |
---|---|
Function Name | Play |
Function Declaration | Status Play(const TtsCommand& cmd); |
Function Overview | Play TTS (Text-to-Speech) voice command. |
Parameter Description | cmd : TTS command, containing text, speech rate, tone, etc. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Blocking interface, ensure module is initialized before calling. |
Stop
Item | Content |
---|---|
Function Name | Stop |
Function Declaration | Status Stop(); |
Function Overview | Stop current audio playback. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Blocking interface, typically used to interrupt current speech. |
SetVolume
Item | Content |
---|---|
Function Name | SetVolume |
Function Declaration | Status SetVolume(int volume); |
Function Overview | Set audio output volume. |
Parameter Description | volume : Volume value, typically range 0~100. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Blocking interface, takes effect immediately after setting. |
GetVolume
Item | Content |
---|---|
Function Name | GetVolume |
Function Declaration | Status GetVolume(int& volume); |
Function Overview | Get current audio output volume. |
Parameter Description | volume : Returns current volume value by reference. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Blocking interface, check return value before using volume . |
OpenAudioStream
Item | Content |
---|---|
Function Name | OpenAudioStream |
Function Declaration | Status OpenAudioStream(); |
Function Overview | Open audio stream, prepare for audio playback. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Blocking interface, check return value to ensure successful execution |
CloseAudioStream
Item | Content |
---|---|
Function Name | CloseAudioStream |
Function Declaration | Status CloseAudioStream(); |
Function Overview | Close audio stream. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Blocking interface, check return value to ensure successful execution |
SubscribeOriginAudioStream
Item | Content |
---|---|
Function Name | SubscribeOriginAudioStream |
Function Declaration | void SubscribeOriginAudioStream(const OriginAudioStreamCallback callback); |
Function Overview | Subscribe to original audio stream data. |
Parameter Description | callback : Audio stream data callback function. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Non-blocking interface. |
SubscribeBfAudioStream
Item | Content |
---|---|
Function Name | SubscribeBfAudioStream |
Function Declaration | void SubscribeBfAudioStream(const BfAudioStreamCallback callback); |
Function Overview | Subscribe to BF audio stream data. |
Parameter Description | callback : Audio stream data callback function. |
Return Value | Status::OK indicates success, others indicate failure. |
Notes | Non-blocking interface. |
Type Definitions
TtsPriority
— TTS Playback Priority Level
Used to control interrupt behavior between different TTS tasks. Higher priority tasks will interrupt current lower priority task playback.
Enumeration Value | Description |
---|---|
TtsPriority::HIGH | Highest priority, e.g.: low battery warning, emergency alerts |
TtsPriority::MIDDLE | Medium priority, e.g.: system prompts, status announcements |
TtsPriority::LOW | Lowest priority, e.g.: daily voice conversation, background announcements |
TtsMode
— Task Scheduling Strategy Under Same Priority
Used to fine-tune control of playback order and clearing logic for multiple TTS tasks under the same priority condition.
Enumeration Value | Description |
---|---|
TtsMode::CLEARTOP | Clear all tasks of current priority (including currently playing and waiting queue), immediately play this request |
TtsMode::ADD | Append this request to the end of current priority queue, play in order (without interrupting current playback) |
TtsMode::CLEARBUFFER | Clear unplayed requests in queue, keep current playback, then play this request |
Structure Definitions
TtsCommand
— TTS Playback Command Structure
Describes complete information for a TTS playback request, supporting unique identifier, text content, priority control, and scheduling mode under same priority.
Field Name | Type | Description |
---|---|---|
id | std::string | TTS task unique ID, e.g. "id_01" , used to track playback status |
content | std::string | Text content to be played, e.g. "Hello, welcome to the intelligent voice system." |
priority | TtsPriority | Playback priority, controls whether to interrupt currently playing lower priority speech |
mode | TtsMode | Scheduling strategy under same priority, controls whether tasks are appended, overridden, etc. |
AudioStream
- Audio Stream Structure
Describes original audio stream or BF audio stream data.
Field Name | Type | Description |
---|---|---|
data_length | int32_t | Data length |
raw_data | std::vector<uint8_t> | Audio stream data |