Issue with trying to play and record audio simultaneously

9 次查看(过去 30 天)
Hi guys, For my project I need to play a wav file from my speaker and while it's playing I want to record it with a microphone simultaneously. I'm using the audioPlayerRecorder which I believe is what I need to use. This is what I've done so far, however I'm not quite sure if its correct.
clear all
clc
filereader=dsp.AudioFileReader('chirp_2.wav'); % this is the wav file saved in my Computer
fs=filereader.SampleRate;
filewriter= audioDeviceWriter(fs);
apr=audioPlayerRecorder('SampleRate',fs);
while ~isDone(filereader)
audioToPlay = filereader();
audioRecorded = apr(audioToPlay);
filewriter(audioToPlay);
end
release(apr);
release(filewriter);
release(filereader);
mic1=getaudiodata(apr);
mic2=getaudiodata(filewriter);
When I run this, it runs fine so I'm assuming that both speaker and microphone are working synchronously?
My issue is, I want to plot both the audio from speaker and the recorded audio. I'm trying to convert the object to a numerical array through the getaudiodata function however having I get an error saying "Unrecognized function or variable getaudiodata()".
Does anyone know how to plot both the speaker and microphone audio?

采纳的回答

Walter Roberson
Walter Roberson 2020-7-24
getaudiodata() is only for audiorecorder() https://www.mathworks.com/help/matlab/ref/audiorecorder.html which is a routine that records audio and holds on to it until it is asked for.
You are using the system-object based routines such as audioPlayerRecorder. Those do not hold on to all the data: they only hold on to one buffer-worth. The audio data can be obtained by using step() -- or, exactly the way you did, by invoking the variable storing the object as-if it were a function. One buffer at a time.
  8 个评论
Victor Dunira
Victor Dunira 2020-8-12
Have you installed ASIO driver, it recognised my laptops microphone and speakers after installation.
Walter Roberson
Walter Roberson 2020-8-12
ASIO does not exist for MacOS. ;-)
And it is true that I do not have a simultaneous input/output audio device. I had been thinking of my speakers and built-in mic as one combine unit, but really they are not at all.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by