MATLAB Answers

Psychtoolbox: How to play selected audio files?

20 views (last 30 days)
Takara Sumoto
Takara Sumoto on 20 Oct 2020
Commented: Takara Sumoto on 24 Oct 2020
I would like to play Beep and selected audion files alternately.
How should I write a code to play selected audio files?
I have a code to play all audio files randomly but I want to play only selected files and not randomely.
% Code for Audio multiple files read
audio_files=dir('C:\toolbox\aud_file2\*.wav');
% initializes sound driver...the 1 pushes for low latency
InitializePsychSound(1);
% opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
%randomize
a=randperm(80);
for i=1:length(audio_files)
% load sound file (make sure that it is in the same folder as this script)
[soundData freq ] = audioread('Beep1000convert.mp3');
% loads data into buffer
PsychPortAudio('FillBuffer', pahandle, soundData');
% how many repititions of the sound
repetitions=1;
%starts sound immediatley
PsychPortAudio('Start', pahandle, repetitions,0);
% stop
PsychPortAudio('Stop', pahandle, 1,0);
% load sound file (make sure that it is in the same folder as this script)
aud_file=strcat('C:\toolbox\aud_file2\',audio_files(a(i)).name);
[soundData freq]=audioread(aud_file);
% wait
rs = randperm(3);
WaitSecs(2.0);
% fill buffer
PsychPortAudio('FillBuffer', pahandle, soundData');
% starts sound immediatley
PsychPortAudio('Start', pahandle, 1,0);
% stop
PsychPortAudio('Stop', pahandle, 1,0);
  4 Comments

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by