Python GTTS Error : AttributeError: #39;NoneType#39; object has no attribute #39;group#39;(Python GTTS错误:AttributeError:#39;NoneType#39;对象没有属性#39;组#39;)
本文介绍了Python GTTS错误:AttributeError:';NoneType';对象没有属性';组';的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目,其中我正在进行文本到语音的转换。我的音频文件正在存储为mp3。
但现在,当我检查Gtts API是否抛出错误时。我尝试搜索,但找不到该错误的可行解决方案。
我的代码如下:
def synth(sent,language='en',slow = False):
"""
Synthesize text into audio
"""
os.system('clear')
print("Speaker Output:" + sent)
gt_ob = gTTS(text=sent, lang=language, slow=slow)
file_name = hashlib.md5(sent.encode('utf-8')).hexdigest()
print("File Name " + file_name)
gt_ob.save("media/audio.mp3")
print("Till here")
os.system("ffmpeg -nostats -loglevel 0 -y -i media/audio.mp3 -ar 16000 media/"+ file_name + ".wav")
if __name__ == "__main__":
synth("good morning","en")
我收到的错误消息是:
File "file_name.py", line 30, in <module>
synth("good morning","en")
File "file_name.py", line 25, in synth
gt_ob.save("media/audio.mp3")
File "/home/arqam/anaconda3/lib/python3.6/site-packages/gtts/tts.py", line 247, in save
self.write_to_fp(f)
File "/home/arqam/anaconda3/lib/python3.6/site-packages/gtts/tts.py", line 187, in write_to_fp
part_tk = self.token.calculate_token(part)
File "/home/arqam/anaconda3/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token
seed = self._get_token_key()
File "/home/arqam/anaconda3/lib/python3.6/site-packages/gtts_token/gtts_token.py", line 62, in _get_token_key
a = re.search("a\\x3d(-?d+);", tkk_expr).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
那么,我们如何解决这个弹出的错误?
推荐答案
现在有了官方修复。这与gtts,gtts-token的上游依赖有关。已在gtts-token==1.1.2
gtts和gtts-token后,该问题已修复。现在,它正在发挥作用。感谢开源的神和@carrey-cole
链接:https://github.com/pndurette/gTTS/issues/137
这篇关于Python GTTS错误:AttributeError:';NoneType';对象没有属性';组';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:Python GTTS错误:AttributeError:';NoneType';对象没有属性';组';
基础教程推荐
猜你喜欢
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
