简体   繁体   English

Python GTTS 错误:AttributeError:'NoneType' 对象没有属性 'group'

[英]Python GTTS Error : AttributeError: 'NoneType' object has no attribute 'group'

I have a project where I was doing text to speech conversion.我有一个项目,我正在做文本到语音的转换。 My audio file is being stored as a mp3.我的音频文件被存储为 mp3。

But now, when I check the Gtts api is throwing error.但是现在,当我检查 Gtts api 时抛出错误。 I tried searching but couldn't find a workable solution for the bug.我尝试搜索,但找不到针对该错误的可行解决方案。

My code is as follows:我的代码如下:

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")

And the Error message that I am getting is :我收到的错误消息是:

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'

So how can we resolve this bug that has popped up?那么我们如何解决这个弹出的错误呢?

There is an official fix now.现在有官方修复。 It had to do with an upstream dependency of gtts , gtts-token .它与gttsgtts-token的上游依赖有关。 It has been fixed in gtts-token==1.1.2它已在gtts-token==1.1.2得到修复

The issue was fixed after I did a fresh install of both gtts and gtts-token .在我重新安装gttsgtts-token后,问题得到了解决。 Now it is working.现在它正在工作。 Thanks to open source gods and @carrey-cole感谢开源大神和@carrey-cole

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

It appears this is a known bug that was already fixed seven days ago as of writing: https://github.com/pndurette/gTTS/issues/137看来这是一个已知的错误,在撰写本文时已于 7 天前修复: https : //github.com/pndurette/gTTS/issues/137

The solution would be to upgrade the gTTS-token package.解决方案是升级 gTTS-token 包。

Try the following:请尝试以下操作:

pip install google_tts

it works the same它的工作原理相同

import google_tts
a = google_tts.TTS(text = 'hello world')
a.save('test.mp3')

If you are using Windows 7, 8, or 10 along with Anaconda for Python, open the Anaconda prompt and try this:如果您将 Windows 7、8 或 10 与 Anaconda for Python 一起使用,请打开 Anaconda 提示符并尝试以下操作:

pip install gtts --upgrade

pip install gtts-token --upgrade

This work for me.这对我有用。

The problem occurs since the gtts version is outdated.出现这个问题是因为gtts版本过时了。

Run the following command in CLI在 CLI 中运行以下命令

pip install gtts --upgrade

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:&#39;NoneType&#39;对象没有属性&#39;group&#39;错误 - AttributeError: 'NoneType' object has no attribute 'group' error Python“AttributeError:&#39;NoneType&#39;对象没有属性”错误 - Python "AttributeError: 'NoneType' object has no attribute" Error AttributeError:&#39;NoneType&#39;对象没有属性&#39;group&#39;无法解析(Python) - AttributeError: 'NoneType' object has no attribute 'group' Can't Parse (Python) Python 正则表达式 AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;group&#39; - Python regex AttributeError: 'NoneType' object has no attribute 'group' Python (googletrans) - AttributeError: 'NoneType' object 没有属性 'group' - Python (googletrans) - AttributeError: 'NoneType' object has no attribute 'group' AttributeError: 'NoneType' object 没有属性 'group' googletrans python - AttributeError: 'NoneType' object has no attribute 'group' googletrans python Python 2.7 / Selenium 2 AttributeError:“ NoneType”对象没有属性“ group” - Python 2.7/Selenium 2 AttributeError: 'NoneType' object has no attribute 'group' Python 正则表达式捕获和 AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;group&#39; - Python regex capturing & AttributeError: 'NoneType' object has no attribute 'group' Python Windows 抛出 AttributeError:“NoneType”对象没有属性“组” - Python Windows throws AttributeError: 'NoneType' object has no attribute 'group' 奇怪的“AttributeError:‘NoneType’对象没有属性‘组’”错误 - Odd "AttributeError: 'NoneType' object has no attribute 'group'" error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM