wavrecord() replacement and sound speed measurement

11 次查看(过去 30 天)
I would like to try to measure sound speed with Matlab. I have two microphones recording sound at the same time. They are both connected to my laptop through stereo input. I have tried to use code from this topic: https://www.mathworks.com/matlabcentral/answers/129171-sound-speed-measurement-with-two-microphones
I replaced 'wavrecord()' to an audiorecorder function but it gives an error. I have no idea what I can change to make the program work properly and start recording a sound.
Here is the code and the error below:
if true
clear; figure; grid on; hold on;
Fs = 22050;
r = audiorecorder(22050,16,2);
record(r,5);
mySpeech = getaudiodata(r, 'int16');
tmax = length(mySpeech)/Fs;
t = linspace(0, tmax, 5*Fs);
plot(t*1000,mySpeech);
axis([0 tmax*1000 -2 2]);
xlabel('time (ms)');
j = 1;
for i=1:length(mySpeech)
if mySpeech(i)>0.15
pick(j) = 1000*i/Fs;
fprintf('%3d --> %8.1f ms\n',j, pick(j));
j=j+1;
end
end
end
Error using audiorecorder/getaudiodata (line 765)
Recorder is empty.
Error in program (line 7)
mySpeech = getaudiodata(r, 'int16');

采纳的回答

Walter Roberson
Walter Roberson 2020-4-27
Change
record(r,5);
to
recordblocking(r,5);

更多回答(1 个)

Dian
Dian 2023-9-21
编辑:Walter Roberson 2023-9-21
clear all;
Fs = 8000;
y = wavrecord(5.0*Fs, Fs, 'double');
wavwrite(y,Fs,'aiueo.wav')
y1=wavread('aiueo.wav');
t=length(y1);
y2=y1(1:10000);
plot(y2)
  1 个评论
Walter Roberson
Walter Roberson 2023-9-21
Unfortunately, that will not solve @Michal Rocinski's problem, which was happening in R2019b. By R2019b, wavrecord() had been completely removed from MATLAB; wavwrite() had also been removed https://www.mathworks.com/matlabcentral/answers/647743-is-wavwrite-still-used#answer_544418 and probably wavread() had been removed too.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by