MATLAB 录音机和 wavwrite

发布于 2024-12-09 02:32:07 字数 945 浏览 0 评论 0原文

在阅读 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2024-12-16 02:32:07

您创建了 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 to audiorecorder and everything should work as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文