[英]Google Cloud Speech-to-Text API - Waiting infinitely
我正在嘗試使用Google Cloud語音轉文本API。
從API文檔了解到,我將mp3音頻文件格式轉換為.raw,然后上傳到存儲桶中。
這是我的代碼:
def transcribe_gcs(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()
# 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))
transcribe_gcs("gs://cloudh3-200314.appspot.com/cs.raw")
我做錯了什么?
我遇到了類似的問題,這與可接受的格式有關。 即使您可能已轉換為RAW,但格式仍然可能存在問題,如果無法讀取文件,則不會提供輸出。
我最近處理了一個56分鍾的音頻,該音頻花費了17分鍾,因此應該讓您知道應該持續多長時間。
使用sox處理文件,我發現可以使用以下命令運行的轉換參數-
sox basefile.mp3 -r 16000 -c 1 newfile.flac
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.