Error in 'untitled/Audio Device Writer': A given audio device may only be opened once.

28 次查看(过去 30 天)
why do i get this error >>> Error in 'untitled/Audio Device Writer': A given audio device may only be opened once<<< while rinning my simlunk block that play a sound?
note that i run it before with no problems. however, now i got this error although i didn't put any changes!!!

采纳的回答

Gabriele Bunkheila
Gabriele Bunkheila 2018-11-29
Hi Fatima,
You may have multiple block instances pointing to the same device in your model, another Simulink model running, or you may similarly have run or created instances of audioDeviceWriter in your MATLAB session. Checking other models open, other blocks in your model, or clearing (or even releasing) existing competing object instances in MATLAB should solve this.
Thanks,
Gabriele.
  2 个评论
fatima alansari
fatima alansari 2018-12-2
%ReadFromMicrophoneAndWriteToAudioFileExample
%Create an audioDeviceReader System object™ with default settings.
%Call setup to reduce the computational load of initialization
%in an audio stream loop.
deviceReader = audioDeviceReader;
setup(deviceReader);
%Create a dsp.AudioFileWriter System object.
%Specify the file name and type to write.
fileWriter = dsp.AudioFileWriter(...
'mySpeech.wav',...
'FileFormat','WAV');
%Record 10 seconds of speech. In an audio stream loop,
%read an audio signal frame from the device,
%and write the audio signal frame to a specified file.
%The file saves to your current folder.
disp('Speak into microphone now.')
tic;
while toc < 10
acquiredAudio = deviceReader();
fileWriter(acquiredAudio);
end
disp('Recording complete.')
release(deviceReader);
release(fileWriter);
Hi Gabriele,
I tryed to exchange 'dsp.AudioFileWriter' with 'audioDeviceWriter' to stream live real-time audio.
i tryed to put 'audioDeviceWriter' function inside the while loop. It received the sound with no error but didn't get the output from the device.
i removed these lines:
fileWriter = dsp.AudioFileWriter(...
'mySpeech.wav',...
'FileFormat','WAV');
and:
fileWriter(acquiredAudio);
inside the loop
and
release(fileWriter);
the last line
and added the following line inside the loop:
audioDeviceWriter(acquiredAudio);
how i can i fix it??
Fatima

请先登录,再进行评论。

更多回答(1 个)

Gabriele Bunkheila
Gabriele Bunkheila 2018-12-3
编辑:Gabriele Bunkheila 2018-12-3
Hi Fatima,
Please refer to the code in the example "Audio Stream from Device to Device" under " Quick Start Examples" in the page Real-Time Audio in MATLAB. In particular, the few lines of code below should do what you need:
% In the two lines of code below, provide any additional property value necessary to point the object to your sound card(s)
deviceReader = audioDeviceReader;
deviceWriter = audioDeviceWriter('SampleRate',deviceReader.SampleRate);
disp('Begin Signal Input...')
tic
while toc < 5
mySignal = deviceReader();
% Process mySignal as needed
deviceWriter(mySignal);
end
disp('End Signal Input')
release(deviceReader)
release(deviceWriter)
Regards,
Gabriele.
  1 个评论
fatima alansari
fatima alansari 2018-12-6
Hello,
1) edit PhaseVocoderMATLABExample
This link includes a code that reads an audio from a file and implements a (Time Dilation and Pitch Shifting) on it, then display it by 'audioDeviceWriter'.
2)'Audio Stream from Device to Device' example under 'Real-Time Audio' title.
Is an example includes code that read the audio signal from a device and write it into the speaker, output.
I was trying to read an audio signal in the first code instead of reading it from a file. I tryed to exchange 'dsp.AudioFileReader' with 'audioDeviceReader' and used 'tic toc' in while loop instead of '~isDone'. However, i got the following error:
"Error using dsp.IFFT/parenReference
Changing the complexity (from real to complex) on input 1 is not allowed without first calling the release()
method."
at the line:
"ywin = win(idft(ys)); % Windowed IFFT", which is inside the loop.
can you help me understanding the error and how to solve it??

请先登录,再进行评论。

类别

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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by