Google语音云长期运行

时间:2019-01-05 09:56:49

标签: python speech-to-text

我是Python的新手,但是在Google Cloud Speech中取得了很大的进步....有一个文件可以很好地处理<1m音频,但是最后一天却花了很长时间试图弄清楚如何对其进行修改演讲。

2期 :

  1. 如何转换长脚本的代码
  2. 如何修改Google凭据以使用API​​
  3. 由于我需要单词置信度,因此需要使用Alpha或Beta版本的长篇演讲

同步输入太长。对于超过1分钟的音频,请使用带有'uri'参数的LongRunningRecognize。“>

 #!/usr/bin/env python3

from pprint import pprint
import pandas as pd
import speech_recognition as sr
import sys
import datetime
import json
from pandas import ExcelWriter
import numpy as np

# obtain path to audio file in the same folder as this script
from os import path

AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "thai120s.flac")

# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
    audio = r.record(source)  # read the entire audio file

# recognize speech using Google Cloud Speech
with open("1901api.json") as f:
    GOOGLE_CLOUD_SPEECH_CREDENTIALS = f.read()


try:
    print("Google Cloud Speech recognition results:")
    output=r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS,language="th-TH", show_all=True)  # pretty-print the recognition result
    dfimport = pd.DataFrame(output)
    count=len(output["results"])

    #initial = dfimport["results"][0]["alternatives"][0]["words"]
    #dfexport = pd.DataFrame(initial)
    dfexport = pd.DataFrame()

    for n in range(count):
        dftemp = dfimport["results"][n]["alternatives"][0]["words"]
        dfexport=dfexport.append(dftemp,sort=True)


    print(dfexport)
    #    dfexport = dfexport.append(pd.DataFrame(data))

    #df = pd.DataFrame(data)

    #print(df)

    print("______________________________")
    print("Nests Alternatives = ",count)
    dfexport.to_excel("output" + ".xlsx")


except sr.UnknownValueError:
    print("Google Cloud Speech could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Cloud Speech service; {0}".format(e))

0 个答案:

没有答案