Pergunta

I have a problem in matlab

I want to record a speech for 2 seconds then read the recorded sound and plot it

I use the code

FS = 8000;    
new_wav = wavrecord(2*FS,FS,'int16');
x = wavread(new_wav);
plot(x);

but the error appears

??? Error using ==> fileparts at 20
Input must be a row vector of characters.

Error in ==> wavread>open_wav at 193
[pat,nam,ext] = fileparts(file);

Error in ==> wavread at 65
[fid,msg] = open_wav(file);

Error in ==> test at 2
x = wavread(new_wav);

I plotted correctly recorded sound files, but when I want to record new one through matlab I get this errors.

I tried many ways by changing FS and 'int16' but nothing happens.

thanks

Foi útil?

Solução

The function WAVRECORD doesn't write data to a file, it only returns a data vector for new_wav, so this variable is what you should be plotting. The function WAVREAD reads data from a file, so it expects a character string as the input. That's the source of the error you're getting.

If you want to save the data from WAVRECORD to a file, you need to use the function WAVWRITE.

Outras dicas

name = input('Enter Your Name   ','s');
file = sprintf('%s%s.wav','train - ',name);
input ('You have 2 seconds to a word. Press enter when ready ')
y = wavrecord (2*fs,fs);
wavwrite(y,fs,file);

At the end this is the complete code :)

% Record your voice for 5 seconds.

recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 3);
disp('End of Recording.');

% Play back the recording.

play(recObj);

% Store data in double-precision array.

myRecording = getaudiodata(recObj);

% Plot the waveform.

plot(myRecording);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top