Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么启用自动标点符号=true在python 3中给出了一个错误_Python_Python 3.x_Google Speech Api - Fatal编程技术网

为什么启用自动标点符号=true在python 3中给出了一个错误

为什么启用自动标点符号=true在python 3中给出了一个错误,python,python-3.x,google-speech-api,Python,Python 3.x,Google Speech Api,我想从谷歌语音api中得到一个带有标点符号的文字记录。我正在使用Python3和 我在运行与示例代码完全相同的代码时出现此错误 我犯了一个错误 “ValueError:协议消息识别配置没有“enableAutomaticpuntuation”字段。 “ 我能做些什么来克服这个问题 def transcribe_file_with_auto_punctuation(path): client = speech.SpeechClient() with io.open(path, 'rb'

我想从谷歌语音api中得到一个带有标点符号的文字记录。我正在使用Python3和

我在运行与示例代码完全相同的代码时出现此错误

我犯了一个错误

“ValueError:协议消息识别配置没有“enableAutomaticpuntuation”字段。

我能做些什么来克服这个问题

def transcribe_file_with_auto_punctuation(path):
    client = speech.SpeechClient()

with io.open(path, 'rb') as audio_file:
    content = audio_file.read()
    audio = speech.types.RecognitionAudio(content=content)
    config = speech.types.RecognitionConfig(
    enableAutomaticPunctuation=True,
    encoding= speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    languageCode= 'en-US',
    model= 'default')

response = client.recognize(config, audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print('-' * 20)
    print('First alternative of result {}'.format(i))
    print('Transcript: {}'.format(alternative.transcript))

pythonapi使用snake_大小写约定(小写单词加下划线)命名所有选项,因此调用您想要的选项。请注意,这同样适用于:

您链接到的示例确实使用了snake_案例名称

请注意,自动标点是较新的API中的一个新功能,因此请确保导入正确的类。从:

新的beta版拼写为
v1p1beta1
,用于预览即将推出的功能。为了使用它,您需要从
google.cloud.speech\u v1p1beta1
导入,而不是从
google.cloud.speech
导入

而且该特性将来可能会从免费API中删除。正如
enableautomaticpuntuation
的v1p1beta1文档所述:

目前,这是一项试验性服务,向所有用户免费提供。在未来,这可能会作为高级功能独家提供


谢谢你@Martijn。我将代码更改为snake_case格式,但仍然出现相同的错误。ValueError:Protocol message RecognitionConfig没有“启用自动标点符号”字段。@isurugayashan:您使用的是
google.cloud.speech\u v1p1beta1
,测试版吗?谢谢@martijn该库文件有问题。pycharm 2018.1给出了特定库的一个未解决的引用错误,因此我在前面将其更改为google.cloude.speech_v1。问题一经解决就改回google.cloud.speech_v1p1beta1。
config = speech.types.RecognitionConfig(
    enable_automatic_punctuation=True,
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    language_code='en-US',
    model='default')