Reputation: 133
So far I haven't had any luck with the voice recognition examples that I have found on Microsoft's website. I have also looked at this website - https://mtaulty.com/2016/02/08/text-to-speech-and-more-with-windows-10-uwp-project-oxford/ and I tried using the examples given and it still doesn't work. What is happening is the SpeechRecognitionConfidence is rejected (it isn't picking up that I said anything). Before you ask, yes I have a working microphone and everything is enabled in Settings.
Is there something simple that I'm missing here?
If you don't quite understand my question scroll to the bottom of the page I linked above and user nhwilly1011 has the same issue I am experiencing.
async void Button_Click_2(object sender, RoutedEventArgs e)
{
this.recognizer = new SpeechRecognizer();
await this.recognizer.CompileConstraintsAsync();
this.recognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(5);
this.recognizer.Timeouts.EndSilenceTimeout = TimeSpan.FromSeconds(20);
this.recognizer.UIOptions.AudiblePrompt = "Say whatever you like, I'm listening";
this.recognizer.UIOptions.ExampleText = "The quick brown fox jumps over the lazy dog";
this.recognizer.UIOptions.ShowConfirmation = true;
this.recognizer.UIOptions.IsReadBackEnabled = true;
this.recognizer.Timeouts.BabbleTimeout = TimeSpan.FromSeconds(5);
var result = await this.recognizer.RecognizeWithUIAsync();
if (result != null)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(
$"I have {result.Confidence} confidence that you said [{result.Text}] " +
$"and it took {result.PhraseDuration.TotalSeconds} seconds to say it " +
$"starting at {result.PhraseStartTime:g}");
var alternates = result.GetAlternates(10);
builder.AppendLine(
$"There were {alternates?.Count} alternates - listed below (if any)");
if (alternates != null)
{
foreach (var alternate in alternates)
{
builder.AppendLine(
$"Alternate {alternate.Confidence} confident you said [{alternate.Text}]");
}
}
this.txtResults.Text = builder.ToString();
}
}
SpeechRecognizer recognizer;
I have also tried the Microsoft example and it does not work either --
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
// Create an instance of SpeechRecognizer.
var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer();
//// Listen for audio input issues.
//speechRecognizer.RecognitionQualityDegrading += speechRecognizer_RecognitionQualityDegrading;
// Add a web search grammar to the recognizer.
var webSearchGrammar = new Windows.Media.SpeechRecognition.SpeechRecognitionTopicConstraint(Windows.Media.SpeechRecognition.SpeechRecognitionScenario.WebSearch, "webSearch");
speechRecognizer.UIOptions.AudiblePrompt = "Say what you want to search for...";
speechRecognizer.UIOptions.ExampleText = @"Ex. 'weather for London'";
speechRecognizer.Constraints.Add(webSearchGrammar);
// Compile the constraint.
await speechRecognizer.CompileConstraintsAsync();
// Start recognition.
Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync();
await speechRecognizer.RecognizeWithUIAsync();
// Do something with the recognition result.
var messageDialog = new Windows.UI.Popups.MessageDialog(speechRecognitionResult.Text, "Text spoken");
await messageDialog.ShowAsync();
}
Upvotes: 4
Views: 2763
Reputation: 4635
HERE you may found the wake up word speech recoognization from Windows.Media.SpeechRecognition
public MAINPage()
{
this.InitializeComponent();
this.Loaded += OnLoaded;
}
Windows.Media.SpeechRecognition.SpeechRecognizer recognizer;
public async void OnLoaded(object sender, RoutedEventArgs args)
{
this.recognizer = new SpeechRecognizer();
var commands = new Dictionary<string, int>()
{
[Constants.WAKEUP_INIT_WORD] = -90, //define your start word
[Constants.WAKEUP_STOP_WORD] = 90 //define your stop word
};
this.recognizer.Constraints.Add(new SpeechRecognitionListConstraint(
commands.Keys));
await this.recognizer.CompileConstraintsAsync();
this.recognizer.ContinuousRecognitionSession.ResultGenerated +=
async (s, e) =>
{
if ((e.Result != null) && (commands.ContainsKey(e.Result.Text)))
{
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
//e.Result.Confidence
double confidence = e.Result.RawConfidence;
if (e.Result.Confidence == SpeechRecognitionConfidence.Medium || e.Result.Confidence == SpeechRecognitionConfidence.High || confidence >0.85)
{
if (e.Result.Text == Constants.WAKEUP_INIT_WORD)
{
recordButton_Click(sender, args);
stopRecordButton.IsEnabled = true;
recordButton.IsEnabled = false;
}
if (e.Result.Text == Constants.WAKEUP_STOP_WORD)
{
stopRecordButton_Click(sender, args);
recordButton.IsEnabled = true;
stopRecordButton.IsEnabled = false;
}
}
}
);
this.recognizer.ContinuousRecognitionSession.Resume();
}
};
await this.recognizer.ContinuousRecognitionSession.StartAsync(
SpeechContinuousRecognitionMode.PauseOnRecognition);
}
enter code here
more varities are here https://mtaulty.com/2016/02/08/text-to-speech-and-more-with-windows-10-uwp-project-oxford/
Upvotes: 1
Reputation: 133
I have found out the answer. My computer was not enabled with Cortana so I initially wasn't getting an error message. After using a computer that had Cortana I was able to figure out that there was an issue with the network that I was using. After switching networks everything worked as expected. My error was Error with speech recognition: "Can't access the network" and it was fixed by switching to an unsecured WiFi connection.
Upvotes: 3