Coder, pause a sound file

Actually I want one of two sounds tracks playing my Ss do a visual task. So far I have:

from psychopy import prefs
prefs.general['audiolib'] = ['pygame'] # also tried pyo
song1 = sound.Sound(u'stimuli/song1.wav', secs=-1)
song1.setVolume(1)
song2 = sound.Sound(u'stimuli/song2.wav', secs=-1)
song2.setVolume(1)
...
song1.play(fromStart=False)   #or just song1.play()
...
song1.stop()
song2.play(fromStart=False)

The problem is that it always starts each song from beginning. (Note its not a fixed time between stopping and starting again.) What I want is something like:

song1.pause()
song2.unpause()
...
song1.unpause()
song2.pause

etc.

I know there are such functions in pygame.mixer.music but I can’t figure out how to use those within psychopy. Or maybe there is some trick with sound.Sound which would be very simple – if I knew what it was.
Thanks in advance for considering this problem.

I’ve no answer for you but I’ve a similar problem. Anyway, since this was posted in 2017 I guess you would not really care about answers ^^!
Did you find a way to do this?

I never figure it out. I found that old app (experiment never worked so canned it). When I go from sound1 to sound2 it always starts at beginning. But if you have an answer, I would like to put it in my notes, incase it comes up again.

Bill Prinzmetal
(510)685-8623
billprinzmetal@gmail.com

Unfortunately no :confused:
My problem was much more simple as I had only one sound at a time (one sound to continuously display for 5 routines). For me it worked with sound.pause() // sound.play()
Did you try something like that?

Begining experiment

myVariable_sound1 = 0
my_Variable_sound2 = 0

End routine (sound 1)

myVariable_sound1 = myVariable_sound1 + t

Begining routine (when continuing sound 1)

mySound1.play(when = myVariable_sound1)

Not sure this would work however. But I guess it should be something similar :woman_shrugging:

To answer Bill’s question, it should have worked by specifying:

song1.stop(reset = False)

so that it won’t start from the beginning the next time song1.play() is called.

NB: in the intervening several years, one should generally now use the PTB backend from rather than pyo or pygame, as it has much better performance (courtesy of PsychToolBox).

@Ambre_Denis-Noel : I’m not sure I got from the posts above precisely what your issue is, or if you have indeed solved it?

Yep I solved it!