gpt4 book ai didi

Python GTTS 错误 : AttributeError: 'NoneType' object has no attribute 'group'

转载 作者:太空宇宙 更新时间:2023-11-03 12:26:19 24 4
gpt4 key购买 nike

我有一个项目,我正在做文本到语音的转换。我的音频文件正在存储为 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

中修复

在我全新安装 gttsgtts-token 后,问题得到解决。现在它正在工作。感谢开源大神和@carrey-cole

链接:https://github.com/pndurette/gTTS/issues/137

关于Python GTTS 错误 : AttributeError: 'NoneType' object has no attribute 'group' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52555027/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com