Skip to main content

audio

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Capture what the device plays: start, stop with a path to save it as a WAV, or omit the action to ask whether a capture is running. These call app_audio.

audio​

def audio(action: str | None=None, path: str | None=None, expect: list | None=None, ignore_ms: int | None=None, app: str | None=None) -> dict

Capture what the device plays: action "start", or "stop" with path to save a WAV; neither asks whether a capture is running.

Stop returns a timeline: segments with from and to in nanoseconds, sound, and for a sound its hz (0 when it has no one pitch) and level in dBFS, and the volumes it was taken at: each stream's index from min to max, and muted. Assert on sound, silence and pitch; the level follows the device's volume, and at its lowest a playing app is silence. An Android emulator only.

expect makes stop an assertion: the sounds to hear, in order, each {"hz": 440} with optional min_ms and max_ms; [] is silence. A sound of ignore_ms (default 200) or less on its own does not count, but short ones that run on into each other do. Anything else raises NotConfirmedError saying what was heard, and the capture is still saved.

Stop also returns interruptions — a call muting app (on start; default the app in front), a ringtone, alarm or notification over it, each with kind, from and to. On an Android phone only the interruptions are recorded: nothing outside it hears the sound.

Examples​

Start capturing what an app plays​

device.audio("start", app="dev.mobium.mobiumapp")

The same call from the command line, mobium audio start --app dev.mobium.mobiumapp, printed on an Android 15 emulator:

capturing audio — stop it with action "stop" and a path

Stop, save the capture, and assert what was heard​

heard = device.audio("stop", "heard.wav", expect=[{"hz": 440}])
for segment in heard["timeline"]:
print(segment)

The same call from the command line, mobium audio stop -o heard.wav --expect 440, printed on an Android 15 emulator:

saved …/heard.wav: 3.746s of audio: 0.0–0.5s silence, 0.5–0.6s sound, no one pitch (-46 dBFS), 0.6–2.6s 440 Hz (-42 dBFS), 2.6–3.7s silence — at media volume 5 of 15