You have to download the sample applications from here:
https://cloud.google.com/speech/docs/samples
The you will find the Speech samples: QuickStart and Recognize.
The Recogize have a lot option, and one of them is Listen. This sample is streaming audio, and write the result to the console continuously.
The sample uses a protobuf byte stream for streaming.
Here is the main part of the code:
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,
}
} );
of course the language must be changed.
Then must be stream the content:
streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
AudioContent = Google.Protobuf.ByteString
.CopyFrom( args.Buffer, 0, args.BytesRecorded )
} ).Wait();