Skip to content
← Back to Community
How would I play/stop audio in python?
Profile icon
RhinoRunner

I know that you can use from replit import audio, but is there something in there that can make an audio file stop playing?
For example:

from replit import audio from time import sleep audio.play_file('beeping_noise.wav') # plays a sound sleep(2) # waits 2 seconds # something here that stops the noise audio.play_file('beeping_noise_2.wav') # plays another sound
Answered by 19wintersp [earned 5 cycles]
View Answer
Voters
Profile icon
GoncaloRod
Profile icon
RhinoRunner
Comments
hotnewtop
Profile icon
19wintersp

You can store the Source which is played, then pause that with set_paused:

from replit import audio from time import sleep source = audio.play_file("beeping_noise.wav") sleep(2) source.set_paused(True) audio.play_file("beeping_noise_2.wav")

More information in the documentation.

Profile icon
RhinoRunner

@19wintersp Yay, thanks!