A read-only audio value for recognizing sounds in an app or game. Use Audio(name) to load a saved sample, or Audio.recent(duration_ms) to copy recently captured audio. Capture and matching run on the device; continuous listening buffers are never uploaded and scripts cannot access raw audio (PCM).
Syntax
Audio(name)Constructor parameters
| Name | Description |
|---|---|
nameString | Required non-empty name of a sample created in this macro's Template Manager, not a file path. Loads immediately, including restored samples and samples in encrypted protected packages; missing or corrupt samples are errors. Backup/Store saves the selected source package and saved samples with the macro: at most 32 PCM16 mono 48 kHz WAV samples, each up to 10 seconds, and 4 MiB of WAV data in total. Required · Positional or named No default |
Returns
Example
# Recognize a local audio sample after listening starts
sample = Audio("alert")
Audio.start()
wait(2000)
clip = Audio.recent(duration_ms=2000)
result = clip.match(sample, threshold=0.85)
if result.matched:
print(result.score, result.start_ms, result.end_ms)
Audio.stop()Fields
| Name | Description |
|---|---|
nameString | None | Saved sample name, or None for a recent snapshot. |
duration_msNumber | Snapshot length in milliseconds. |
start_msNumber | Start time in milliseconds; zero for a named sample, session-relative for a recent snapshot. |
end_msNumber | Exclusive end time in milliseconds on the same timeline as start_ms. |
# Load a sample saved in this macro
audio = Audio("alert")