是带有打印功能的 pyttsx3 错误吗?

is it pyttsx3 bug with print function?

这是一个简单的文本转语音程序。它所做的只是接受一个句子和一个说话者(不是来自用户),并在它应该说出那个词的时候打印这个词。但是打印函数(标有#/的函数)出现了问题。当这个程序被执行时,我想在一行中打印句子。但是当 print function(#/ marked) 是参数 print(" ",end="") 时,它首先说出内容,然后打印整行。

源代码:-

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

输出:-

案例一 单词与演讲一起打印,但每个单词都在下一行

旁白:-


棕色
狐狸
跳了
超过

懒惰
狗.

案例2:- 文本打印正确,但在说出句子后才打印。

旁白:-敏捷的棕色狐狸跳过了懒惰的狗。

ps:-就像 python 不希望我打印行中的句子。

在打印功能上设置flush=True

import pyttsx3

message = 'The quick brown fox jumped over the lazy dog.'

def onWord(name, location, length):
    print(message[location:location + length], end=' ', flush=True)


engine = pyttsx3.init()
engine.connect('started-word', onWord)
engine.say(message)
engine.runAndWait()