I have 80 audio files as an experiment stimuli.
I can play 1 audio file but how can I play several files?
% load sound file (make sure that it is in the same folder as this script)
[soundData freq ] = audioread('FS1.wav');
%inidializes sound driver...the 1 pushes for low latency
InitializePsychSound(1);
% opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
% loads data into buffer
PsychPortAudio('FillBuffer', pahandle, soundData');
% how many repititions of the sound
repetitions=1;
%starts sound immediatley
PsychPortAudio('Start', pahandle, repetitions,0);

 採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 8 月 26 日

1 投票

% Code for Audio multiple files read
audio_files=dir('C:\complete_path_to folder\forlder_name\*.wav');
%........................^^........................^^ Note on this
for i=1:length(audio_files)
aud_file=strcat('C:\complete_path_to folder\forlder_name\',audio_files(i).name);
% load sound file (make sure that it is in the same folder as this script)
[soundData freq]=audioread(aud_file);
%inidializes sound driver...the 1 pushes for low latency
InitializePsychSound(1);
% opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
% loads data into buffer
PsychPortAudio('FillBuffer', pahandle, soundData');
%pause() if it require??
end

4 件のコメント

Takara Sumoto
Takara Sumoto 2019 年 8 月 27 日
I tried with 10 audio files instead of 80 (FS01, FS02,.....FS10) as for a trial.
It worked if I put "end" before % opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
But only one audio file (FS10) was played and stoped.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 8 月 27 日
The "end" use to for loop statement closing
for
%Play audio
end
After first play, it go to the second audio, hence use pause (define some value) commnad before end, so that current audio playing is completed, then only go for next audio.
Takara Sumoto
Takara Sumoto 2019 年 8 月 28 日
It worked when I added "stop" and "close" before "end".
Thank you so much for your help!!
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 8 月 28 日
Takara it’s my pleasure

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

その他の回答 (0 件)

製品

リリース

R2019a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by