error using xcorr function to compare audio file that is recorded by device microphone

The code for recording voice through device -
recording = audiorecorder(fs, 16, 1);
voice = getaudiodata(recording);
voice = voice / max(abs(voice));
y1 = audioread('one.wav');
z1 = xcorr(voice, y1);
m1 = max(z1);
The error message is - [Error: Second argument must be a vector.]
How to solve this issue?

 Accepted Answer

Your y1 is stero but needs to be mono

2 Comments

Just an additional question. In the script above the recorder isn't stopped (no stop or recordblocking). Stopps the recorder automatically when getaudiodata is issued or continues it recording?
The above script does not call record() or recordblocking() so getaudiodata() would complain that the recorder was empty.
If you use record() then my experiments show that getaudiodata() fetches all of the data that has accumulated since you called record(). In particular if I call getaudiodata() again while the same record() is still active, then in my experiment the values returned by the first call to getaudiodata() are identical to the leading prefix of the values returned by the second call to getaudiodata() -- calling getaudiodata() does not clear the buffer.
An implication of this is that you cannot use just record() / getaudiodata() in a loop or with a timer to record and return adjacent segments of sound, not without stopping the recording and starting it again. audiorecorder() with record() and getaudiodata() are not designed for streaming data.

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!