I would like to know if there is a way to set Timeout on the google speech to text API call. From the documentation below is the code to get the test from a wav file. However what i need is be able to set the timeout for this API call. I don't want to wait forever for the response from Google API. At max i want to wait for 5 seconds, and if i don't get the result under 5 seconds i want to throw an error and move on with further execution.
static object SyncRecognize(string filePath)
{
var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "en",
}, RecognitionAudio.FromFile(filePath));
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine(alternative.Transcript);
}
}
return 0;
}