【发布时间】:2017-12-16 02:09:19
【问题描述】:
到目前为止,我对在 Microsoft 网站上找到的语音识别示例没有任何帮助。我还查看了这个网站 - https://mtaulty.com/2016/02/08/text-to-speech-and-more-with-windows-10-uwp-project-oxford/ 并尝试使用给出的示例,但它仍然无法正常工作。正在发生的事情是 SpeechRecognitionConfidence 被拒绝(我没有说什么)。在你问之前,是的,我有一个可以使用的麦克风,并且在“设置”中启用了所有功能。
我在这里缺少什么简单的东西吗?
如果您不太理解我的问题,请滚动到我上面链接的页面底部,并且用户 nhwilly1011 遇到了与我相同的问题。
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;
我也试过微软的例子,它也不起作用--
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();
}
【问题讨论】:
-
请编辑您的问题,提供错误的详细信息。 mtaulty.com 的链接可能会在几年后断开,因此将详细信息包含在一个位置(在 stackoverflow 中)会更安全。
-
当 UI 提示用户说话(我说了些什么)并且它无法识别我所说的内容时。它识别出我已经说过一些话,但它默认输出对“”所说的内容。
-
@kennyzx 我已经添加了代码-谢谢你的推荐
标签: c# uwp windows-10 speech-recognition speech-to-text