Issue
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 play the audio and is connected to a tkinter button, right now I need a function to stop playing any audio.
Solution
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()
Answered By - user14463336
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.