Python 我可以同时使用print()函数和speak或say(如pyttsx3模块中的)吗?
我正试图找到一种方法,使通过Python 我可以同时使用print()函数和speak或say(如pyttsx3模块中的)吗?,python,pyttsx,Python,Pyttsx,我正试图找到一种方法,使通过print()函数在屏幕上打印的文本同时也能被说出。我目前正在使用pyttsx3模块,但我不知道如何才能做到这一点 我不知道在这种情况下我可以尝试什么。下面的代码只是一个示例代码 import pyttsx engine = pyttsx.init() print('Sally sells seashells by the seashore.') engine.say('Sally sells seashells by the seashore.') print(
print()
函数在屏幕上打印的文本同时也能被说出。我目前正在使用pyttsx3
模块,但我不知道如何才能做到这一点
我不知道在这种情况下我可以尝试什么。下面的代码只是一个示例代码
import pyttsx
engine = pyttsx.init()
print('Sally sells seashells by the seashore.')
engine.say('Sally sells seashells by the seashore.')
print('The quick brown fox jumped over the lazy dog.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
我希望打印和引擎。说命令一起工作。在每个句子后使用runAndWait()
如果您为此定义了一个函数,然后在要打印和说出的句子列表上迭代,那么代码可能会是这样的:
import pyttsx3
engine = pyttsx3.init()
def print_and_speak(text):
print(text)
engine.say(text)
engine.runAndWait()
text_list = ['Sally sells seashells by the seashore.',
'The quick brown fox jumped over the lazy dog.']
for t in text_list:
print_and_speak(t)