Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.1.0 - 日本語


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, while speed > 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.

If playerCmd 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 — ビープ音を生成
  • realtime — 時間の単位を設定
  • lin2mu — linear信号をmu-lawエンコーディングに変換
  • wavread — .wav サウンドファイルを読み込む
  • auread — .au サウンドファイルを読み込む
  • mcisendstring — sends a command string to an MCI device (Windows only)
  • winopen — Open file in appropriate application (Windows only)

History

バージョン記述
6.1.0
  • 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-2024 (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:
Mon May 22 12:43:11 CEST 2023