sound

Convert matrix of signal data to sound

Description

example

sound(y) sends audio signal y to the speaker at the default sample rate of 8192 hertz.

example

sound(y,Fs) sends audio signal y to the speaker at sample rate Fs.

example

sound(y,Fs,nBits) uses nBits bits per sample for audio signal y.

Examples

collapse all

Load the example file gong.mat, which contains sample data y and rate Fs, and listen to the audio.

load gong.mat;
sound(y);

Play an excerpt from Handel's “Hallelujah Chorus” at twice the recorded sample rate.

load handel.mat;
sound(y, 2*Fs);
load handel.mat;
nBits = 16;
sound(y,Fs,nBits);

MATLAB® plays the audio with a bit depth of 16 bits per sample, if this is supported on your system.

Input Arguments

collapse all

Audio data, specified as an m-by-1 column vector for single-channel (mono) audio, or an m-by-2 matrix for stereo playback, where m is the number of audio samples. If y is an m-by-2 matrix, then the first column corresponds to the left channel, and the second column corresponds to the right channel. Stereo playback is available only if your system supports it.

Data Types: double

Sample rate, in hertz, of audio data y, is specified as a positive number from 1000 through 384000. Valid values depend on both the sample rates permitted by MATLAB® and the specific audio hardware on your system. MATLAB has a hard restriction of 1000 Hz <= Fs <= 384000 Hz, although further hardware-dependent restrictions apply.

Data Types: single | double

Bit depth of the sample values, specified as an integer. Valid values depend on the audio hardware installed. Most platforms support bit depths of 8 bits or 16 bits.

Limitations

  • sound ignores nBits. Instead, it plays audio data using the default number of bits per sample of the output audio device.

More About

collapse all

Security Considerations When Using MATLAB Online

When using sound in MATLAB Online™, certain features and settings help you keep control of your privacy.

To reduce the likelihood of unwanted applications using your microphone, turn off automatic access to your audio device. You can change these settings at any time. After granting permission to a website once, your browser may be able to access your microphone automatically for that site on future visits. Use the browser settings for Google Chrome to revoke access for specific sites after you have initially allowed access.

You can also access the MATLAB Online website using the private browsing mode in Google Chrome. When you do this, Chrome™ automatically asks you for permission to access your microphone every time you open the MATLAB Online site and run sound, regardless of your browser settings.

Tips

  • The sound function supports sound devices on all Windows® and most UNIX® platforms.

  • Most sound cards support sample rates between 5 and 48 kilohertz. Specifying a sample rate outside this range might produce unexpected results.

  • Audio playback in MATLAB Online is supported in Google Chrome™.

Introduced before R2006a