How do I return the result of this method to a textbox
static async Task<object> StreamingRecognizeAsync(string filePath)
{
var speech = SpeechClient.Create();
var streamingCall = speech.StreamingRecognize();
String saidWhat, lastSaidWhat = null;
// 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 = "pt-br",
},
InterimResults = true,
}
});
// Print responses as they arrive.
Task printResponses = Task.Run(async () =>
{
while (await streamingCall.ResponseStream.MoveNext(
default(CancellationToken)))
{
foreach (var result in streamingCall.ResponseStream
.Current.Results)
{
foreach (var alternative in result.Alternatives)
{
saidWhat = alternative.Transcript;
if (lastSaidWhat != saidWhat)
{
Console.WriteLine(saidWhat);
lastSaidWhat = saidWhat;
PegaTexto(saidWhat);
//Need to call this on UI thread ....
//textBox1.Invoke((MethodInvoker)delegate { textBox1.AppendText(textBox1.Text + saidWhat + " \r\n"); });
}
}
}
}
});
// Stream the file content to the API. Write 2 32kb chunks per
// second.
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
{
var buffer = new byte[32 * 1024];
int bytesRead;
while ((bytesRead = await fileStream.ReadAsync(
buffer, 0, buffer.Length)) > 0)
{
await streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
AudioContent = Google.Protobuf.ByteString
.CopyFrom(buffer, 0, bytesRead),
});
await Task.Delay(500);
};
}
await streamingCall.WriteCompleteAsync();
await printResponses;
return 0;
}