Filter löschen
Filter löschen

Playing audio in the background while running another function

23 Ansichten (letzte 30 Tage)
I want to play audio using AudioFileReader and while that audio is playing, I want to run a separate loop that asks for user input. The loop asking for user input is not tied to the iterations of the loop playing the audio. Thus, the best way to do this seemed to try to run them in parallel using pareval, but I cannot get it to work.
The code to play audio:
function audioPlayback(filename)
% call audio device
playRec = audioPlayerRecorder(48000);
playRec.Device = 'MOTU Pro Audio';
% PRESENT
afr = dsp.AudioFileReader(filename);
adw = playRec;
while ~isDone(afr)
audio = afr();
adw(audio);
end
release(afr);
release(adw);
The code for the for loop:
function [score] = TestProgram(keywords, sentences)
for ii = 1:6
list = keywords(ii,:); % get keywords by stimuli
prompt = sentences(ii,:); % get full sentence
% prompt for selection of keywords
[indx, ~] = listdlg('PromptString', prompt,'ListString',list,'SelectionMode','multiple', 'ListSize',[300,100], 'CancelString','None');
% fill zeros for missed keywords
num_zeros = zeros(1,(5 - numel(indx)));
pad_indx = horzcat(indx, num_zeros);
% save words correct
scoreSave(ii,:) = pad_indx;
end
When I try to run in parallel, they run simultaneously:
fun1 = @audioPlayback;
fun2 = @ScoreQuickSIN;
playbackThread = parfeval(fun1, 0, audioList);
scoreSave_1 = parfeval(fun2, 0, keywords, sentences);
Am I doing something wrong? Is there a better way to do this?
I don't want to use audioplayer because the output sound level seems to depend on the output level I have set for my computer, which I don't want (e.g., I don't want changing the speaker volume on the computer to change the output level).

Akzeptierte Antwort

Francis Tiong
Francis Tiong am 4 Mai 2023
The AudioFileReader and other audio interface functions cannot be run in the background. In addition, the user interface functions cannot be run in the background also. You can run the signal processing tasks or string processing tasks in the background. You can run the processing inside that audio loop and for each data frame push/check for processing going to and back from the other threads.
  5 Kommentare
Francis Tiong
Francis Tiong am 4 Mai 2023
Use of class or function AudioFileReader is not supported on a thread-based worker.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by