フィルターのクリア

Playing audio in the background while running another function

22 ビュー (過去 30 日間)
Erik J
Erik J 2023 年 5 月 3 日
コメント済み: Erik J 2023 年 5 月 11 日
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).

採用された回答

Francis Tiong
Francis Tiong 2023 年 5 月 4 日
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 件のコメント
Francis Tiong
Francis Tiong 2023 年 5 月 4 日
Use of class or function AudioFileReader is not supported on a thread-based worker.
Erik J
Erik J 2023 年 5 月 11 日
Thanks Francis!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by