本文介绍了如何在python中使用gTTS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下代码时

 from gtts import gTTS
 tts = gTTS('hello')
 tts.save('hello.mp3')

我收到"AttributeError:'NoneType'对象没有属性'group'".

I am getting "AttributeError: 'NoneType' object has no attribute 'group'".

Traceback (most recent call last):

File "C:\Users\HP\Desktop\Desktop\programming\Python_code\New Text Document - Copy (8) - Copy.py", line 3, in <module>
    tts.save('hello.mp3')
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\gtts\tts.py", line 247, in save
    self.write_to_fp(f)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\gtts\tts.py", line 187, in write_to_fp
    part_tk = self.token.calculate_token(part)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\gtts_token\gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\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'

是否可以在Python中使用gTTS?

Is it possible to use gTTS in Python?

推荐答案

现在有官方修复程序.它与gtts的上游依赖性有关, gtts-token .它已在gtts-token == 1.1.2

There is an official fix now. It had to do with an upstream dependency of gtts, gtts-token. It has been fixed in gtts-token==1.1.2

我重新安装了gtts和gtts-token后,我的问题已解决.

My issue was fixed after I did a fresh install of both gtts and gtts-token.

可以在此处中找到gtts中的相关github问题.这个问题在12小时内得到解决.赞美开源之神! :D

The relevant github issue in gtts can be found here. Amazing this issue was fixed in 12 hours. Praise the open source gods! :D

这篇关于如何在python中使用gTTS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 01:33