SpeechRecognizer.SpeechRecognitionRejected SpeechRecognizer.SpeechRecognitionRejected SpeechRecognizer.SpeechRecognitionRejected SpeechRecognizer.SpeechRecognitionRejected Event

Definizione

Viene generato quando il riconoscimento riceve un input che non corrisponde ad alcuna grammatica di riconoscimento vocale caricata.Occurs when the recognizer receives input that does not match any of the speech recognition grammars it has loaded.

public:
 event EventHandler<System::Speech::Recognition::SpeechRecognitionRejectedEventArgs ^> ^ SpeechRecognitionRejected;
public event EventHandler<System.Speech.Recognition.SpeechRecognitionRejectedEventArgs> SpeechRecognitionRejected;
member this.SpeechRecognitionRejected : EventHandler<System.Speech.Recognition.SpeechRecognitionRejectedEventArgs> 
Public Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs) 

Esempi

Nell'esempio seguente vengono riconosciute frasi come "visualizzare l'elenco degli artisti nella categoria jazz" o "visualizzare gli album gospel".The following example recognizes phrases such as "Display the list of artists in the jazz category" or "Display albums gospel". Nell'esempio viene usato un gestore per SpeechRecognitionRejected l'evento per visualizzare una notifica nella console quando non è possibile associare l'input vocale al contenuto della grammatica con una confidenza sufficiente per produrre un riconoscimento riuscito.The example uses a handler for the SpeechRecognitionRejected event to display a notification in the console when the speech input cannot be matched to the contents of the grammar with sufficient confidence to produce a successful recognition.

using System;  
using System.Speech.Recognition;  

namespace SampleRecognition  
{  
  class Program  
  {  
    static void Main(string[] args)  

    // Initialize a shared speech recognition engine.  
    {  
      using (SpeechRecognizer recognizer =  
         new SpeechRecognizer())  
      {  

        // Create a grammar.  
        //  Create lists of alternative choices.  
        Choices listTypes = new Choices(new string[] { "albums", "artists" });  
        Choices genres = new Choices(new string[] {   
          "blues", "classical", "gospel", "jazz", "rock" });  

        //  Create a GrammarBuilder object and assemble the grammar components.  
        GrammarBuilder mediaMenu = new GrammarBuilder("Display");  
        mediaMenu.Append("the list of", 0, 1);  
        mediaMenu.Append(listTypes);  
        mediaMenu.Append("in the", 0, 1);  
        mediaMenu.Append(genres);  
        mediaMenu.Append("category", 0, 1);  

        //  Build a Grammar object from the GrammarBuilder.  
        Grammar mediaMenuGrammar = new Grammar(mediaMenu);  
        mediaMenuGrammar.Name = "Media Chooser";  

        // Attach event handlers.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.SpeechRecognitionRejected +=   
          new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);  

        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(mediaMenuGrammar);  

        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  

    // Handle the SpeechRecognitionRejected event.  
    static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine("Speech input was rejected.");  
    }  

    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized: " + e.Result.Text);  
    }  
  }  
}  

Commenti

Il riconoscimento condiviso genera questo evento se determina che l'input non corrisponde a un grado di attendibilità sufficiente per le grammatiche di riconoscimento vocale caricate.The shared recognizer raises this event if it determines that input does not match with sufficient confidence any of the loaded speech recognition grammars. La Result proprietà RecognitionResult di contiene l'oggetto rifiutato. SpeechRecognitionRejectedEventArgsThe Result property of the SpeechRecognitionRejectedEventArgs contains the rejected RecognitionResult object.

Le soglie di confidenza per il riconoscimento condiviso gestito SpeechRecognizerda sono associate a un profilo utente e archiviate nel registro di sistema di Windows.Confidence thresholds for the shared recognizer, managed by SpeechRecognizer, are associated with a user profile and stored in the Windows registry. Le applicazioni non devono scrivere modifiche al registro di sistema per le proprietà del riconoscimento condiviso.Applications should not write changes to the registry for the properties of the shared recognizer.

Quando si crea un delegato per un SpeechRecognitionRejected evento, si identifica il metodo che gestirà l'evento.When you create a delegate for a SpeechRecognitionRejected event, you identify the method that will handle the event. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato.To associate the event with your event handler, add an instance of the delegate to the event. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non venga rimosso il delegato.The event handler is called whenever the event occurs, unless you remove the delegate. Per ulteriori informazioni sui delegati del gestore eventi, vedere eventi e delegati.For more information about event-handler delegates, see Events and Delegates.

Si applica a

Vedi anche