Возвращает пять слов аудио продолжительностью 1 минута

Я реализовал пример кода Google для преобразования аудио в текст, аудио размещено в облаке Google и имеет следующие функции: формат: flac, частота дискретизации: 16000, 320 кбит / с, канал: моно, язык: испанский. Я использую следующий код:

import sys
import os
import io


os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = '/home/eparionad/Dropbox/Tesis/CredencialesApiGoogle/Tesis-59cc7659afbc.json'

speech_file = '/home/eparionad/Descargas/19-02-2018/JuninInformado/3-JuninInformado-19-02-18-13:51.flac'


def transcribe_gcs():
    """Asynchronously transcribes the audio file specified by the gcs_uri."""
    from google.cloud import speech
    from google.cloud.speech import enums
    from google.cloud.speech import types
    client = speech.SpeechClient()

    gcs_uri = 'gs://audiosparareconocimiento/3-JuninInformado-19-02-18-13:51.flac'

    audio = types.RecognitionAudio(uri=gcs_uri)
    config = types.RecognitionConfig(
        encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
        sample_rate_hertz=16000,
        language_code='es-PE')

    operation = client.long_running_recognize(config, audio)

    print('Waiting for operation to complete...')
    response = operation.result(timeout=90)

    # Each result is for a consecutive portion of the audio. Iterate through
    # them to get the transcripts for the entire audio file.
    for result in response.results:
        # The first alternative is the most likely one for this portion.
        print('Transcript: {}'.format(result.alternatives[0].transcript))
        print('Confidence: {}'.format(result.alternatives[0].confidence))
# [END def_transcribe_gcs]

transcribe_gcs()

1 ответ

Попробуйте увеличить значение тайм-аута, чтобы получить больше слов

Вместо:

response = operation.result(timeout=90)

Положил:

response = operation.result(timeout=900)
Другие вопросы по тегам