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
相关文章