SpeechUI.SendTextFeedback(RecognitionResult, String, Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将状态和描述性文本发送到语音平台用户界面,了解识别操作的状态。
public:
static bool SendTextFeedback(System::Speech::Recognition::RecognitionResult ^ result, System::String ^ feedback, bool isSuccessfulAction);
public static bool SendTextFeedback(System.Speech.Recognition.RecognitionResult result, string feedback, bool isSuccessfulAction);
static member SendTextFeedback : System.Speech.Recognition.RecognitionResult * string * bool -> bool
Public Shared Function SendTextFeedback (result As RecognitionResult, feedback As String, isSuccessfulAction As Boolean) As Boolean
参数
- result
- RecognitionResult
有效 RecognitionResult 实例。
- feedback
- String
String一个包含有关生成该操作的识别操作的RecognitionResultresult注释。
- isSuccessfulAction
- Boolean
指示 bool 应用程序是否认为识别操作成功。
返回
true 如果提供给方法的信息(Feedback且 isSuccessfulAction)已成功提供给语音平台用户界面,并且 false 操作失败,则为 。
示例
以下示例是事件的 SpeechRecognized 处理程序。 此事件由 Grammar 设计为处理表单的密码输入“我的密码...”形式的事件使用。
如果密码不存在或无效,则 SendTextFeedback 用于将错误信息发送到语音平台用户界面。
grammar.SpeechRecognized +=
delegate(object sender, SpeechRecognizedEventArgs eventArgs)
{
SemanticValue semantics = eventArgs.Result.Semantics;
RecognitionResult result=eventArgs.Result;
if (!semantics.ContainsKey("Password"))
{
SpeechUI.SendTextFeedback(eventArgs.Result, "No Password Provided", false);
}
else
{
RecognizedAudio pwdAudio = result.GetAudioForWordRange(
result.Words[3],
result.Words[result.Words.Count - 1]);
MemoryStream pwdMemoryStream = new MemoryStream();
pwdAudio.WriteToAudioStream(pwdMemoryStream);
if (!IsValidPwd(pwdMemoryStream))
{
string badPwd = System.IO.Path.GetTempPath() + "BadPwd" +
(new Random()).Next().ToString() + ".wav";
FileStream waveStream = new FileStream(badPwd, FileMode.Create);
pwdAudio.WriteToWaveStream(waveStream);
waveStream.Flush();
waveStream.Close();
SpeechUI.SendTextFeedback(eventArgs.Result, "Invalid Password", false);
}
}
};
注解
SendTextFeedback 可用于指示识别操作未能满足某些条件,即使已识别输入。
例如,验证安全代码信息,其中输入已完全识别,但验证信息不正确。