Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Русский

Change language to:
English - Français - 日本語 - Português -

Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
See the recommended documentation of this function

Справка Scilab >> Sound file handling > playsnd


command-line sound player facility


playsnd(filename, speed)
playsnd(filename, speed, nbiter)
playsnd(filename, speed, nbiter, playerCmd)
playsnd(filename, speed, playerCmd)

playsnd(y, rate)
playsnd(y, rate, nbiter)
playsnd(y, rate, nbiter, playerCmd)
playsnd(y, rate, playerCmd)



single string: the path and name of the sound file to play.

real positive number: relative playing speed. speed < 1 plays slower, while speed > 1 plays faster. (1.0 by default).

matrix of normalized linear sound data, in [-1,1]. Each row feeds a channel.

real positive number: sampling frequency in Hz (default value is 22050).

positive decimal integer: number of consecutive times (iterations) that the sound must be played.

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.

If playerCmd is set to /dev/audio, then a 8 bits mu-law raw sound file is created and send to /dev/audio.


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.


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
playsnd(File, 2)        // Play it once at speed x 2
playsnd(File,, 3)       // Play it 3 times at normal speed
playsnd(File, 1.5, 3)   // Play it 3 times at speed x 1.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
playsnd(y, 3e4)         // Play it once at 30 kHz sampling rate
playsnd(y,, 3)          // Play it 3 times at the default sampling rate
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)


  • playsnd(filename,..) can now be used. The relative speed wrt the native one in the file can be specified.
  • nb_iter option introduced.
  • playsnd([]) is introduced to stop a sound run without repetition.
  • playsnd(…) is now by default not-modal on Linux and MacOS, like on Windows.
  • playsnd(…) can now be modal on any OS, through any explicit nb_iter value.
  • Input argument bits removed.
Report an issue
<< mu2lin Sound file handling savewave >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:54:58 CET 2020