Record Sound Using Matlab

2 08 2009

Record sound using Windows audio input device.

WAVRECORD (N,FS,CH) records N audio samples at FS Hertz from CH number of input channels from the Windows WAVE audio device. Standard audio rates are 8000, 11025, 22050, and 44100 Hz.  CH can be 1 or 2 (mono or stereo).  Samples are returned in a matrix of size N x CH.  If not specified, FS=11025 Hz, and CH=1.

WAVRECORD (…, DTYPE) records and returns data using the data type specified by DTYPE.  Supported data types and the corresponding number of bits per sample recorded in each format are as follows:

DTYPE     bits/sample
‘double’      16
‘single’      16
‘int16’       16
‘uint8’        8

This function is only for use with 32-bit Windows machines.

Example:

Record and play back 5 seconds of 16-bit audio sampled at 11.025 kHz.

Fs = 11025;
y  = wavrecord(5*Fs, Fs, ‘int16’);
wavplay(y, Fs);

Syntax

y = wavrecord(n,Fs)
y = wavrecord(…,ch)
y = wavrecord(…,’dtype’)

Description

y = wavrecord (n,Fs) records n samples of an audio signal, sampled at a rate of Fs Hz (samples per second). The default value for Fs is 11025 Hz. y = wavrecord(…,ch) uses ch number of input channels from the audio device. ch can be either 1 or 2, for mono or stereo, respectively. The default value for ch is 1. y = wavrecord(…,’dtype’) uses the data type specified by the string ‘dtype’ to record the sound. The string ‘dtype’ can be one of the following: ‘double’ (default value), 16 bits/sample ‘single’, 16 bits/sample ‘int16’, 16 bits/sample ‘uint8’, 8 bits/sample

Remarks

Standard sampling rates for PC-based audio hardware are 8000, 11025, 2250, and 44100 samples per second. Stereo signals are returned as two-column matrices. The first column of a stereo audio matrix corresponds to the left input channel, while the second column corresponds to the right input channel.

Examples

Record 5 seconds of 16-bit audio sampled at 11025 Hz. Play back the recorded sound using wavplay. Speak into your audio device (or produce your audio signal) while the wavrecord command runs. Fs = 11025;
y = wavrecord(5*Fs,Fs,’int16′);
wavplay(y,Fs);

Reff : Matlab Documentation


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: