Google Speech Cloud Longrunning - PullRequest
       5

Google Speech Cloud Longrunning

0 голосов
/ 05 января 2019

Я новичок в Python, но добился большого прогресса в Google Cloud Speech .... у меня есть файл, работающий хорошо для аудио <1 м, но я потратил последний день, пытаясь выяснить, как изменить его надолго речь. </p>

2 вопроса :

  1. Как конвертировать код для длинного скрипта
  2. Как изменить учетные данные Google для использования API
  3. нужно использовать альфа- или бета-версию длинной речи, так как мне нужна уверенность в слове

Входной сигнал синхронизации слишком длинный. Для аудио длительностью более 1 минуты используйте LongRunningRecognize с параметром 'uri'. ">

 #!/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))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...