首页 > 解决方案 > 谷歌云文本语音“没有属性'SynthesisInput'”错误

问题描述

https://cloud.google.com/text-to-speech/docs/libraries?hl=pt-br#client-libraries-install-python

在尝试主要的谷歌示例时,我收到了这个错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-92-866a7868dbb4> in <module>
     10 
     11 # Set the text input to be synthesized
---> 12 synthesis_input = texttospeech.SynthesisInput(text="Hello, World!")
     13 
     14 # Build the voice request, select the language code ("en-US") and the ssml

AttributeError: module 'google.cloud.texttospeech' has no attribute 'SynthesisInput'

有什么建议吗?使用 conda-forge:google-cloud-texttospeech 1.0.1

标签: pythongoogle-cloud-platformgoogle-text-to-speech

解决方案


我使用相同的库(google-cloud-texttospeech==1.0.1)尝试了您的示例,但它也失败了。解决这个问题的方法是简单地将您的库更新到最新版本(2.3.0),!pip install --upgrade google-cloud-texttospeech 然后您的代码片段就可以工作了。

使用过时的 1.0.1 版本时出错。

在此处输入图像描述

出于测试目的,我包括打印编码响应。 在此处输入图像描述


推荐阅读