我正在使用UWP创建一个智能镜像应用程序,我尝试将应用程序与连续语音识别集成起来,这样用户就可以使用语音来控制它。但是Bing语音REST不支持连续语音识别,所以我还可以使用其他什么吗?如果你有源代码,那就更好了。
发布于 2017-07-12 09:02:21
我从这段代码中找到了一些想法,希望它也能对你有所帮助。
public sealed partial class MainPage : Page
{ public MainPage()
{
this.InitializeComponent();
}
//連続音声認識のためのオブジェクト
private SpeechRecognizer contSpeechRecognizer;
private CoreDispatcher dispatcher;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
//ハックグラウンドスレッドからUIスレッドを呼び出すためのDispatcher
dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
//初期化
contSpeechRecognizer =
new Windows.Media.SpeechRecognition.SpeechRecognizer();
await contSpeechRecognizer.CompileConstraintsAsync();
//認識中の処理定義
contSpeechRecognizer.HypothesisGenerated +=
ContSpeechRecognizer_HypothesisGenerated;
contSpeechRecognizer.ContinuousRecognitionSession.ResultGenerated +=
ContinuousRecognitionSession_ResultGenerated;
// 音声入力ないままタイムアウト(20秒位)した場合の処理
contSpeechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
//認識開始
await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
}
private async void ContinuousRecognitionSession_Completed(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionCompletedEventArgs args)
{
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
textBlock1.Text = "Timeout.";
});
// 音声を再度待ち受け
await contSpeechRecognizer.ContinuousRecognitionSession.StartAsync();
}
private async void ContSpeechRecognizer_HypothesisGenerated(
SpeechRecognizer sender, SpeechRecognitionHypothesisGeneratedEventArgs args)
{
//認識途中に画面表示
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
textBlock1.Text = args.Hypothesis.Text;
});
}
private async void ContinuousRecognitionSession_ResultGenerated(
SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
{
//認識完了後に画面に表示
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
textBlock1.Text = "Waiting ...";
output.Text += args.Result.Text + "。\n";
});
}
}
发布于 2017-07-10 13:03:34
Windows.Media.SpeechRecognition
支持连续识别。Microsoft在他们的语音识别与合成样本中有一个这样的例子,或者查看MicrosoftDocsforWindows.媒体.语音识别
https://stackoverflow.com/questions/45004966
复制相似问题