I have a sound file which plays a beep and I want to play the sound continuously for a few seconds, so that it sounds like one continuous sound. Here is my code
alarm = sound.Sound('alarm.wav', secs = 5)
alarm.play()
But it only plays for 1 sec, which is how long the original sound is. Please help!
Here're some solutions:
Use psychopy to generate the beep:
alarm = sound.Sound(700, secs=5) # 700Hz beep
When you want a length that is a multiple of the original file, loop it, although this is likely to generate some clicks at each repeat (because of the sudden jump in amplitude, unless they match perfectly):
alarm = sound.Sound('alarm.wav', loops=5)
Use an audio editor to extend the beep to five seconds, making sure that there's no click at the loops. This is probably better than (2) if you have a fixed duration.
If you have multiple playback lengths, e.g. between conditions, use the alarm.stop()
at the appropriate time during the experiment. Then either set loops
to a high number or audio edit the sound to be long enough as in (3) so that you know that it only stops on your command.