Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

is it pyttsx3 bug with print function?

Here is a simple text to speech program. All it does is that it takes in a sentence and a speaker(not from user) and prints the word at the time it is supposed to speak that word. But the problem arises with the print function(The one marked with #/).When this program gets executed I want to print the sentence in a single line. But when print function(#/ marked) is argument print(" ",end="") it first speaks the content and then prints the whole line.

source code:-

import pyttsx;
    def onStar(name):
        print(name+":-",end="")
def onWord(name, location, length):
    for x in range(location,length+location+1) :
        print(a[x],end="")

    print()    #*/      The function I am talking about.


#case1(works correctly)                  case2(does not work correctly[bug])
#    print("")                          print("",end="")
#    print()                       
#    or just any print() without end as 2nd arg.


sentence=a='The quick brown fox jumped over the lazy dog.
speaker="narrator"
engine = pyttsx3.init()
engine.connect('started-utterance', onStart)
engine.connect('started-word', onWord)
engine.say(a,speaker)
engine.runAndWait()
del engine

output :-

case 1 The words get printed with the speech but a every word is on next line

Narrator:-
The
quick
brown
fox
jumped
over
the
lazy
dog.

case2:- The text gets printed correctly but it gets printed after the sentence has been spoken.

Narrator:-The quick brown fox jumped over the lazy dog.

ps:-Its like python does not want me to print the sentence in the row.

Comments