SpeechRecognitionEngine.BabbleTimeout 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置时间间隔,在此时间间隔内,SpeechRecognitionEngine 将在终结识别之前接受仅包含背景噪音的输入。
public:
property TimeSpan BabbleTimeout { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan BabbleTimeout { get; set; }
member this.BabbleTimeout : TimeSpan with get, set
Public Property BabbleTimeout As TimeSpan
属性值
计时器间隔的持续时间。
例外
该属性已设置为小于 0 秒。
示例
以下示例演示控制台应用程序的一部分,该应用程序演示了在启动语音识别之前设置 BabbleTimeout 和 InitialSilenceTimeoutSpeechRecognitionEngine 属性的基本语音识别。 语音识别器和AudioStateChangedRecognizeCompleted事件的处理程序将事件信息输出到控制台,InitialSilenceTimeout以演示 的属性SpeechRecognitionEngine如何影响识别操作。
using System;
using System.Speech.Recognition;
namespace SpeechRecognitionApp
{
class Program
{
static void Main(string[] args)
{
// Initialize an in-process speech recognizer.
using (SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(
new System.Globalization.CultureInfo("en-US")))
{
// Load a Grammar object.
recognizer.LoadGrammar(CreateServicesGrammar("FindServices"));
// Add event handlers.
recognizer.AudioStateChanged +=
new EventHandler<AudioStateChangedEventArgs>(
AudioStateChangedHandler);
recognizer.RecognizeCompleted +=
new EventHandler<RecognizeCompletedEventArgs>(
RecognizeCompletedHandler);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(3);
recognizer.BabbleTimeout = TimeSpan.FromSeconds(2);
recognizer.EndSilenceTimeout = TimeSpan.FromSeconds(1);
recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(1.5);
Console.WriteLine("BabbleTimeout: {0}", recognizer.BabbleTimeout);
Console.WriteLine("InitialSilenceTimeout: {0}", recognizer.InitialSilenceTimeout);
Console.WriteLine("EndSilenceTimeout: {0}", recognizer.EndSilenceTimeout);
Console.WriteLine("EndSilenceTimeoutAmbiguous: {0}", recognizer.EndSilenceTimeoutAmbiguous);
Console.WriteLine();
// Start asynchronous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Single);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
}
// Create a grammar and build it into a Grammar object.
static Grammar CreateServicesGrammar(string grammarName)
{
// Create a grammar for finding services in different cities.
Choices services = new Choices(new string[] { "restaurants", "hotels", "gas stations" });
Choices cities = new Choices(new string[] { "Seattle", "Boston", "Dallas" });
GrammarBuilder findServices = new GrammarBuilder("Find");
findServices.Append(services);
findServices.Append("near");
findServices.Append(cities);
// Create a Grammar object from the GrammarBuilder.
Grammar servicesGrammar = new Grammar(findServices);
servicesGrammar.Name = ("FindServices");
return servicesGrammar;
}
// Handle the AudioStateChanged event.
static void AudioStateChangedHandler(
object sender, AudioStateChangedEventArgs e)
{
Console.WriteLine("AudioStateChanged ({0}): {1}",
DateTime.Now.ToString("mm:ss.f"), e.AudioState);
}
// Handle the RecognizeCompleted event.
static void RecognizeCompletedHandler(
object sender, RecognizeCompletedEventArgs e)
{
Console.WriteLine("RecognizeCompleted ({0}):",
DateTime.Now.ToString("mm:ss.f"));
string resultText;
if (e.Result != null) { resultText = e.Result.Text; }
else { resultText = "<null>"; }
Console.WriteLine(
" BabbleTimeout: {0}; InitialSilenceTimeout: {1}; Result text: {2}",
e.BabbleTimeout, e.InitialSilenceTimeout, resultText);
if (e.Error != null)
{
Console.WriteLine(" Exception message: ", e.Error.Message);
}
// Start the next asynchronous recognition operation.
((SpeechRecognitionEngine)sender).RecognizeAsync(RecognizeMode.Single);
}
}
}
注解
每个语音识别器都有一种算法来区分静音和语音。 识别器会将与任何识别器加载和启用的语音识别语法的初始规则不匹配的任何非静音输入分类为背景噪音。 如果识别器在 babble 超时间隔内仅收到背景噪音和静音,则识别器将完成该识别操作。
对于异步识别操作,识别器引发 RecognizeCompleted 事件,其中 属性 RecognizeCompletedEventArgs.BabbleTimeout 为
true
, RecognizeCompletedEventArgs.Result 属性为null
。对于同步识别操作和仿真,识别器返回
null
,而不是有效的 RecognitionResult。
如果 babble 超时期限设置为 0,则识别器不会检查执行 babble 超时。 超时间隔可以是任何非负值。 默认值为 0 秒。