我正在用 python 做一个虚拟助手。我用 pyttsx3 跟我说话。我以 oops 的方式编写了 pyttsx3 初始化。但是当我运行这段代码时,它什么也没说。这是我的代码。
import pyttsx3
class Speaker:
def __init__(self):
self.engine = pyttsx3.init() # Initializing pyttsx3
self.voices = self.engine.getProperty('voices') # Getting voices property
def speaker_config(self):
''' Configurations for speaker '''
self.engine.getProperty('voices')
self.engine.setProperty('voice', self.voices[1].id) # Changing voice male to female
self.engine.setProperty('rate', 140) # Changing the speed
def say(self):
self.engine.say('hello')
s1 = Speaker()
s1.say()```