Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
playsnd
command-line sound player facility
Syntax
playsnd(filename) playsnd(filename, speed) playsnd(filename, speed, nbiter) playsnd(filename, speed, nbiter, playerCmd) playsnd(filename, speed, playerCmd) playsnd(y) playsnd(y, rate) playsnd(y, rate, nbiter) playsnd(y, rate, nbiter, playerCmd) playsnd(y, rate, playerCmd) playsnd([])
Arguments
- filename
- single string: the path and name of the sound file to play.
- speed
- real positive number: relative playing speed.
speed
< 1 plays slower, whilespeed
> 1 plays faster. (1.0 by default). - y
- matrix of normalized linear sound data, in [-1,1]. Each row feeds a channel.
- rate
- real positive number: sampling frequency in Hz (default value is 22050).
- nb_iter
- positive decimal integer: number of consecutive times (iterations) that the sound must be played.
- playerCmd
- Only used on Unix and MacOS systems. Single string giving the OS command
to use for playing sound (wav) files. The default value is
"aplay"
on Linux and"afplay"
on MacOS. IfplayerCmd
is set to/dev/audio
, then a 8 bits mu-law raw sound file is created and send to/dev/audio
.
Description
playsnd(filename,..) or playsnd(y,..) cancels any running sound and then starts playing a single or multi channel signal.
When nb_iter
is not used, the sound is played only once, and
playsnd(…)
behaves in a non-modal way: Scilab returns to the prompt
or to the next instruction just after starting playing, without waiting for the end of
the sound.
Otherwise, the sound is played nb_iter
consecutive times,
and playsnd(…)
becomes modal (even for
nb_iter
=1): Scilab returns to the prompt
or to the next instruction only after the end of the last time the sound is played.
The repetition is interruptible with CTRL-C or any pause or
abort callback instruction. |
playsnd([]) cancels any sound running without
nb_iter
and not through /dev/audio.
Examples
Playing a sound from its audio file:
// A two channel signal File = "SCI/modules/sound/demos/chimes.wav"; playsnd(File) // Play it once at normal speed sleep(5) playsnd(File, 2) // Play it once at speed x 2 sleep(5) playsnd(File,, 3) // Play it 3 times at normal speed sleep(5) playsnd(File, 1.5, 3) // Play it 3 times at speed x 1.5 sleep(5) playsnd(File, 0.2) // Play it once and slowly. // Note that Scilab returns as soon as the player starts. // Plays a longer sound. Interrupts it 1.0 s after it started: playsnd(File, 0.2), sleep(1,'s'), playsnd([])
Playing a sound from its data in a matrix:
y = loadwave("SCI/modules/sound/demos/chimes.wav"); playsnd(y) // Play it once at the default 22050 Hz sampling rate sleep(5) playsnd(y, 3e4) // Play it once at 30 kHz sampling rate sleep(5) playsnd(y,, 3) // Play it 3 times at the default sampling rate sleep(5) playsnd(y, 44100, 3) // Play it 3 times at 44.1 kHZ sampling rate
Interrupting with CTRL + C a repeated sound:
playsnd("SCI/modules/sound/demos/chimes.wav",, 20); // Now enter CTRL-C to interrupt the repetition // Then type "resume" or "abort"
See also
- beep — Produce a beep sound
- realtime — sets the time unit
- lin2mu — linear signal to mu-law encoding
- wavread — reads sound data or querries data info from a .wav audio file
- auread — load .au sound file
- mcisendstring — sends a command string to an MCI device (Windows only)
- winopen — Open file in appropriate application (Windows only)
History
Версия | Описание |
6.1.0 |
|
Report an issue | ||
<< mu2lin | Sound file handling | savewave >> |