Issue with trying to play and record audio simultaneously
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Swapnil Srivastava
am 24 Jul. 2020
Kommentiert: Walter Roberson
am 12 Aug. 2020
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 24 Jul. 2020
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 Kommentare
Victor Dunira
am 12 Aug. 2020
Have you installed ASIO driver, it recognised my laptops microphone and speakers after installation.
Walter Roberson
am 12 Aug. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!