2

我在matlab中有问题

我想录制一段演讲 2 秒钟然后读取录制的声音并绘制它

我使用代码

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

但出现错误

??? 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);

我绘制了正确录制的声音文件,但是当我想通过 matlab 录制新的声音文件时,我得到了这个错误。

我通过更改 FS 和“int16”尝试了很多方法,但没有任何反应。

谢谢

4

3 回答 3

2

函数WAVRECORD不会将数据写入文件,它只返回 的数据向量new_wav,因此您应该绘制此变量。函数WAVREAD从文件中读取数据,因此它需要一个字符串作为输入。这就是你得到的错误的根源。

如果要将数据从WAVRECORD保存到文件,则需要使用函数WAVWRITE

于 2010-12-22T18:56:38.410 回答
0
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);
于 2012-05-09T12:11:16.517 回答
0

最后这是完整的代码:)

% 录制你的声音 5 秒。

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

% 播放录音。

play(recObj);

% 将数据存储在双精度数组中。

myRecording = getaudiodata(recObj);

% 绘制波形。

plot(myRecording);
于 2013-03-21T04:58:56.373 回答