You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UWP连续语音识别为何自动停止?已设无超时仍异常

Troubleshooting Random Stopping in UWP Continuous Speech Recognition

Hey Michael, great call going with SpeechRecognizer instead of Cortana—you’re totally right about the control benefits. Let’s break down why your continuous recognition is stopping randomly even with timeouts set to 0, and how to fix this issue.

Why This Is Happening

First, an important detail: setting those timeout values to TimeSpan.FromSeconds(0) doesn’t always translate to "infinite" silence tolerance in practice. The UWP speech recognition engine has underlying fallback behaviors that can trigger a session completion even when you’ve disabled explicit timeouts.

When you see the Completed event fire with a SUCCESS status but no result, that’s the engine quietly concluding the "silent session" has ended—ignoring your timeout overrides. It’s not an error; it’s just the system’s default behavior kicking in when it detects prolonged silence.

Fixes to Keep Recognition Running Continuously

1. Add a Dictation Constraint (Critical!)

By default, the SpeechRecognizer uses a generic constraint with stricter session rules. Switching to a dictation constraint tells the engine you want open-ended, continuous listening:

// Replace your constraint compilation code with this
var dictationConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Dictation");
speechRecognizer.Constraints.Add(dictationConstraint);
SpeechRecognitionCompilationResult result = await speechRecognizer.CompileConstraintsAsync();

This changes the engine’s behavior to prioritize ongoing listening over quick session termination.

2. Disable All Possible Timeouts (Including the Ambiguous One)

You missed one key timeout setting that’s often the culprit: EndSilenceTimeoutAmbiguous. Add this to your OnLoaded setup:

speechRecognizer.Timeouts.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(0);

This covers edge cases where the engine isn’t sure if speech has ended, preventing premature session stops.

3. Auto-Restart Recognition in the Completed Event

As a safety net, detect when the session ends unexpectedly (without a result) and restart it automatically. Update your Completed event handler:

private async void ContinuousRecognitionSession_Completed(ContinuousRecognitionSession sender, SpeechContinuousRecognitionCompletedEventArgs args)
{
    // Restart if session succeeded but no result was generated
    if (args.Status == SpeechRecognitionResultStatus.Success)
    {
        if (speechRecognizer.State == SpeechRecognizerState.Idle)
        {
            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {
                await speechRecognizer.ContinuousRecognitionSession.StartAsync();
            });
        }
    }
}

Use the dispatcher to run this on the UI thread—speech recognition operations require main-thread access.

4. Verify App Capabilities

Double-check your Package.appxmanifest includes these required capabilities:

  • Microphone (for audio input)
  • Internet (some speech features rely on cloud processing, even for dictation)

Final Notes

With these changes, your recognition should run continuously until you explicitly call StopAsync(). Keep in mind the system might still pause recognition in edge cases (like if the app is minimized), but for foreground use, these fixes should resolve the random stopping issue.

内容的提问来源于stack exchange,提问作者Michael Bedford

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:01:29