Google语音转文本-使用Python保存和访问API结果

时间:2018-12-02 08:06:55

标签: json python-3.x google-cloud-speech

尝试在多个文件上运行Google云语音,然后使用python将结果另存为json。然后在以后访问文件并解析信息。

已经尝试了多次,但是当我保存文件时,我似乎无法稍后解析结果。我正在使用python和以下代码来调用服务并保存结果。

def transcribe_c_gcs(gcs_uri):
"""Asynchronously transcribes the audio file specified by the gcs_uri."""
from google.cloud import speech_v1p1beta1 as speech

client = speech.SpeechClient()

audio = speech.types.RecognitionAudio(uri=gcs_uri)
config = speech.types.RecognitionConfig(
    language_code='en-US',
    enable_word_time_offsets=True,
    enable_automatic_punctuation=True
    )

operation = client.long_running_recognize(config, audio)


reading = operation.result(timeout=90000)


with open( 'out.csv', 'w') as outfile:
    json.dump(result_json, outfile)

0 个答案:

没有答案