No Rhyme, No Reason, Just Trial, Error and Luck


Every so often my Python code doesn't work even though it "should".

I'm relying on somebody's imported module and have no idea how it works.

In this case it is the PYTTSX3 module.

In theory, if you follow the instructions, it will accept a text string and output the corresponding audio in a male voice or a female voice. (TTS means Text To Speech).

I got it to work. But only ONCE. When called the second time ... silence.
Apparently I'm not the first to experience this puzzling behavior. Look it up in Reddit, look it up in Google and you see that others also ask, "How do I get 
PYTTSX3 to play more than once?"

Google's AI (Gemini) offers some suggestions but none of them work.
Out of frustration, I try all kinds of permutations including re-initializing the talk engine, time delays, whatever.

Out of dumb luck I stumble upon a variation that suddenly makes my old Windows 10 computer perform. Why does this variation work? No idea.
(Click on below images to make them larger, then Back to go back)



The upper image is a relative main (called Scratch_01.py) that calls upon on a Talker_go() function in the Funcs_02 module (inside the lower screen shot).

Notable in the lower image is that Talker_go() calls the engine.say() method twice. Once was not enough. Three times was too much and thus is commented out. Why does twice work? I have no idea. However I ran into the same thing with the Keyboard module. Perhaps it's something unique to my specific windows 10 old computer? Perhaps it is related to linking Python execution with asynchronous events?

Also note my insertion of an "um" string for delay. The um is composed of unpronounceable characters like tilda "~".

MORE TO EXPLORE
Google search: "getting a Python module method to execute by calling it twice"
Google search: "python calling async events"

tbc ...

Comments

Popular posts from this blog

Links for Python Noobs

The Learn HOW to Learn Page

Welcome to Circular Import Hell