how can i read audio file in matlab?

Discussion in 'Programmer's Corner' started by sepideh-gh, Mar 10, 2012.

  1. sepideh-gh

    Thread Starter New Member

    Mar 5, 2012
    4
    0
    hi . i use this code for read wav file but i don't know is it true or fale?please direct me.(i want read a wav file that it is in my flash , i copy it to my hard but when use this code i don't give any result)
    [y Fs]=wavread('H:\k\term3\audio files\pop.wav');
    wavplay(y,Fs);
    :confused:
     
  2. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    here is working code that reads, manipulates and then saves WAV file:

    Code ( (Unknown Language)):
    1. % read in sound file and determine length and period
    2. [signal, Fs, bits_per_sample]=wavread('speech.wav');
    3.  
    4. L=length(signal); % file length
    5. T=1/Fs;           % sample period
    6. t=[0:L-1]*T;      % time vector in seconds
    7.  
    8. % define echo and amplitude values
    9. Te=40;           % set echo to 300 ms
    10. alpha = 0.9;      % scale amplitude of echo
    11. DelaySec = round(Te / 1000); % must be integer
    12. te = round(DelaySec / T); % echo delay as integer (rel. to sample period)
    13.  
    14. signalplusecho=1:L+te; % declare it as vector before loop
    15. for t = 1:L+te
    16.    if (t<te)  
    17.        signalplusecho(t)=signal(t);
    18.    elseif (t>=L)              
    19.        signalplusecho(t)=signal(t-te);
    20.    else  
    21.        signalplusecho(t)=signal(t) + alpha*signal(t+te);
    22.    end
    23. end
    24.  
    25. wavwrite(signalplusecho,Fs,8, 'speechwithecho.wav');
    26.  
     
  3. m_arezoo

    New Member

    Apr 13, 2012
    1
    0
    hi
    i do this work but also it has an error, please help me

    ??? Error using ==> wavread at 166
    Invalid field name: ''.
    Error in ==> read at 4
    [signal, Fs, bits_per_sample]=wavread('C:\Users\hp\Desktop\abc.wav');
     
  4. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    @m_arezoo

    you sent me PM regarding this. unfortunately you also disabled your own PMs so one can't reply. you need to look at the code sample you sent me and verify that path and file names are correct. Read error messages - they are there for you.
     
Loading...