ztcl::audio play
Plays a sound.
ztcl::audio play FILE ?OPTION VALUE ...?
ztcl::audio play -data BYTES ?OPTION VALUE ...?
ztcl::audio play SOUND ?-in MS|-at FRAME? ?-gain G? ?-pan P? ?-choke GROUP? ?-command SCRIPT?
Description
With SOUND, an id of ztcl::audio load, the audio engine starts a voice and gives its id, such as voice2. -in MS starts it that time from now, as after, and -at FRAME at that frame of the clock of the engine; with neither, it starts at once. -gain is 0 to 1, and 1 by default. -pan is -1 (left) to 1 (right), and 0 by default. -choke GROUP (1 to 65535) stops each other voice of the group when this one starts, with a short fade. -command runs SCRIPT at the end of the voice, from the event loop, with {status done} or {status stopped} appended. A word of the form soundN is always an id of the engine.
Plays an audio file, such as WAV, MP3, or AAC, and gives its handle. FILE is a file that ztcl reads with the open and read of the script, so it follows the root folder of the interpreter and needs the capability channels. -data plays BYTES, the bytes of an audio file. The host decodes the bytes, at most 64 MiB.
-volume is 0.0 to 1.0, and 1.0 by default. -loop plays the sound COUNT times, 1 to 1,000, or until stop with 0; the default is 1. -command runs SCRIPT at the end, from the event loop, with a dict appended: {status done}, {status stopped} after stop, or {status error} when the host cannot decode or play the bytes.
Returns
A handle, such as audio1.
Examples
# A host with no audio, as a desktop.
% catch {ztcl::audio play -data RIFF -volume 0.5} msg; set msg
audio is not available on this platform
Errors
% ztcl::audio play -data RIFF -volume 2
bad volume "2": must be 0.0 to 1.0
-errorcode ZTCL AUDIO VALUE
% ztcl::audio play -data RIFF -loop -1
bad loop count "-1": must be 0 to 1000
-errorcode ZTCL AUDIO VALUE
% ztcl::audio play -data RIFF -speed 2
bad option "-speed": must be -command, -loop, or -volume
-errorcode NONE
% ztcl::audio play
wrong # args: should be "ztcl::audio play file|-data bytes ?-volume v? ?-loop count? ?-command script?"
-errorcode TCL WRONGARGS
% ztcl::audio play sound9
sound "sound9" doesn't exist
-errorcode TCL LOOKUP AUDIO sound9
Facts
- Capability
audio. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.6