0

Using the pyttsx3 text-to-speech library, I'm saving the audio files during the iteration of the list of strings.

The program is always stacked on the second round after saving the file.

What may possibly be the cause of this behavior?

    import pyttsx3
    engine = pyttsx3.init()
    names = ["1", "2", "3", "4", "5", "6", "7"]
    for idx, name in enumerate(names):
        print(name)
        engine.save_to_file('Hello World', f'test-{idx}.mp3')
        engine.runAndWait()

When looping the same list of data, there is no issue with the engine.say('Hello World') method.

shapale
  • 123
  • 2
  • 9

1 Answers1

0

I had to move the runAndWait() method out of the loop since during the loop action engine will gather all the calls and after that runs the list of them

    import pyttsx3
    engine = pyttsx3.init()
    names = ["1", "2", "3", "4", "5", "6", "7"]
    for idx, name in enumerate(names):
        print(name)
        engine.save_to_file('Hello World', f'test-{idx}.mp3')
    engine.runAndWait()
shapale
  • 123
  • 2
  • 9