0
I wonder if it is possible to sign an event from a third party lib, which in the case is Microsoft.Speech.dll. Because, in my attempt, it did not work very well, ie, recognition does not happen and the event is not fired. I tried using Task
and also without, but I did not succeed. I don’t really know if it is possible. sign an event in this way and the request wait.
Thanks in advance for the attention and possible help. Follow the code.
private string retorno = string.Empty;
public async Task<string> Get()
{
var result = Task.Run(() =>
{
var comandos = new string[] { "comando 1", "comando 2", "comando N" };
var ci = new CultureInfo("pt-BR");
var sre = new SpeechRecognitionEngine(ci);
var gramatica = new Choices();
gramatica.Add(comandos);
var gb = new GrammarBuilder(gramatica);
var g = new Grammar(gb);
sre.RequestRecognizerUpdate();
sre.LoadGrammarAsync(g);
sre.SpeechRecognized += Sre_SpeechRecognized;
sre.SetInputToWaveFile("anyWavfile.wav");
sre.RecognizeAsync(RecognizeMode.Multiple);
});
await Task.WhenAll(result);
return retorno;
}
private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
retorno += e.Result.Text;
}
Explain better what you intend to do, not missing a await no
RecognizeAsync()
or on the call of yourGet()
?– Leandro Angelo
I ended up solving gave another way, holding the Thread until the event ends. These methods do not accept await, it is a very old lib. Thanks!
– Pazoti
It would be nice if you posted an answer to how you solved the question or closed the question to not leave it open.
– Leandro Angelo