Lesson 001: Read Audio Files in Matlab

Introduction

 

Audio and Speech signal processing is quiet an interesting field and find its application in several areas like speech to text conversion, speech recognition, speaker recognition and biometric authentication. Before doing any processing on audio/speech signal, it is required to either record audio/sound or read the pre-recorded audio/sound signal stored in memory of computer into processing algorithm. For our tutorials we will be using Matlab software for writing all kind of processing algorithms.

Figure 1 shows the block diagram of above stated procedure. Speaker speech or audio signal from any other source first converted to electrical (analog) signal through a transducer (or microphone) then this analog signal is converted into digital signal with the help of ADC (Analog to Digital Converter). Inside computer this digital sound is stored in a form of a file on hard disk or any other storage media.

                              Fig. 1: Block Diagram of a typical Audio/Speech Signal Processing

 

There are several file formats available by which sound files or speech signal can be stored on a computer. Some of them are *.mp3, *.wav, *.wma, *.ogg, *.flac etc. There are many others as well. Once Audio or Speech is stored on computer then any standard software like Matlab, Scilab or Octave can be used to access those files and can be used to perform further processing.

In our tutorials, we will be using Matlab in order to do process Audio/Speech signals. First step in audio/speech signal processing is to read and play those files. In next section we will point out Matlab commands in order to read and play sound files in Matlab.

 

 

 

 

Read Audio Files in Matlab  

 

Matlab provides various commands for reading and playing sound files. Here, we have provided a short description of those commands. Full and complete description can be found in Matlab Help.

  1. [y, fs] = wavread(filename): this Command is used to read .wav file format files only. It returns the sound data and sampling frequency used while recording the signal.

  2. [y, fs] = audioread(filename): This command is used to read any file format files supported by Matlab. It also returns the sound data and sampling frequency used while recording the signal.

  3. Sound(y, fs): This command is used to play the sound file from Matlab. It is required for good sound that we provide the sampling frequency information along with the sound data. Problem with this command is that we cannot pause or stop sound once it is started.

  4. Player = audioplayer(y, fs): This command is used to create audio player object for specific sound data at specific sampling frequency (fs). Once object is created then we can play, pause, resume or stop the sound from following commands play(Player), pause(Player), resume(Player), stop(Player) respectively.

Matlab Code Example for Reading Sound File

(It will be easier for you if you put the sound file to be read in the same folder where your Matlab code is.)

% read .wav file

[data,fs] = wavread('10a07La_boredom');

 

% read .mp3 file

[x, fs1] = audioread('preview.mp3');

 

% play audio files

sound(x,fs1);   %one method

 

% play, pause audio files by another method

player = audioplayer(x,fs1);

play(player);

pause(5);

pause(player);

pause(5);

stop(player);

 

% plot signal

plot(x); title('Input Sound File');

 

Play with this code by changing sound file name.

 

(Note: Go through the video tutorial on the same. Link is given below)

(https://youtu.be/O8GlKE2Iu_I)

        (NOTE: Download Matlab Codes Here)

For More Information
Contact: 
 
Ph. : 0120-2663236
mob: +91-9971776373
e-mail: jcbrolabs@gmail.com
 
or Fill Quick Enquiry Form

© 2014 by JCBRO LABS

  • w-facebook
  • Twitter Clean
  • w-googleplus
  • w-youtube