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

10-08 16:42