Run Google Cloud Speech Recognition

083     client = speech.SpeechClient()
084     
085     with io.open(speech_file, 'rb') as audio_file:
086         content = audio_file.read()
087 
088     audio = types.RecognitionAudio(content=content)
089     
090     response = client.recognize(config, audio)

行83~90是完整的google cloud speech recognition的操作。

行83建立一個speech.SpeechClient的程序(process),負責跟google cloud service的溝通。

行85-86是把speech_file音頻檔以二進位檔讀入,存在content變數裡。

行88是把content透過types.RecognitionAudio函數轉換成google speech-to-text api可以辨識的音頻格式audio

行90是透過client.recognize函數把configaudio上傳到google cloud server,server把轉譯完的結果傳回來,存在response變數裡。

results matching ""

    No results matching ""