Python 使用替代语言代码的异步语音识别响应没有语言代码

Python 使用替代语言代码的异步语音识别响应没有语言代码,python,google-cloud-speech,Python,Google Cloud Speech,我正在尝试使用新的测试版,它允许在创建转录作业时提供一组语言,并将检测到的语言连同该语言的转录结果一起返回 当我从文档页面(同步)运行代码示例时,一切运行正常,检测到的语言代码在结果中返回: from google.cloud import speech_v1p1beta1 as speech client = speech.SpeechClient() speech_file = 'resources/multi.wav' first_lang = 'en-US' second_lang =

我正在尝试使用新的测试版,它允许在创建转录作业时提供一组语言,并将检测到的语言连同该语言的转录结果一起返回

当我从文档页面(同步)运行代码示例时,一切运行正常,检测到的语言代码在结果中返回:

from google.cloud import speech_v1p1beta1 as speech
client = speech.SpeechClient()

speech_file = 'resources/multi.wav'
first_lang = 'en-US'
second_lang = 'es'

with open(speech_file, 'rb') as audio_file:
    content = audio_file.read()

audio = speech.types.RecognitionAudio(content=content)

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=44100,
    audio_channel_count=2,
    language_code=first_lang,
    alternative_language_codes=[second_lang])

print('Waiting for operation to complete...')
response = client.recognize(config, audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print(result.language_code)  # this prints 'en-US'
    print('-' * 20)
    print('First alternative of result {}: {}'.format(i, alternative))
    print(u'Transcript: {}'.format(alternative.transcript))
from google.cloud import speech_v1p1beta1 as speech
client = speech.SpeechClient()

gs_url = 'gs://my-bucket-name/multi.wav'
first_lang = 'en-US'
second_lang = 'es'

audio = speech.types.RecognitionAudio(uri=gs_url)

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=44100,
    audio_channel_count=2,
    language_code=first_lang,
    alternative_language_codes=[second_lang])

print('Waiting for operation to complete...')
operation = client.long_running_recognize(config, audio)
response = operation.result(timeout=40)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print(result.language_code)  # this prints nothing! result.language_code is empty string 
    print('-' * 20)
    print('First alternative of result {}: {}'.format(i, alternative))
    print(u'Transcript: {}'.format(alternative.transcript))
但当我尝试异步模式时,语言代码不会随结果一起返回:

from google.cloud import speech_v1p1beta1 as speech
client = speech.SpeechClient()

speech_file = 'resources/multi.wav'
first_lang = 'en-US'
second_lang = 'es'

with open(speech_file, 'rb') as audio_file:
    content = audio_file.read()

audio = speech.types.RecognitionAudio(content=content)

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=44100,
    audio_channel_count=2,
    language_code=first_lang,
    alternative_language_codes=[second_lang])

print('Waiting for operation to complete...')
response = client.recognize(config, audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print(result.language_code)  # this prints 'en-US'
    print('-' * 20)
    print('First alternative of result {}: {}'.format(i, alternative))
    print(u'Transcript: {}'.format(alternative.transcript))
from google.cloud import speech_v1p1beta1 as speech
client = speech.SpeechClient()

gs_url = 'gs://my-bucket-name/multi.wav'
first_lang = 'en-US'
second_lang = 'es'

audio = speech.types.RecognitionAudio(uri=gs_url)

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=44100,
    audio_channel_count=2,
    language_code=first_lang,
    alternative_language_codes=[second_lang])

print('Waiting for operation to complete...')
operation = client.long_running_recognize(config, audio)
response = operation.result(timeout=40)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print(result.language_code)  # this prints nothing! result.language_code is empty string 
    print('-' * 20)
    print('First alternative of result {}: {}'.format(i, alternative))
    print(u'Transcript: {}'.format(alternative.transcript))
尽管存在以下情况,但仍会发生这种行为:

Speech-to-Text支持所有语音识别方法的替代语言代码:Speech:Recognite、Speech:LongRunningRecognite和Streaming

你知道如何为异步转录请求获取检测到的语言代码吗


您好,这里是云平台支持!似乎这通常是在API中发生的,而不是在Python客户端库本身中发生的。我已经打开了这个坑()来得到这个问题的澄清/解决方案。您可以启动PIT以在出现任何通知时接收通知。Hi@Victorgl和Al-Fat Toes调用long_running_Recognite方法时我也面临问题:ValueError:Protocol message RecognitionConfig没有“alternative_language_codes”字段。你们能解决这个问题吗?