How to detect the end of a sound ?

841 views
Skip to first unread message

Sylvain Clément

unread,
Sep 5, 2012, 5:30:31 PM9/5/12
to psychop...@googlegroups.com
Dear Psychopy gurus,


In a experiment I have a sound playing in a routine. The sound duration is left blank becaus the sound duration may vary between trials (different sound for each trial). 

however, I like to launch the next step (display a rating scale) just after the end of a sound. My idea was to place the rating scale on the next routine. However I did not found how to force the "sound" routine de end when the sound is finished.

I first though I needed a "if sound_1.status==FINISHED: continueRoutine=False" code at each frame... But it looks like the sound never go to the FINISHED status (is there any explicit to check the sound status ? ).

Is there any trick to do what I want ?

Thanks in advance
Sylvain


Sylvain Clément

unread,
Sep 5, 2012, 6:12:31 PM9/5/12
to psychop...@googlegroups.com
Ok I've have found a way to get the things done...

To force the sound component (let's call it sound1) to switch to the FINISHED status at the end it is possible to  to enter sound1.getDuration() in the duration field (builder). 

Then to launch an action at the end of the sound (here I wanted to end the routine) you can add a code component and put this in the "each frame" field :

if son_essai.status==FINISHED: 
continueRoutine=False


A problem remains with the initialisation of sound1. The builder generates the following line :
sound1=sound.Sound('A',secs=sound1.getDuration()) 
which causes an error since we can't read the duration of a sound which is not yet created.

The trick to have it working is to add a piece of code in the first routine of the experiment (or at least a routine before the problematic one) with this line in the "Begin Experiment" field : 
sound1=sound.Sound('A',secs=1)


With this the generated line with "getDuration" is no more a problem since sound1 yet exists...

Hope this help....

Sylvain Clément

Jonathan Peirce

unread,
Sep 6, 2012, 5:00:45 AM9/6/12
to psychop...@googlegroups.com
I'll be having a look at the way that the sounds and durations are being initialised shortly. Unfortunately there isn't a way to detect whether a sound is actually finished, but psychopy could probably do something more reasonable like testing whether we have reached the time when the sound was /expected/ to finish. ie it could implement something like you've done and make your experiment code neater. :-)

Thanks for bringing this up

Jon
--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To post to this group, send email to psychop...@googlegroups.com.
To unsubscribe from this group, send email to psychopy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/exOSy0YlNyQJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

Jonathan Peirce

unread,
Oct 18, 2012, 8:03:51 AM10/18/12
to psychop...@googlegroups.com
I agree, it should be. Could you elaborate on "it isn't possible" ?

On 18/10/2012 09:40, Thomas K. Müller wrote:
I was wondering why it isn't possible to set the duration by calling a variable from the xlsx file. Have a column with the soundfile-names and a column with the duration of each file in seconds - let's call it 'tid'. Then in the component's (f.ex. 'sound_1') duration field we will type '$tid'. Since we can call the variable with the file-names in that component then why not the other variable?
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/Q5RgXFFLZpMJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Thomas K. Müller

unread,
Oct 18, 2012, 6:30:58 PM10/18/12
to psychop...@googlegroups.com
I'm running v1.75.01 on a Win 7 Asus laptop.
Using the builder.
winType is pyglet.
---

The stimuli consists of 18 sound files of varying length (from 16 to 53 seconds). I have an xlsx file with a column of names of sound files, and also a column with the length in seconds for each sound file.
My setup is fairly standard with an instructions routine followed by a loop running the 18 trials randomly. When listening to the sound stimuli the participant can press a button several times without stopping the routine, so "Force end of Routine" is unchecked. After the trial routine (still inside the loop) there's a routine asking for a decision (yes or no).

As I started out I left the Duration field empty, thinking "blank to use the duration of the sound file", but then the trial routine wouldn't finish and the program wouldn't move on to the decision. Then I tried the xlsx header name for the column with length for each file (preceded by $), but the problem persisted. From the present google group I got some hints about "getDuration()" and "sound_1.status==FINISHED" which solved it, but I just thought the xlsx method should work.

Kuppu Raj

unread,
May 8, 2017, 7:28:58 AM5/8/17
to psychopy-users
Any idea why '$sound.status==FINISHED' does not work to initiate mouse component in Psychopy builder? It rather works perfectly for Keyboard.

I am struggling to find answer for this

Michael MacAskill

unread,
May 8, 2017, 4:23:12 PM5/8/17
to psychop...@googlegroups.com

> On 8/05/2017, at 23:28, Kuppu Raj <kupp...@gmail.com> wrote:
>
> Any idea why '$sound.status==FINISHED' does not work to initiate mouse component in Psychopy builder? It rather works perfectly for Keyboard.
>
> I am struggling to find answer for this

Hello,

This group is no longer active. Please take this query to discourse.psychopy.org

Regards,

Michael


Reply all
Reply to author
Forward
0 new messages