why os.remove isn't removing a file in python?

Question:

I have imported and installed all the libraries properly, and wrote the side code until here

def speak(audio_str):
    tts = gTTS(text=audio_str, lang='en')
    r = random.randint(1, 10000000)
    audio_file = 'audio-' + str(r) + '.mp3'
    tts.save(audio_file)
    playsound.playsound(audio_file)
    speak(audio_str)
    os.remove(audio_file)

when it came to executing:
speak('How can I help you?')
It played the sound but didn’t remove the created voice file
any solutions?

Asked By: O_MEEEER

||

Answers:

os.remove() isn’t removing the file because your code never reaches it, because it recurses before it gets there.

Remove the speak(audio_str) immediately preceding.

Answered By: Charles Duffy
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.