Shadi
Shadi

Reputation: 481

How to read a ".wav" file into MATLAB?

I wanted to input a wave file in the MATLAB so that I could process it using filters, when I come to input the wave file called wave.wav, this file is located on my desktop, and then I used

[y, fs, nb] = wavread('wave.wav');

to read the wave file but always gives me an error cannot open file, the only thing I can think of is that the function doesnt know the path of the wave.wav, any help? And how can I play the file also using MATLAB after read, sound()?

Upvotes: 1

Views: 44207

Answers (3)

kripa
kripa

Reputation: 11

This works: [y,Fs]=wavread('filename'); sound(y,Fs);

note: the filename could be any audio file. but use a converter from .mp3 to .wav coz filename must be in wav format( few even say that waveread converts the file automatically into .wav file but in my case it did not!! ) :)

Upvotes: 1

Ruben Capote
Ruben Capote

Reputation: 324

Use the full path to the file and you can play the sound using soundsc(y,fs) instead sound

Upvotes: 0

jonsca
jonsca

Reputation: 10381

Yes, you are correct on both counts. Use the full path to the file, and use the sound function to play it back. See this reference page for a thorough example. The documentation from the Mathworks is quite comprehensive.

Upvotes: 3

Related Questions