赞
踩
When executing the below code
from gtts import gTTS
tts = gTTS('hello')
tts.save('hello.mp3')
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
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'
Is it possible to use gTTS in Python?
解决方案
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
My issue was fixed after I did a fresh install of both gtts and gtts-token.
The relevant github issue in gtts can be found here. Amazing this issue was fixed in 12 hours. Praise the open source gods! :D
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。