Audio Module
AudioManager is the entry point for the audio module. Do not construct AudioPlayer, AudioRecorder, AudioLocalizer, or AudioCaptureStream directly. Initialize AudioManager, then create child objects through its factory methods.
Source headers:
include/booster/robot/audio/audio_manager.hinclude/booster/robot/audio/audio_player.hinclude/booster/robot/audio/audio_recorder.hinclude/booster/robot/audio/audio_localizer.hinclude/booster/robot/audio/audio_capture_stream.hinclude/booster/robot/audio/audio_types.h
Initialization
#include <booster/robot/audio/audio_manager.h>
#include <booster/robot/channel/channel_factory.hpp>
booster::robot::ChannelFactory::Instance()->Init(0, "<network_ip>");
booster::robot::audio::AudioManager manager;
if (manager.Init() != 0) {
return 1;
}
const bool ready = manager.IsInitialized();
const std::string client_id = manager.GetClientId();
// Shut down the manager after all child objects have been released.
manager.Shutdown();
AudioManager
Method | Description |
|---|---|
| Initialize or shut down audio resources. |
| Query manager state. |
| Return the client ID registered with the audio service. |
| Generate a request ID. |
| Create an audio player. |
| Create an audio recorder. |
| Create a sound-source localizer. |
| Create an audio-frame capture stream. |
| Set or read system output volume. The service accepts values in |
| Set or read the system mute state; the getter writes to its output argument. |
| Enumerate input or output endpoints. |
| Start or stop Bluetooth discovery; |
| Return known Bluetooth devices, optionally including unpaired devices. |
| Pair/connect an endpoint and optionally apply the default route according to |
| Disconnect a device by Bluetooth address. |
| Remove pairing/trust information for a device. |
| Register a service-level progress-topic callback. |
| Register a service-level event-topic callback. |
| Register a service-level error-topic callback. |
| Register a Bluetooth state-event callback. |
System volume and mute state:
manager.SetSystemVolume(0.6F);
float volume = 0.0F;
manager.GetSystemVolume(&volume);
manager.SetSystemMute(false);
bool muted = false;
manager.GetSystemMute(&muted);
Player
AudioPlayer supports PCM, WAV, and MP3 files as well as PCM streams.
File playback:
#include <booster/robot/audio/audio_player.h>
auto player = manager.CreatePlayer();
booster::robot::audio::PlayerInitOptions options;
options.source_type = booster::robot::audio::AudioSourceType::kWavFile;
options.source_uri = "<audio.wav>";
options.priority = booster::robot::audio::PlayerPriority::kMedium;
if (player->Init(options) == 0) {
player->Start();
booster::robot::audio::PlayerInfo info;
player->GetInfo(&info);
player->Stop();
player->Release();
}
PCM stream:
#include <cstdint>
#include <vector>
auto player = manager.CreatePlayer();
booster::robot::audio::PlayerInitOptions options;
options.source_type = booster::robot::audio::AudioSourceType::kPcmStream;
options.sample_rate_hz = 16000;
options.channels = 1;
options.bits_per_sample = 16;
if (player->Init(options) == 0) {
player->Start();
std::vector<uint8_t> pcm(3200, 0);
player->PushPcmStream(pcm.data(), pcm.size());
player->Stop();
player->Release();
}
Available callbacks:
SetStateCallback(callback)SetProgressCallback(callback)SetCompletionCallback(callback)SetErrorCallback(callback)
Public player interface:
C++ method | Python method | Description |
|---|---|---|
|
| Create the playback session and negotiate the input format; returns 0 on success. |
|
| Start or resume playback; |
|
| Pause playback while retaining the current position. |
|
| Stop playback and reset the play cursor. |
|
| Reset a stopped or completed player for reuse. |
|
| Release the service-side playback session. |
|
| Compatibility alias for |
|
| Set session volume in the range |
|
| Select the preferred output endpoint for this session; use an output device ID. |
|
| Read the cached playback snapshot, including state, byte progress, and volume. |
|
| Push non-empty PCM bytes to a |
|
| Return the service-side session ID. |
|
| Read the latest locally observed state without an RPC. |
|
| Invoke the callback with |
|
| Invoke the callback with |
|
| Invoke once when the state first becomes |
|
| Invoke with |
Call SetPreferredDevice only after a successful Init. File source_uri values must be absolute paths readable by the robot-side audio service; PCM files also require the correct sample rate, channel count, and sample width. Streaming requires source_type == kPcmStream; the URI may be empty, but pushed data must be non-empty.
Recorder
#include <booster/robot/audio/audio_recorder.h>
auto recorder = manager.CreateRecorder();
booster::robot::audio::RecorderInitOptions options;
options.output_path = "<record.wav>";
options.sample_rate_hz = 16000;
options.channels = 1;
options.bits_per_sample = 16;
if (recorder->Init(options) == 0) {
recorder->Start();
booster::robot::audio::RecorderInfo info;
recorder->GetInfo(&info);
recorder->Stop();
recorder->Release();
}
Available callbacks:
SetStateCallback(callback)SetProgressCallback(callback)SetErrorCallback(callback)
Public recorder interface:
C++ method | Python method | Description |
|---|---|---|
|
| Create a recording session. The output path must be an absolute path writable by the robot audio service. |
|
| Start or resume recording; |
|
| Pause recording while retaining the session. |
|
| Stop recording and finalize the output file. |
|
| Release the service-side recording session. |
|
| Compatibility alias for |
|
| Read the cached recorder state and captured-byte count. |
|
| Select the preferred input endpoint for this session; use an input device ID. |
|
| Return the service-side session ID. |
|
| Read the latest locally observed state without an RPC. |
|
| Invoke the callback with |
|
| Invoke the callback with |
|
| Invoke with |
sample_rate_hz, channels, and bits_per_sample must all be positive. Running recording sessions currently cannot migrate input devices; stop/destroy and reinitialize with the new device. After recording, explicitly call Stop and then Destroy or Release.
Audio Capture Stream
AudioCaptureStream subscribes to audio frames and can request raw PCM and NAEC PCM.
#include <iostream>
#include <booster/robot/audio/audio_capture_stream.h>
auto capture = manager.CreateCaptureStream();
booster::robot::audio::AudioCaptureStreamOptions options;
options.enable_raw_pcm = true;
options.enable_naec_pcm = false;
options.requested_raw_format = {16000, 1, 16};
capture->SetFrameCallback(
[](const booster::robot::audio::AudioCaptureFrame &frame) {
if (frame.raw_valid) {
std::cout << frame.frame_seq << " "
<< frame.raw_pcm.size() << "\n";
}
});
if (capture->Init(options) == 0) {
capture->Start();
// Process callbacks while the stream is active.
capture->Stop();
capture->Destroy();
}
Available methods:
Init(options)Start()/Pause()/Stop()/Destroy()GetInfo(out)SetPreferredDevice(device_id)SetFrameCallback,SetStateCallback, andSetErrorCallback
Sound-Source Localization
#include <booster/robot/audio/audio_localizer.h>
auto localizer = manager.CreateLocalizer();
int angle_deg = 0;
if (localizer->GetDoaAngle(&angle_deg) == 0) {
std::cout << angle_deg << "\n";
}
Device Queries and Bluetooth
Query input and output devices:
#include <vector>
std::vector<booster::robot::audio::AudioDeviceInfo> outputs;
manager.GetDevices(
booster::robot::audio::AudioDeviceQueryType::GET_DEVICES_OUTPUTS,
&outputs);
for (const auto &device : outputs) {
std::cout << device.device_id << " "
<< device.display_name << "\n";
}
Scan and connect over Bluetooth:
booster::robot::audio::BluetoothScanOptions scan;
scan.timeout_ms = 30000;
scan.audio_only = true;
manager.StartBluetoothScan(scan);
std::vector<booster::robot::audio::BluetoothDeviceInfo> devices;
manager.GetBluetoothDevices(true, &devices);
manager.StopBluetoothScan();
if (!devices.empty()) {
booster::robot::audio::BluetoothConnectOptions options;
options.address = devices.front().address;
options.preferred_profile =
booster::robot::audio::BluetoothAudioProfile::kNone;
booster::robot::audio::BluetoothConnectResult result;
manager.ConnectBluetoothDevice(options, &result);
}
Bluetooth methods:
StartBluetoothScan(options)StopBluetoothScan()GetBluetoothDevices(include_unpaired, devices)ConnectBluetoothDevice(options, result)DisconnectBluetoothDevice(address)ForgetBluetoothDevice(address)
Event Callbacks
AudioManager supports global topic callbacks:
SetProgressCallback(callback)SetEventCallback(callback)SetErrorCallback(callback)SetBluetoothEventCallback(callback)
Child objects also provide state, progress, error, completion, or frame callbacks. Callbacks run from DDS topic handling; avoid long blocking operations inside them.
Complete Types and Enums
This section merges the public audio_sdk_guide.pdf with the current public headers. When the PDF and headers differ, the current headers are authoritative. For example, AudioCaptureStreamOptions::requested_raw_format currently defaults to 16000/3/16 (16 kHz, three channels, 16 bit); the negotiated service format must still be read from AudioCaptureStreamInfo.
AudioSourceType:
Enumerator | Value | Meaning |
|---|---|---|
|
| Read raw PCM from a robot-side file; provide the correct sample rate, channels, and width. |
|
| Play a WAV file at an absolute path accessible to the robot audio service. |
|
| Feed PCM chunks with |
|
| Play an MP3 file when the deployed audio service provides the codec. |
State and priority enums:
Enum | Values | Meaning |
|---|---|---|
|
| Not initialized, initialized and ready, or currently playing. |
|
| Paused, stopped by the caller, reached end of source, or terminated by an error. |
|
| Low, normal, or high arbitration priority; high priority may preempt lower priority playback. |
|
| Not initialized, ready, or recording. |
|
| Paused, stopped, or terminated by an error. |
|
| Not initialized, negotiated and ready, or publishing frames. |
|
| Paused, stopped, or terminated by an error. |
Device and Bluetooth enums:
Enum | Values | Meaning |
|---|---|---|
|
| Enumerate input / output devices. |
|
| Input / output endpoint direction. |
|
| Built-in, USB, or Bluetooth transport. |
|
| Virtual endpoint or unknown transport. |
|
| PulseAudio-compatible backend. |
|
| BoosterAEC microphone-array backend, commonly used for NAEC/localization. |
|
| ALSA diagnostic endpoint. |
|
| No scan is running / discovery is active. |
|
| Unknown state / paired but not connected. |
|
| Connecting / connected. |
|
| Disconnecting / most recent connection failed. |
|
| Audio/video device, peripheral, or phone class. |
|
| Computer class, or another/unknown class. |
|
| No preferred or active profile. |
|
| A2DP playback sink / audio source; headphones normally use the sink role. |
|
| HFP headset / audio-gateway role; select HFP explicitly for a headset microphone. |
Public Topic enums ( include/booster/idl/audio/AudioCommon.h )
These enums classify public Topic sessions, events, and errors. Values start at zero in declaration order. They are distinct from AudioError.ret_code, which is the RPC/business error code (for example 7001).
SessionType:
Enumerator | Value | Description |
|---|---|---|
|
| A player session; Topics describe playback state or progress. |
|
| A recorder session; Topics describe recording state or progress. |
|
| Session classification for direction-of-arrival requests or results. |
|
| A raw/NAEC real-time capture stream session. |
AudioErrorCode:
Enumerator | Value | Description |
|---|---|---|
|
| The audio service is reachable but operating in a degraded state. |
|
| The current session state does not allow the requested operation. |
|
| The requested audio device is occupied by another operation. |
|
| The target hardware or backend does not support the capability. |
|
| Direction-of-arrival localization is unavailable. |
|
| The requested ALSA device could not be found. |
|
| Audio algorithm initialization failed. |
|
| Audio algorithm processing failed. |
|
| System-volume control failed. |
|
| System-mute control failed. |
|
| Media decoding failed. |
|
| Media encoding failed. |
|
| The media format is unsupported. |
AudioEventCode:
Enumerator | Value | Description |
|---|---|---|
|
| Player initialization succeeded. |
|
| Player start or resume succeeded. |
|
| Player pause succeeded. |
|
| Player stop succeeded. |
|
| Player reset succeeded. |
|
| Player session destruction succeeded. |
|
| Recorder initialization succeeded. |
|
| Recorder start or resume succeeded. |
|
| Recorder pause succeeded. |
|
| Recorder stop succeeded. |
|
| Recorder session destruction succeeded. |
|
| The player entered a terminal state such as completed or error. |
|
| System-volume update succeeded. |
|
| System-mute update succeeded. |
|
| Capture-stream initialization and format negotiation succeeded. |
|
| Capture-stream publishing started successfully. |
|
| Capture-stream pause succeeded. |
|
| Capture-stream stop succeeded. |
|
| Capture-stream session destruction succeeded. |
AudioErrorCategory:
Enumerator | Value | Description |
|---|---|---|
|
| RPC transport or common request error. |
|
| Playback business error. |
|
| Recording business error. |
|
| Capture-stream runtime error. |
|
| Direction-of-arrival localization error. |
|
| System-volume control error. |
|
| System-mute control error. |
|
| Internal service error; applications should still record |
AudioErrorDetail:
Enumerator | Value | Description |
|---|---|---|
|
| No more specific operation is identified. |
|
| Player initialization operation. |
|
| Player start operation. |
|
| Player pause operation. |
|
| Player stop operation. |
|
| Player reset operation. |
|
| Player destruction operation. |
|
| Player-information query. |
|
| PCM stream data submission. |
|
| Recorder initialization operation. |
|
| Recorder start operation. |
|
| Recorder pause operation. |
|
| Recorder stop operation. |
|
| Recorder destruction operation. |
|
| Recorder-information query. |
|
| Direction-of-arrival query. |
|
| System-volume update operation. |
|
| System-volume query. |
|
| System-mute update operation. |
|
| System-mute query. |
|
| Capture-stream initialization operation. |
|
| Capture-stream start operation. |
|
| Capture-stream pause operation. |
|
| Capture-stream stop operation. |
|
| Capture-stream destruction operation. |
|
| Capture-stream information query. |
Public structure fields
PcmFormatcontainssample_rate_hz(default 16000),channels(default 1), andbits_per_sample(default 16).PlayerInitOptionscontainssource_type,source_uri, sample rate, channels, width, andpriority. File paths must be accessible to the robot audio service; a PCM stream may leave the URI empty.RecorderInitOptionscontainsoutput_path, sample rate, channels, and width. The path must be an absolute, writable robot-side path and numeric values must be positive.AudioCaptureStreamOptionscontainsenable_raw_pcm(default true),enable_naec_pcm(default false), andrequested_raw_format. At least one stream must be enabled; raw requests currently accept only 16-bit samples and NAEC depends on BoosterAEC/hardware support.PlayerInfocontainsstate,played_bytes,total_bytes, andvolume;RecorderInfocontainsstateandcaptured_bytes.AudioCaptureFramecontainsframe_seq,timestamp_ms, and for raw/NAEC each*_validflag, actual format, samples per channel, and an int16*_pcmarray.AudioCaptureStreamInfocontains state, raw/NAEC enable flags, negotiated formats,published_frames, anddropped_frames.AudioDeviceInfocontains device ID, display name, direction, transport, backend affinity, availability/default flags, input/output capabilities, provider/native IDs, andmetadata_json.AudioErrorcontainsret_code,ret_msg,error_category, anderror_detail.BluetoothDeviceInfocontains address, name, RSSI, state, major class, paired/trusted/ connected flags, sink/source/HFP capabilities, connected profiles, Pulse sink/source IDs, and the last-seen timestamp.BluetoothScanOptionscontainstimeout_ms(default 30000, never negative) andaudio_only.BluetoothConnectOptionscontains requiredaddress,auto_pair,make_default,preferred_profile, andtimeout_ms(strictly positive). The connection RPC timeout ismax(5000, timeout_ms).BluetoothConnectResultcontains the connected device, Pulse sink/source IDs, active profile, endpoint readiness, default-route flags, and default-route error code/message.
Lifecycle, callbacks, and routing
Audio objects follow manager.Init -> object.Init -> Start/Pause/Stop -> Destroy. Release exists only on player and recorder and is equivalent to Destroy; capture streams have no Release. GetCachedState reads local cache and does not make an RPC; call GetInfo for a service-side snapshot. Running recorder/capture sessions currently cannot migrate input devices, so stop and reinitialize them.
SetPreferredDevice selects the current session’s preferred endpoint; it does not change the system default. Players use IDs from GetDevices(GET_DEVICES_OUTPUTS); recorders and capture streams use input IDs. Global topics can contain messages for multiple objects in one process; filter by client_id, request_id, session_type, session_id, and timestamp_ms.
Bluetooth headphones are normally connected with A2DP for playback. To use a headset microphone, disconnect and reconnect with BluetoothAudioProfile::kHfpHeadset. Automatic reconnect normally remains A2DP and does not switch to HFP. Inspect default_* fields in BluetoothConnectResult when make_default is enabled.
Error codes
In addition to common RPC statuses (-1 invalid, 0 success, 100 timeout, 400 bad request, 409 conflict, 429 too frequent, 500 internal, 501 refused, and 502 state transition failed), common audio-service codes are: 2001 service degraded, 4001 Bluetooth unavailable, 4002 busy, 4003 unknown device, 4004 pairing failed, 4005 connection failed, 4006 timeout, 4007 not an audio device, 4008 profile unsupported, 4009 authentication rejected, 5001 device busy, 7001 kAudioErrNotSupported, 7002 localization unavailable, 7003 ALSA not found, 7004/7005 algorithm initialization/processing failed, 7006 system-volume failure, 7007 mute failure, 7008 decode failure, 7009 encode failure, and 7010 format unsupported. Also record AudioError.ret_msg.
PDF guide and Python
Complete audio guide: download audio_sdk_guide.pdf. The PDF’s C++ lifecycle, WAV/PCM streaming, recording, raw/NAEC capture, device, and Bluetooth examples are merged into this page. Python bindings use PascalCase names such as GetDevices, SetPreferredDevice, and ConnectBluetoothDevice; high-level failures are commonly wrapped as RuntimeError. Interactive examples include player_init, player_stream_init, rec_init, devices inputs|outputs, bt_scan, bt_connect, cap_init, and cap_destroy.
Detailed Public Interfaces
The following tables enumerate the methods in the current public headers. Check every int32_t return value: 0 means that local validation and the RPC succeeded; a nonzero value reports a transport, service, or argument error.
AudioManager methods
Interface | Description |
|---|---|
| Construct an uninitialized manager; destruction removes listeners and releases RPC resources. |
| Initialize the DDS audio runtime and register a |
| Stop global topic subscribers and release manager resources; call it after child sessions are destroyed. |
| Return whether manager initialization completed; no RPC is made. |
| Return the service-registered client ID used to filter global callback messages. |
| Generate a client-unique request ID for diagnostics and topic correlation. |
| Create the corresponding child object. Player, recorder, and capture objects still need |
| Set or query the global output volume. The output overload writes through its pointer. |
| Set or query the global mute switch; this is not a player-session volume. |
| Enumerate input or output endpoints using |
| Start or stop discovery; timeout and |
| Return known Bluetooth devices, optionally including unpaired devices. |
| Pair/connect by address, optionally selecting A2DP/HFP and applying a default route. |
| Disconnect an endpoint without removing pairing information. |
| Remove pairing/trust information so that the device must be paired again. |
| Register global progress or event topic callbacks; messages can belong to multiple sessions. |
| Register global audio-error or Bluetooth-event callbacks. |
AudioPlayer methods
Interface | Description |
|---|---|
| Create the service playback session; file sources need robot-side absolute paths, while streaming uses |
| Start or resume, pause, or stop playback. Streaming must start before data is pushed. |
| Reset a stopped or completed player for reuse without allocating another session ID. |
| Release the service session; |
| Set this playback session’s volume without changing the system volume. |
| Select the output endpoint for this session; use an output ID from |
| Query a service-side snapshot of state, byte progress, and session volume. |
| Push nonempty PCM bytes to a |
| Return the service session ID or read local state without making an RPC. |
| Receive |
| Invoke once when the session first reaches |
| Receive an |
AudioRecorder methods
Interface | Description |
|---|---|
| Create a recording session; |
| Start or resume, pause, or stop recording; stop explicitly to finalize the output file. |
| Release the recording session; |
| Query recording state and captured byte count; bytes can estimate duration. |
| Select the input endpoint for this session; use an ID from |
| Return the service session ID or read local state without making an RPC. |
| Receive |
| Receive recording errors and update the cached state. |
AudioLocalizer methods
Interface | Description |
|---|---|
| Query direction of arrival in degrees; a BoosterAEC/microphone-array backend is required, otherwise |
AudioCaptureStream methods
Interface | Description |
|---|---|
| Negotiate raw/NAEC streams and create a dedicated DDS data subscriber; at least one stream is required and raw requests currently accept only 16-bit samples. |
| Start, pause, or stop frame delivery while retaining the session. |
| Close the data subscriber and release the service capture session; this class has no |
| Query negotiated formats, enable flags, and published/dropped frame counters. |
| Select the input endpoint; live migration is normally unsupported. |
| Return the service session ID or read local state without making an RPC. |
| Receive each captured frame; process or hand off data quickly. |
| Receive state changes or |
Callback topic fields
Global callback arguments come from booster_msgs::audio. Python bindings expose the same callback message classes using PascalCase names:
Type or field | Description |
|---|---|
| The manager client ID and request ID; use them to filter and correlate messages. |
| Session category (player, recorder, capture, and so on) and service session ID. |
| Millisecond timestamp generated by the service. |
| Current position and total bytes; streaming sources may report zero/unknown duration. |
| Service state integer converted by the SDK to the object state. |
| Event value, state at event time, and backend diagnostic detail. |
| Error status and human-readable message. |
| Error classification and detail values for RPC, device, format, and other sources. |
| Event time, event name, and associated Bluetooth address. |
| Version-dependent event JSON and the operation error code (normally zero on success). |
Python mapping
src/python/binding.cpp exposes PascalCase names such as Init, Shutdown, CreatePlayer, CreateRecorder, CreateLocalizer, CreateCaptureStream, GetDevices, SetPreferredDevice, and ConnectBluetoothDevice. Output-pointer arguments become returned objects (for example, GetInfo() returns PlayerInfo), and nonzero statuses are usually raised as RuntimeError. PushPcmStream accepts bytes; capture and global callbacks receive the corresponding bound message objects.