Python GTTS错误:AttributeError:'NoneType'对象没有属性'组' [英] Python GTTS Error : AttributeError: 'NoneType' object has no attribute 'group'

查看:37
本文介绍了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'

那么,我们如何解决这个弹出的错误?

推荐答案

现在有了官方修复。这与gttsgtts-token的上游依赖有关。已在gtts-token==1.1.2

中修复 在我重新安装gttsgtts-token后,该问题已修复。现在,它正在发挥作用。感谢开源的神和@carrey-cole

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

这篇关于Python GTTS错误:AttributeError:&#39;NoneType&#39;对象没有属性&#39;组&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆