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');
0 个评论
采纳的回答
更多回答(1 个)
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!