MATLAB 录音机和 wavwrite
在阅读 MathWorks 网站时,我了解到他们不鼓励使用 wavrecord
函数,因为它即将被弃用,因此我决定使用 audiorecorder
代替。一切都很好,甚至播放功能也在播放录制的音频,但是当我使用 wavwrite
函数写入 wav 文件听起来不太好,基本上我注意到持续时间设置不正确。
我正在展示该程序,请建议我如何使其正确。谢谢。
fs = 44100
bits = 16
recObj = audiorecorder(fs, bits, 1);
%# get(recObj)
%# Collect a sample of your speech with a microphone, and plot the signal data:
%# Record your voice for 5 seconds.
recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 5);
disp('End of Recording.');
%# Play back the recording.
play(recObj);
%# Store data in double-precision array.
myRecording = getaudiodata(recObj);
%disp(size(myRecording));
%# Plot the waveform.
plot(myRecording);
wavwrite(myRecording, fs, bits,'sample01_6k');
%#wavplay(myRecording,fs);
While reading the website of MathWorks I learned that they are discouraging the usage of wavrecord
function, because it's going to be deprecated soon, so I decided to use the audiorecorder
instead. Everything was fine, even the play function was also playing the recorded audio, but when I use wavwrite
function to write to a wav file it's not sounding well, basically I noticed that the duration is not set properly.
I am showing the program, please suggest me how to make it correct. Thank you.
fs = 44100
bits = 16
recObj = audiorecorder(fs, bits, 1);
%# get(recObj)
%# Collect a sample of your speech with a microphone, and plot the signal data:
%# Record your voice for 5 seconds.
recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 5);
disp('End of Recording.');
%# Play back the recording.
play(recObj);
%# Store data in double-precision array.
myRecording = getaudiodata(recObj);
%disp(size(myRecording));
%# Plot the waveform.
plot(myRecording);
wavwrite(myRecording, fs, bits,'sample01_6k');
%#wavplay(myRecording,fs);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您创建了
recObj
两次,第二次创建它时,您使用默认设置而不是自定义设置来创建它。删除对audiorecorder
的第二次调用,一切都应该按预期工作。you are creating
recObj
twice, and the second time you create it, you create it with default settings instead of your custom settings. Remove the second call toaudiorecorder
and everything should work as expected.