Точка доступа Google Cloud для преобразования речи в текст

Я использую точку доступа Google Cloud Speech-to-Text и пытаюсь расшифровать длинный аудиофайл, однако аудиофайл из корзины не может быть обнаружен. Я получаю сообщение об ошибке: IOError: [Errno 2] Нет такого файла или каталога:

def transcribe_gcs (gcs_uri):

time(gcs_uri)

"""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()

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

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(u'Transcript: {}'.format(result.alternatives[0].transcript))
    print('Confidence: {}'.format(result.alternatives[0].confidence))

person Shruti    schedule 27.05.2018    source источник


Ответы (1)


Попробуй это

import requests
import json

url = "https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<apiaccesskey>"


payload = {"config": {"encoding": "LINEAR16","sample_rate_hertz": 8000,
                     "language_code": "en-IN"},
                     "audio": {"uri": "gs://bucketname/file.flac"}}

r = requests.post(url, data=json.dumps(payload))

json_resp = r.json()
token_resp=json_resp['name']

url = "https://speech.googleapis.com/v1/operations/" + str(token_resp) + 
      "?key=<apiacesskey>"

content_response = requests.get(url)
content_json = content_response.json()

Ваш ответ находится в content_json переменной.

person Yash Kumar Atri    schedule 28.06.2018