Treatment recordMono

record/audio::recordMono


Parameters

↳ var device: Option<string>
↳ var sample_rate: Option<u32>

Inputs

⇥ trigger: Block<void>

Outputs

↦ errors: Stream<string>
↦ failed: Block<void>
↦ info: Block<AudioInfo> (audio/audio_info::AudioInfo)
↦ signal: Stream<f32>


Record from the default audio input device as a normalised mono f32 signal.

Capture starts immediately when the treatment is activated. Samples are emitted through signal as a continuous stream of f32 values in the range [-1.0, 1.0].

If the input device has more than one channel, all channels are mixed down to mono by averaging each frame across channels before emission.

The sample format and channel count are determined automatically from the default configuration reported by the host for the default input device. The optional device parameter can be set to the name of a specific input device to use instead of the system default. When none, the system default input device is used.

The optional sample_rate parameter requests a specific capture rate (e.g. 16000, 44100, 48000). The device must support the requested rate; if it does not, a fatal error is emitted and capture does not start. When none, the device default rate is used.

errors emits a message for every problem encountered during capture:

  • recoverable problems (a transient stream error reported by the driver) produce one message and capture continues;
  • fatal problems (no input device available, unsupported sample format, unsupported sample rate, stream build failure) produce one message, trigger failed, and close all outputs immediately.

failed triggers if and only if capture cannot continue at all, regardless of whether any samples were already emitted on signal before the failure occurred.

⚠️ The treatment runs until the downstream consumer closes signal or until a fatal error occurs. It does not stop on its own.

graph LR
     T("recordMono()")
     T -->|signal| S["−0.3 … 0.7"]
     T -->|info| I["AudioInfo"]
     T -->|errors| E["…"]
     T -->|failed| F["⬛"]

     style S fill:#ffff,stroke:#ffff
     style I fill:#ffff,stroke:#ffff
     style E fill:#ffff,stroke:#ffff
     style F fill:#ffff,stroke:#ffff