0

I created a small function that converts string to speech and saves to a .mp3 file.

This works without any issues on main thread. But when I run this function on second thread it doesn't generate any .mp3 file and doesn't raise any error. Do you have any idea what could cause that?

Edit: I realized that I have never initialized text_to_speech.py, only ran the function.

File with text-to-speech function:

# text_to_speech.py

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices') 

engine.setProperty('voice', voices[3].id)
engine.runAndWait()

def tts_to_file(text_string, save_file_path):
    
    engine.save_to_file(text_string, save_file_path)
    engine.runAndWait()

Main thread (works):

# main_file.py

from text_to_speech import tts_to_file
tts_to_file("Hello world", "./test.mp3")

Main thread (doesn't work):

# main_file.py

from text_to_speech import tts_to_file
from threading import Thread

p = Thread(target = tts_to_file, args = ("Hello world", "./test.mp3"))
p.start()
p.join()
# This doesn't do anything and raises no errors
herdek550
  • 625
  • 1
  • 5
  • 10

1 Answers1

0

I realized that I have never initialized text_to_speech.py, only ran the function.

herdek550
  • 625
  • 1
  • 5
  • 10