wavrecord() replacement and sound speed measurement

조회 수: 11 (최근 30일)
Michal Rocinski
Michal Rocinski 2020년 4월 27일
댓글: Walter Roberson 2023년 9월 21일
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