你必須從這裏下載示例應用程序: 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();
似乎有是誰在C#使得它的人。然而,沒有任何示例代碼可用。 https://groups.google.com/forum/#!topic/cloud-speech-discuss/cdGB40GAeOc如果您發現任何問題,請告訴我。我一直在尋找答案。 – Hespen
Hespen,臨時解決方案我引入了node.js二進制服務器,並通過websocket連接到我的JS以用於音頻流。然後Node.js與Google Cloud Speech API進行通信。這個解決方案似乎現在運行良好,但我真的很想找C#來使它簡單,乾淨 –
感謝您的信息! – Hespen