Je possède ce code dans mon projet C#:Comment réparer ce bug méchant de reconnaissance vocale?
public void startRecognition(string pName)
{
presentationName = pName;
if (WaveNative.waveInGetNumDevs() > 0)
{
string grammar = System.Environment.GetEnvironmentVariable("PUBLIC") + "\\SoundLog\\Presentations\\" + presentationName + "\\SpeechRecognition\\soundlog.cfg";
if (File.Exists(grammar))
{
File.Delete(grammar);
}
executeCommand();
/// Create an instance of SpSharedRecoContextClass which will be used
/// to interface with the incoming audio stream
recContext = new SpSharedRecoContextClass();
// Create the grammar object
recContext.CreateGrammar(1, out recGrammar);
//recContext.CreateGrammar(2, out recGrammar2);
// Set up dictation mode
//recGrammar2.SetDictationState(SpeechLib.SPRULESTATE.SPRS_ACTIVE);
//recGrammar2.SetGrammarState(SPGRAMMARSTATE.SPGS_ENABLED);
// Set appropriate grammar mode
if (File.Exists(grammar))
{
recGrammar.LoadCmdFromFile(grammar, SPLOADOPTIONS.SPLO_STATIC);
//recGrammar.SetDictationState(SpeechLib.SPRULESTATE.SPRS_INACTIVE);
recGrammar.SetGrammarState(SPGRAMMARSTATE.SPGS_ENABLED);
recGrammar.SetRuleIdState(0, SPRULESTATE.SPRS_ACTIVE);
}
/// Bind a callback to the recognition event which will be invoked
/// When a dictated phrase has been recognised.
recContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(handleRecognition);
// System.Windows.Forms.MessageBox.Show(recContext.ToString());
// gramática compilada
}
}
private static void handleRecognition(int StreamNumber,
object StreamPosition,
SpeechLib.SpeechRecognitionType RecognitionType,
SpeechLib.ISpeechRecoResult Result)
{
string temp = Result.PhraseInfo.GetText(0, -1, true);
_recognizedText = "";
// System.Windows.Forms.MessageBox.Show(temp);
// System.Windows.Forms.MessageBox.Show(recognizedWords.Count.ToString());
foreach (string word in recognizedWords)
{
if (temp.Contains(word))
{
// System.Windows.Forms.MessageBox.Show("yes");
_recognizedText = word;
}
}
}
Ce code génère une dll que je l'utilise dans une autre application.
Maintenant, le bug méchant: - lorsque je lance la méthode startRecognition au début de l'exécution de l'autre application, ce code fonctionne très bien. Mais quand je l'exécute quelque temps après le début, ce code fonctionne mais la méthode handleRecognition n'est jamais appelée. Je vois que les mots sont reconnus car ils apparaissent sur l'application Microsoft Speech Recognition, mais la méthode de gestionnaire n'est jamais appelée.
Savez-vous quel est le problème avec ce code?
REMARQUE: ce projet contient du code qui est toujours exécuté. Cela pourrait-il être le problème? Parce que l'autre code est en cours d'exécution, il ne lui permet pas de s'exécuter?
Il pourrait être tous les commentaires faisant le compilateur en colère et jouer des tours moyennes sur vous: P –
Je me demandais si vous avez essayé de faire le gestionnaire virtuel au lieu de statique? – code4life
Je vais essayer le truc virtuel plus tard :) –