1

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?

2 Answers2

0

Try to see the permissions of the file that has been created. It might have only read permissions.

Toto Briac
  • 908
  • 9
  • 29
0

When passing in the function, attempt to supply various file names for each of the distinct texts, or use the random.randit() method to set different file names, or use the current time as your file name using the time module.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – R. Marolahy Nov 27 '22 at 18:18