I am building a voice assistant using a tutorial.I am attaching the link below for reference
Now in the function def assistant_speaks(output) I have made some changes. Now whenever the assistant speaks, a back-end mp3 file is generated. The files are numbered randomly. I want to delete those mp3 files once the voice assistant stops. How to achieve that ? Here is the code -
num = random.randint(1,10000000000)
def assistant_speaks(output):
global num
num += 1
print("PerSon : ", output)
toSpeak = gTTS(text = output, lang ='en', slow = False)
file = str(num)+".mp3"
toSpeak.save(file)
playsound.playsound(file, True)
os.remove(file)
This worked for me. Instead of using the variable num as a global I passed it in directely into the function.
Hope this worked for you. (If not please let me know)