Python gtts 无法写入类文件对象

问题描述

我试图将 gtts 用于临时聊天机器人 AI,此代码为 tts

def say_sentence(sentence):
    tts = gTTS(sentence,'en')
    #ps,this lib is installed with pip install gtts
    f = TemporaryFile()
    tts.write_to_fp(f)
    #ps,this lib is installed with pip install audioplayer
    AudioPlayer(f).play(block=True)

但是运行的时候,这里有一个错误

Traceback (most recent call last):
  File "c:/Users/giuse/OneDrive/Desktop/Apps/Py/chatterbot/chatbot.py",line 34,in <module>
    say_sentence(response)
  File "c:/Users/giuse/OneDrive/Desktop/Apps/Py/chatterbot/chatbot.py",line 14,in say_sentence
    tts.write_to_fp(f)
  File "D:\Softwares\Python 3.8\lib\site-packages\gtts\tts.py",line 258,in write_to_fp
    prepared_requests = self._prepare_requests()
  File "D:\Softwares\Python 3.8\lib\site-packages\gtts\tts.py",line 193,in _prepare_requests
    text_parts = self._tokenize(self.text)
  File "D:\Softwares\Python 3.8\lib\site-packages\gtts\tts.py",line 157,in _tokenize
    text = text.strip()
AttributeError: 'Statement' object has no attribute 'strip'

我正在尝试解决这个问题,但没有成功,有什么帮助吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...