Pyttsx3 不工作,进程结束,退出代码为 0

Pyttsx3 not working, process finished with exit code 0

我正在制作一个人工智能 (AI) 助手,我写了这个让它说话:

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[0].id)


def speak(audio):
    engine.say(audio)
    print(audio)
    engine.runAndWait()

它不会说话和显示:

Process finished with exit code 0

如何解决?

您忘记使用该功能了。使用此代码:

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[0].id)


def speak(audio):
    engine.say(audio)
    print(audio)
    engine.runAndWait()


# what you are missing
# use your function to say something
speak('Hello')

希望它有用!