Microphone

microphone.py

Overview

microphone.py is a synthetic audio-channel selector that emulates the front-end of an ASR pipeline by publishing random “utterance IDs” at a fixed rate. It’s ideal for CI, headless simulation, or bandwidth-constrained environments where real ASR is unavailable.

Interfaces (strongly-typed, stateless)

Direction / Type

Topic

Semantics

Provided

/{robot}/mic_channel

Encoded Int32 utterance ID ∈ [0, _RANGE)

Contract

Pre-conditions

  • Node launched with a valid robot_id CLI argument.

  • _RANGE and _RATE constants set before import.

Post-conditions

  • Publishes exactly one std_msgs/Int32 per loop iteration.

  • Value is uniformly random in [0, _RANGE).

  • No other side-effects or state.

Invariants

  • Loop frequency = _RATE ± 5% (dependant on ROS scheduler).

  • Peak CPU ≤ 1% per instance.

Quality-of-Service KPIs

Metric

Target

Rationale

Message rate

1 Hz ± 0.1 Hz

Keeps downstream recogniser in sync.

Latency

< 200 ms

Avoids stale commands.

Packet loss

< 0.1 %

Ensures planners always receive input.

CPU load

< 1 %

Safe on TIAGo’s on-board computer.

Implementation notes

  • Draws labels via np.random.randint(_RANGE).

  • All logic lives in publish(); the main loop only maintains timing.

  • To extend: adjust _RANGE, _RATE, or seed NumPy for reproducible tests.

microphone.publish() None[source]

Select a random utterance ID and publish it.

Steps

  1. Generate a uniform random integer in [0, _RANGE).

  2. Wrap it in std_msgs/Int32.

  3. Publish on the namespaced mic_channel topic.