0

I am trying to write a code for voice assistant but having problem in accessing my voiceModel file after saving.

Can anyone help me out please:)

My Code:

def talk(voiceModel):
    print(voiceModel)
    for line in voiceModel.splitlines():
        text_to_speech=gTTS(text='Welcome To Inspiration',lang='en-uk')
        text_to_speech.save('voiceModel.mp3')
        mixer.init()
        mixer.music.load('voiceModel.mp3')
        mixer.music.play()
        os.remove("voiceModel.mp3")

And I Got this error:

File "C:/Users/Harsh/Desktop/Projects/Python/Inspiration/Inspire.py", line 23, in talk
    os.remove("voiceModel.mp3")

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'voiceModel.mp3'

So I just want help to be within limit of accessing my file always without changing my program code a lot: Plzz Help???

Btw I went here but its not much of help to me Stack Overflow

Harsh
  • 9
  • 5

0 Answers0