Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I get the rest of the function to quit once a sound file is done playing out?

2 ビュー (過去 30 日間)
Kristi
Kristi 2014 年 9 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am working with a PsychToolbox code that plays out a continuous sound file (let's call it "Sound1") for approximately 2 minutes while a certain image is displayed on the computer screen. When Sound1 finishes play out, I want the image display to quit as well. The tricky part is that all of the sound files I will be playing out are not the same duration, so I cannot use a command to close out of the image display that is based on time. Are there any recommendations as to what syntax to use?

回答 (1 件)

Andrew Reibold
Andrew Reibold 2014 年 9 月 3 日
編集済み: Andrew Reibold 2014 年 9 月 3 日
If you use the audioplayer function you can use the stop function to close the image.
StopFcn - Function to execute one time when playback stops.
  1 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 9 月 4 日
編集済み: Joseph Cheng 2014 年 9 月 4 日
if not using audioplayer, you probably know the samplerate and number of samples of the audio such that you can calculate the number of seconds it is.
oh and FYI, There is a slight delay for the StopFcn
load chirp
bird = audioplayer(y,Fs);
playfunc = @(hand,ob) toc;
set(bird,'StopFcn',playfunc)
tic,play(bird)
which for me has a duration of 2.051 seconds but based on the number of samples in y and the sample rate Fs it should be close to 1.6 seconds. Not sure if that small bit of time matters to you.

Community Treasure Hunt

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

Start Hunting!

Translated by