Pyttsx3 error in streamlit

Hey there, I’m creating a streamlit application which requires TTS in it.
`

 def speak_text(text, voice, rate=150):
  
  engine = pyttsx3.init()

  print("TEXT : ", text, '\n')
  print("VOICE : ", voice, '\n')

  st.write("VOICE : " , voice)

  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)
  # time.sleep(2)
  engine.runAndWait()
  engine.stop()

  return file_path

The above code mentioned is working properly as desired in my local environment but during deployment I get file not found(my_audio.wav) error seems like file isn’t getting created inside the function and “file_path” contains a path which doesn’t exist.

Any idea why so ?
Link to my code

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.