Swain_Woo 2023-08-17 01:44 采纳率: 0%
浏览 59
已结题

pyttsx3父类初始化函数及内核挂掉问题

问题遇到的现象和发生背景

本人使用的是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内核直接挂掉
如图所示

img

  • 写回答

10条回答 默认 最新

  • Marst·Zhang 2023-08-17 08:47
    关注

    在macOS系统上,需要确保安装了pyobjc库.
    (PyObjC是一个Python框架,用于在Python中使用Objective-C编写的Cocoa应用程序。它提供了一组工具和桥接代码,使得可以直接在Python中调用Objective-C的API。)
    安装指令如下

    pip install pyobjc
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月24日
  • 创建了问题 8月17日