Ошибка с тегом enable_speaker_diarization в Google Cloud Speech to Text

Попробуйте это,

[ngClass]="{'aside': true, 'links': message === 'NORMAL', 'links2' : message === 'LIGHT'}"

0
задан Asif Shaikh 20 January 2019 в 07:46
поделиться

1 ответ

Параметр enable_speaker_diarization=True в speech.types.RecognitionConfig в данный момент доступен только в библиотеке speech_v1p1beta1, поэтому вам нужно импортировать эту библиотеку, чтобы использовать этот параметр, а не речевой по умолчанию. Я сделал некоторые изменения в вашем коде и отлично работает для меня. Учтите, что вам нужно использовать служебную учетную запись для запуска этого кода.

def transcribe_gcs(gcs_uri):
    from google.cloud import speech_v1p1beta1 as speech
    from google.cloud.speech_v1p1beta1 import enums
    from google.cloud.speech_v1p1beta1 import types
    client = speech.SpeechClient()
    audio = types.RecognitionAudio(uri = gcs_uri)
    config = speech.types.RecognitionConfig( language_code = 'en-US',enable_speaker_diarization=True, diarization_speaker_count=2)
    operation = client.long_running_recognize(config, audio)
    print('Waiting for operation to complete...')
    response = operation.result(timeout=3000)
    result = response.results[-1]

    words_info = result.alternatives[0].words

    tag=1
    speaker=""

    for word_info in words_info:
        if word_info.speaker_tag==tag:
            speaker=speaker+" "+word_info.word

        else:
            print("sepaker {}: {}".format(tag,speaker))
            tag=word_info.speaker_tag
            speaker=""+word_info.word

И результат должен быть таким:

enter image description here

0
ответ дан Alex Riquelme 20 January 2019 в 07:46
поделиться
Другие вопросы по тегам:

Похожие вопросы: