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