33.3 Audio Player

The following methods are used to create and use audioplayer objects. These objects can be used to play back audio data stored in Octave matrices and arrays. The audioplayer object supports playback from various devices available to the system, blocking and non-blocking playback, convenient pausing and resuming and much more.

 
: player = audioplayer (y, fs)
: player = audioplayer (y, fs, nbits)
: player = audioplayer (y, fs, nbits, id)
: player = audioplayer (recorder)
: player = audioplayer (recorder, id)

Create an audioplayer object that will play back data y at sample rate fs.

The signal y can be a vector (mono audio) or a two-dimensional array (multi-channel audio).

The optional arguments nbits and id specify the number of bits per sample and player device ID, respectively. Device IDs may be found using the audiodevinfo function.

Given an audiorecorder object recorder, use the data from the object to initialize the player.

The list of actions for an audioplayer object are shown below. All methods require an audioplayer object as the first argument.

MethodDescription
getRead audioplayer property values
isplayingReturn true if audioplayer is playing
pausePause audioplayer playback
playPlay audio stored in audioplayer object w/o blocking
playblockingPlay audio stored in audioplayer object
resumeResume playback after pause
setWrite audioplayer property values
stopStop playback

Example

Create an audioplayer object that will play back one second of white noise at 44100 sample rate using 8 bits per sample.

y = 0.25 * randn (2, 44100);
player = audioplayer (y, 44100, 8);
play (player);

See also: @audioplayer/get, @audioplayer/isplaying, @audioplayer/pause, @audioplayer/play, @audioplayer/playblocking, @audioplayer/resume, @audioplayer/set, @audioplayer/stop, audiodevinfo, @audiorecorder/audiorecorder, sound, soundsc.