This is my function :
def speak_text(text, voice, rate=150):
engine = pyttsx3.init()
print("TEXT : ", text, '\n')
print("VOICE : ", voice, '\n')
engine.setProperty('voice', voice)
engine.setProperty('rate', rate)
download_dir = 'dir_mp3'
os.makedirs(download_dir, exist_ok=True)
file_path = os.path.join(download_dir, "my_audio.wav")
engine.save_to_file(text, file_path)
engine.runAndWait()
engine.stop()
return file_path
`
And when I call this function in my main function :
if genders=="Male":
bytes_path = speak_text(story, voices[0])
else:
bytes_path = speak_text(story, voices[1])
with open(bytes_path, "rb") as mp3_file:
aud_bytes = mp3_file.read()
with open(bytes_path, "rb") as mp3_file:
aud_bytes = mp3_file.read()
I get an error saying that file or directory doesn’t exists, but when I manually print ‘bytes_path’ variable I get complete path of .wav file.
Note that code is uploaded on Github and while deploying my app I’m getting these logs .
Is there anything wrong with my code ?
Thanks
I Appreciate your response