record_stream
Signature:
BoosterAudioManager.record_stream(
sample_rate: int = 16000,
channels: int = 1,
sample_format: PcmSampleFormat = "S16LE",
*,
use_naec: bool = False,
chunk_bytes: int | None = None,
stop_event: threading.Event | None = None,
) -> Iterator[AudioData]
Description:
Reads microphone input as a generator, continuously yielding AudioData audio chunks.
Parameters:
Parameter | Type | Default | Description |
|---|---|---|---|
|
|
| Sample rate in Hz. |
|
|
| Number of channels. |
|
|
| PCM sample format, see "Perception and State Data / PcmSampleFormat". |
|
|
| Whether to prioritize NAEC audio. |
|
|
| When not |
|
|
| External stop signal. |
Returns:
Iterator[AudioData], see "Perception and State Data / AudioData"
Raises:
ValueError: Invalid sample format, sample rate, channels, or chunk_bytes.
RuntimeError: Audio subsystem is closed, or an error occurred during capture.
Example:
import threading
from boosteros.robots.booster import BoosterRobot
robot = BoosterRobot()
stop_event = threading.Event()
for index, chunk in enumerate(
robot.audio_manager.record_stream(chunk_bytes=4096, stop_event=stop_event)
):
print(chunk.duration.seconds)
# Example output: 0.128
if index >= 2:
stop_event.set()