连续语音识别 UWP
continuous speech recognition UWP
我正在使用 UWP 创建一个智能镜子应用程序,我尝试将该应用程序与连续语音识别集成,以便用户可以使用语音来控制它。但是 Bing Speech REST API 不支持连续语音识别,所以我还能用什么吗?如果有源码就更好了
Windows.Media.SpeechRecognition
支持连续识别 。 Microsoft Github for UWP 在他们的 Speech recognition and synthesis sample or check out the Microsoft Docs for Windows.Media.SpeechRecognition
中有一个这样的例子
我从这段代码中找到了一些思路,希望对你也有帮助。
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";
});
}
}
我正在使用 UWP 创建一个智能镜子应用程序,我尝试将该应用程序与连续语音识别集成,以便用户可以使用语音来控制它。但是 Bing Speech REST API 不支持连续语音识别,所以我还能用什么吗?如果有源码就更好了
Windows.Media.SpeechRecognition
支持连续识别 。 Microsoft Github for UWP 在他们的 Speech recognition and synthesis sample or check out the Microsoft Docs for Windows.Media.SpeechRecognition
我从这段代码中找到了一些思路,希望对你也有帮助。
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";
});
}
}