I am creating an app based on speech. Everything works fine but I do not want my app to use outside program to open mp3 file. At the moment program can do several commands only if I will use: cmd
def speak(text):
tts = gTTS(text=text, lang='pl')
filename = 'speak.mp3'
tts.save(filename)
cmd = filename #works for several commands with external program
os.system(cmd)
What I would like to do is something like this:
def speak(text):
tts = gTTS(text=text, lang='pl')
filename = 'speak.mp3'
tts.save(filename)
playsound.playsound(filename)
return speak
Unfortunately it works only for first audio input, second one gives error:
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\gtts\tts.py", line 294, in save
with open(str(savefile), 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'speak.mp3'
I was trying to delete mp3 file after it has been saved and played but it did not helped. Any idea how to solve it?