I'm trying to make an assistant but when the user wants to play a song, it keeps playing it until finishes. I want it to stop when the user presses a key. It is same for the engine.say()
, too.
I couldn't find a way to interrupt actions on their docs. There is engine.stop()
for pyttsx3 but I couldn't make it work. I thought it might be because of the engine.runAndWait()
but if I don't include it the machine says nothing. How can I solve these problems?
I can try using another module too if there is a way to solve this.
import pyttsx3
from playsound import playsound
if "play" in input:
songName = input[5:] + ".mp3"
try:
playsound(songName)
except:
engine.say("I couldn't find the song.")
engine.runAndWait()