How do I stop playing music with simple audio?
Question:
How do you stop playing audio with simpleaudio?
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
I have a function here that plays the audio and is connected to a Tkinter button. Right now I need a function to stop playing any audio.
Answers:
See simpleaudio.
As suggested in the earlier comment, you can do it using wave_obj.stop or sa.stopall() which will stop all currently playing audio.
You would either use wave_obj.stop() to stop that specific audio, or you can use sa.stopall(), which will stop all audio. The code should either look like this:
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
# Play for as long as you want
stop_obj = wave_obj.stop()
Or this:
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
# Play for as long as you want
sa.stopall()
You just have to call .stop()
on the play object:
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
play_obj.stop()
How do you stop playing audio with simpleaudio?
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
I have a function here that plays the audio and is connected to a Tkinter button. Right now I need a function to stop playing any audio.
See simpleaudio.
As suggested in the earlier comment, you can do it using wave_obj.stop or sa.stopall() which will stop all currently playing audio.
You would either use wave_obj.stop() to stop that specific audio, or you can use sa.stopall(), which will stop all audio. The code should either look like this:
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
# Play for as long as you want
stop_obj = wave_obj.stop()
Or this:
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
# Play for as long as you want
sa.stopall()
You just have to call .stop()
on the play object:
def audio_1():
wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
play_obj = wave_obj.play()
play_obj.stop()