Main Content


Scale data and play as sound



soundsc(y) scales the values of audio signal y to fit in the range from –1 to 1, and then sends the data to the speaker at the default sample rate of 8192 Hz. By first scaling the data, soundsc plays the audio as loudly as possible without clipping. The mean of the dynamic range of the data is set to zero.


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


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


soundsc(___,yRange), where yRange is a vector of the form [low,high], linearly scales the values in y between low and high to the full sound range [–1, 1]. Values outside [low,high] scale beyond [–1, 1]. You can use yRange with any of the input argument combinations in the previous syntaxes.


collapse all

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

load gong.mat

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

load handel.mat
load handel.mat
nBits = 16;

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

Play an excerpt from Handel's Hallelujah Chorus at 70% of its original volume.

load handel.mat
yRange = [-0.7,0.7];

Input Arguments

collapse all

Audio data, specified as an m-by-1 numeric column vector for single-channel (mono) audio, or an m-by-2 numeric matrix for stereo audio, 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 to the right channel. Stereo playback is available only if your system supports it.

Data Types: double

Sample rate in hertz (Hz), specified as a positive scalar.

Valid values of the sample rate depend on the audio hardware of your system. Typical sample rates supported by most setups are 8000, 11,025, 22,050, 44,100, 48,000, 96,000, and 192,000 Hz.

Data Types: single | double

Bits per sample, specified as 16, 8, or 24.

Valid values of nBits depend on the audio hardware of your system.

Range of audio data to scale, specified as a two-element vector of the form [low,high], where low and high are the lower and upper limits of the range, respectively. Values in y that are scaled beyond [–1, 1] are clipped when played back on a sound device.

If you do not specify yRange, it defaults to the value [-M,M], where M is the maximum entry in abs(y).

Example: [-0.8,0.8]

Data Types: double


  • In MATLAB® Online™ or MATLAB Web App Server™, soundsc ignores nBits. Instead, it plays audio data using the default number of bits per sample of the output audio device.


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

  • soundsc in MATLAB Online and MATLAB Web App Server is supported in Google Chrome®.

  • Note

    Security Considerations When Using MATLAB Online or MATLAB Web App Server: When using soundsc in MATLAB Online or MATLAB Web App Server, 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 or MATLAB Web App Server using the private browsing mode in Google Chrome. When you do this, Chrome® automatically asks you for permission every time it tries to access your microphone, regardless of your browser settings.

Extended Capabilities

Version History

Introduced before R2006a