private async void btnListen_Click(object sender, RoutedEventArgs e) { bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (!permissionGained) { var ssml = await Modem.BuildSsmlAsync("Could not enable the microphone, please try again.", "en"); var modem = new Modem(AppConfiguration.ModemConfig); var speech = await modem.ProduceSpeechAsync(ssml); Play(speech); } else { txtUtterance.Text = "(listening...)"; var modem = new Modem(AppConfiguration.ModemConfig); var utterance = await modem.ListenAsync(); switch (utterance.Item1) { case ResultReason.RecognizedSpeech: txtUtterance.Text = utterance.Item2; break; case ResultReason.NoMatch: default: txtUtterance.Text = ""; var ssml = await Modem.BuildSsmlAsync("Could not understand utterance, please try again.", "en"); var speech = await modem.ProduceSpeechAsync(ssml); Play(speech); break; } } }