2016-10-26 118 views
0

我需要通過Google Cloud Speech API進行實時語音識別。然而,它仍處於beta版本,並沒有太多有用的東西在互聯網上。Google Cloud Streaming Speech API

https://cloud.google.com/speech/docs/samples這裏有少量樣本可用,但我沒有看到使用C#的流式API,這是否意味着我無法使用C#來蒸發我的音頻輸入Google Cloud Speech API?

任何人都嘗試使用.NET將音頻輸入流傳輸到Cloud Speech API?

僅供參考,我無法使用Google提供的普通Web Speech API。我只需要使用Goolge Cloud Speech API。

+0

似乎有是誰在C#使得它的人。然而,沒有任何示例代碼可用。 https://groups.google.com/forum/#!topic/cloud-speech-discuss/cdGB40GAeOc如果您發現任何問題,請告訴我。我一直在尋找答案。 – Hespen

+1

Hespen,臨時解決方案我引入了node.js二進制服務器,並通過websocket連接到我的JS以用於音頻流。然後Node.js與Google Cloud Speech API進行通信。這個解決方案似乎現在運行良好,但我真的很想找C#來使它簡單,乾淨 –

+0

感謝您的信息! – Hespen

回答

2

你必須從這裏下載示例應用程序: https://cloud.google.com/speech/docs/samples

的,你會發現,這些語音樣本:快速入門和認識。

Recogize有很多選項,其中之一是Listen。此示例是流式音頻,並將結果連續寫入控制檯。

該示例使用protobuf字節流進行流式傳輸。 這裏是代碼的主要部分:

var credential = GoogleCredential.FromFile("privatekey.json").CreateScoped(SpeechClient.DefaultScopes); 
var channel = new Grpc.Core.Channel(SpeechClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials()); 
var speech = SpeechClient.Create(channel); 
var streamingCall = speech.StreamingRecognize(); 
// Write the initial request with the config. 
await streamingCall.WriteAsync(
    new StreamingRecognizeRequest() 
    { 
     StreamingConfig = new StreamingRecognitionConfig() 
     { 
      Config = new RecognitionConfig() 
      { 
       Encoding = 
       RecognitionConfig.Types.AudioEncoding.Linear16, 
       SampleRateHertz = 16000, 
       LanguageCode = "hu", 
      }, 
      InterimResults = true, 
     } 
    }); 

當然,語言必須改變。

然後必須將內容流傳輸:

streamingCall.WriteAsync(
    new StreamingRecognizeRequest() 
    { 
     AudioContent = Google.Protobuf.ByteString 
      .CopyFrom(args.Buffer, 0, args.BytesRecorded) 
    }).Wait();