问题遇到的现象和发生背景
本人使用的是macos arm架构,在Python中使用pyttsx3包时发生了父类初始化方法的错误。
遇到的现象和发生背景,请写出第一个错误信息
在
model = pyttsx3.init()
运行之后,发生了此错误
12: ObjCSuperWarning: Objective-C subclass uses super(), but super is not objc.super
class NSSpeechDriver(NSObject):
13 @objc.python_method
14 def initWithProxy(self, proxy):
---> 15 self = super(NSSpeechDriver, self).init()
16 if self:
17 self._proxy = proxy
AttributeError: 'super' object has no attribute 'init'
根据
https://stackoverflow.com/questions/76434535/attributeerror-super-object-has-no-attribute-init
的解决方法我更改了nsss.py的部分代码
更改前
def initWithProxy(self, proxy):
self = super(NSSpeechDriver, self).init()
if self:
self._proxy = proxy
self._tts = NSSpeechSynthesizer.alloc().initWithVoice_(None)
self._tts.setDelegate_(self)
# default rate
self._tts.setRate_(200)
self._completed = True
return self
更改后
def initWithProxy(self, proxy):
self = objc.super(NSSpeechDriver, self).init()
if self:
self._proxy = proxy
self._tts = NSSpeechSynthesizer.alloc().initWithVoice_(None)
self._tts.setDelegate_(self)
# default rate
self._tts.setRate_(200)
self._completed = True
return self
或者
def initWithProxy(self, proxy):
if self:
self._proxy = proxy
self._tts = NSSpeechSynthesizer.alloc().initWithVoice_(None)
self._tts.setDelegate_(self)
# default rate
self._tts.setRate_(200)
self._completed = True
return self
结果在运行
model.runAndwWait()
时
在发出前面通过model.say()输入的声音后,kernel内核直接挂掉
如图所示