python - 我的 pyvona speak() 函数不工作

标签 python function python-3.x pygame typeerror

我正在尝试使用 pyvona,但在 speak() 函数中,这种情况一直在发生。这是代码:

def speak(self, text_to_speak):
    """Speak a given text
    """
    if not pygame_available:
        raise PyvonaException(
            "Pygame not installed. Please install to use speech.")

    with tempfile.SpooledTemporaryFile() as f:
        with self.use_ogg_codec():
            self.fetch_voice_fp(text_to_speak, f)
        f.seek(0)
        if not pygame.mixer.get_init():
            pygame.mixer.init()
        channel = pygame.mixer.Channel(5)
        sound = pygame.mixer.Sound(f)
        channel.play(sound)
        while channel.get_busy():
            pass

错误是

Traceback (most recent call last):
    File "/Users/noahchalifour/Desktop/pyvona-0.25/pyvona.py", line 250, in <module>
        v.speak('Hello World')
    File "/Users/noahchalifour/Desktop/pyvona-0.25/pyvona.py", line 138, in speak
        sound = pygame.mixer.Sound(f)
TypeError: Unrecognized argument (type SpooledTemporaryFile)

最佳答案

试试这个

sound = pygame.mixer.Sound(file=f)

sound = pygame.mixer.Sound(file=f._file)

如果文件是声音文件,它应该可以工作。

关于python - 我的 pyvona speak() 函数不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35024598/

相关文章:

python - Python sshtunnel-如何验证SSH连接?

python - 从 go 客户端到 python 服务器的 Protobuf 消息

vba - 在 VBA 中通过字符串的值调用变量

当我添加参数时,Javascript 函数不会触发

javascript面向对象函数调用初学者问题

multithreading - 在 QThread.exit() 上立即停止处理事件队列

python - 如何robuSTLy检索python环境的bin路径?

python - 在 Twisted 中将消息从一台服务器发送到另一台服务器

Python 写入 csv 忽略逗号

python - 有没有办法用 qpython 进行 ssh ?