|
Par
janulrich00001
Mise à jour : 06/11/2009
120 visites depuis 7 jours
, classé 515/777
|
).
.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | namespace DemoRecoVocale { partial class Form1 { /// <summary> /// Variable nécessaire au concepteur. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Nettoyage des ressources utilisées. /// </summary> /// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Code généré par le Concepteur Windows Form /// <summary> /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas /// le contenu de cette méthode avec l'éditeur de code. /// </summary> private void InitializeComponent() { this.recoTextLabel = new System.Windows.Forms.Label(); this.afficheLabel = new System.Windows.Forms.Label(); this.devineLabel = new System.Windows.Forms.Label(); this.recoText = new System.Windows.Forms.Label(); this.affiche = new System.Windows.Forms.Label(); this.devine = new System.Windows.Forms.Label(); this.exemplesLabel = new System.Windows.Forms.Label(); this.exemples = new System.Windows.Forms.TextBox(); this.commandLabel = new System.Windows.Forms.Label(); this.commandText = new System.Windows.Forms.Label(); this.helpLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // recoTextLabel // this.recoTextLabel.AutoSize = true; this.recoTextLabel.Location = new System.Drawing.Point(12, 32); this.recoTextLabel.Name = "recoTextLabel"; this.recoTextLabel.Size = new System.Drawing.Size(85, 13); this.recoTextLabel.TabIndex = 3; this.recoTextLabel.Text = "Texte reconnu : "; // // afficheLabel // this.afficheLabel.AutoSize = true; this.afficheLabel.Location = new System.Drawing.Point(12, 78); this.afficheLabel.Name = "afficheLabel"; this.afficheLabel.Size = new System.Drawing.Size(123, 13); this.afficheLabel.TabIndex = 5; this.afficheLabel.Text = "Vous souhaitez afficher :"; // // devineLabel // this.devineLabel.AutoSize = true; this.devineLabel.Location = new System.Drawing.Point(12, 101); this.devineLabel.Name = "devineLabel"; this.devineLabel.Size = new System.Drawing.Size(98, 13); this.devineLabel.TabIndex = 6; this.devineLabel.Text = "Vous avez deviné :"; // // recoText // this.recoText.AutoSize = true; this.recoText.Location = new System.Drawing.Point(103, 32); this.recoText.Name = "recoText"; this.recoText.Size = new System.Drawing.Size(27, 13); this.recoText.TabIndex = 7; this.recoText.Text = "vide"; // // affiche // this.affiche.AutoSize = true; this.affiche.Location = new System.Drawing.Point(141, 78); this.affiche.Name = "affiche"; this.affiche.Size = new System.Drawing.Size(27, 13); this.affiche.TabIndex = 8; this.affiche.Text = "vide"; // // devine // this.devine.AutoSize = true; this.devine.Location = new System.Drawing.Point(116, 101); this.devine.Name = "devine"; this.devine.Size = new System.Drawing.Size(27, 13); this.devine.TabIndex = 9; this.devine.Text = "vide"; // // exemplesLabel // this.exemplesLabel.AutoSize = true; this.exemplesLabel.Location = new System.Drawing.Point(12, 124); this.exemplesLabel.Name = "exemplesLabel"; this.exemplesLabel.Size = new System.Drawing.Size(146, 13); this.exemplesLabel.TabIndex = 10; this.exemplesLabel.Text = "Exemple de textes reconnus :"; // // exemples // this.exemples.Enabled = false; this.exemples.Location = new System.Drawing.Point(12, 144); this.exemples.Multiline = true; this.exemples.Name = "exemples"; this.exemples.Size = new System.Drawing.Size(384, 81); this.exemples.TabIndex = 11; this.exemples.Text = "Fin du travail\r\nC'est la lettre a\r\nC'est le chiffre 5\r\nAffiche la lettre p\r\nAffiche le chiffre 0"; // // commandLabel // this.commandLabel.AutoSize = true; this.commandLabel.Location = new System.Drawing.Point(12, 55); this.commandLabel.Name = "commandLabel"; this.commandLabel.Size = new System.Drawing.Size(66, 13); this.commandLabel.TabIndex = 12; this.commandLabel.Text = "Commande :"; // // commandText // this.commandText.AutoSize = true; this.commandText.Location = new System.Drawing.Point(84, 55); this.commandText.Name = "commandText"; this.commandText.Size = new System.Drawing.Size(27, 13); this.commandText.TabIndex = 13; this.commandText.Text = "vide"; // // helpLabel // this.helpLabel.AutoSize = true; this.helpLabel.Location = new System.Drawing.Point(12, 9); this.helpLabel.Name = "helpLabel"; this.helpLabel.Size = new System.Drawing.Size(309, 13); this.helpLabel.TabIndex = 14; this.helpLabel.Text = "Pressez la touche espace pour commencer la reconnaissance..."; // // MainWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(408, 237); this.Controls.Add(this.helpLabel); this.Controls.Add(this.commandText); this.Controls.Add(this.commandLabel); this.Controls.Add(this.exemples); this.Controls.Add(this.exemplesLabel); this.Controls.Add(this.devine); this.Controls.Add(this.affiche); this.Controls.Add(this.recoText); this.Controls.Add(this.devineLabel); this.Controls.Add(this.afficheLabel); this.Controls.Add(this.recoTextLabel); this.Name = "MainWindow"; this.Text = "Démonstrateur de reconnaissance vocale"; this.ResumeLayout(false); this.PerformLayout(); } #endregion public System.Windows.Forms.Label recoTextLabel; public System.Windows.Forms.Label afficheLabel; public System.Windows.Forms.Label devineLabel; public System.Windows.Forms.Label recoText; public System.Windows.Forms.Label affiche; public System.Windows.Forms.Label devine; public System.Windows.Forms.Label exemplesLabel; public System.Windows.Forms.TextBox exemples; public System.Windows.Forms.Label commandLabel; public System.Windows.Forms.Label commandText; public System.Windows.Forms.Label helpLabel; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Speech.Recognition.SrgsGrammar; using System.Speech.Recognition; using System.Windows.Forms; namespace DemoRecoVocale { class ASR { public SpeechRecognitionEngine ASREngine; private Label recoText; private Label commandText; private Label devine; private Label affiche; /// <summary> /// Constructeur de l'ASR (Automatic Speech Recognition) /// </summary> public ASR(ref Label recoText, ref Label commandText, ref Label devine, ref Label affiche) { //Les 4 labels dont le texte devra être changé //en fonction de ce qui est reconnu this.recoText = recoText; this.commandText = commandText; this.devine = devine; this.affiche = affiche; //Démarrage du moteur de reconnaissance vocale StartEngine(); } /// <summary> /// Démarrage du moteur de reconnaissance vocale et chargement du /// fichier de grammaire Grammaire.grxml /// </summary> private void StartEngine() { //Création d'un document de la norme SRGS à partir du fichier grxml SrgsDocument xmlGrammar = new SrgsDocument("Grammaire.grxml"); //Création d'une grammaire depuis le fichier de grammaire Grammar grammar = new Grammar(xmlGrammar); //Création de l'objet traitant la reconnaissance vocale ASREngine = new SpeechRecognitionEngine(); //Récupération du son du microphone ASREngine.SetInputToDefaultAudioDevice(); //Chargement de la grammaire ASREngine.LoadGrammar(grammar); //Link des fonctions a appeler en cas de reconnaissance d'un texte ASREngine.SpeechRecognized += ASREngine_SpeechRecognized; ASREngine.SpeechRecognitionRejected += ASREngine_SpeechRecognitionRejected; ASREngine.SpeechHypothesized += ASREngine_SpeechHypothesized; //Spécification du nombre maximum d'alternatives //Par exemple : b ou p ou d ou t, t ou d, i ou j, etc. //Utile pour les sons qui se ressemblent ASREngine.MaxAlternates = 4; } /// <summary> /// Méthode utilisée lorsque la reconnaissance vocale est en cours /// </summary> private void ASREngine_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e) { } /// <summary> /// Méthode utilisée lorsque la reconnaissance vocale a échoué /// </summary> private void ASREngine_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e) { } /// <summary> /// Méthode utilisée lorsque la reconnaissance vocale est réussi /// </summary> private void ASREngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Speech.Recognition; namespace DemoRecoVocale { public partial class Form1 : Form { private ASR ASR; public Form1() { InitializeComponent(); ASR = new ASR(ref this.recoText, ref this.commandText, ref this.devine, ref this.affiche); this.KeyPress += ActivateASR; } /// <summary> /// Active la reconnaissance vocale lors de la pression sur la touche /// espace pour une séquence de commande /// </summary> private void ActivateASR(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Space) { try { //Activation de la reconnaissance vocale pour une commande ASR.ASREngine.RecognizeAsync(RecognizeMode.Single); } catch { } } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?xml version="1.0" encoding="UTF-8"?> <grammar version="1.0" xml:lang="fr-FR" mode="voice" tag-format="semantics-ms/1.0" root="mouskie" xmlns="http://www.w3.org/2001/06/grammar"> <rule id="mouskie" scope="public"> <ruleref special="GARBAGE" /> <one-of> <item> a <tag>$.mouskie={}; $.mouskie._value="A";</tag> </item> <item> b <tag>$.mouskie={}; $.mouskie._value="B";</tag> </item> <item> Quitter <tag>$.mouskie={}; $.mouskie._value="QUIT";</tag> </item> <item> Fermer <tag>$.mouskie={}; $.mouskie._value="QUIT";</tag> </item> </one-of> <ruleref special="GARBAGE" /> </rule> </grammar> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <?xml version="1.0" encoding="UTF-8"?> <grammar version="1.0" xml:lang="fr-FR" mode="voice" tag-format="semantics-ms/1.0" root="mouskie" xmlns="http://www.w3.org/2001/06/grammar"> <rule id="mouskie" scope="public"> <ruleref special="GARBAGE" /> <one-of> <item> <one-of> <item>quitter</item> <item>fermer</item> </one-of> <tag>$.mouskie={}; $.mouskie._value="QUIT";</tag> </item> <item> <one-of> <item>affiche</item> <item>montre</item> <item>c'est</item> </one-of> <ruleref uri="#data_type" /> <tag>$.data_type=$data_type; $.mouskie={}; $.mouskie._value="LEARN";</tag> </item> </one-of> <ruleref special="GARBAGE" /> </rule> <rule id="data_type" scope="public"> <one-of> <item> la lettre<tag>$._value="LETTER";</tag> <ruleref uri="#letters" /> <tag>$.letters=$letters;</tag> </item> <item> le chiffre<tag>$._value="NUMBER";</tag> <ruleref uri="#numbers" /> <tag>$.numbers=$numbers;</tag> </item> </one-of> </rule> <rule id="letters" scope="public"> <one-of> <item>a</item> <item>b</item> </one-of> <tag>$._value = $recognized.text;</tag> </rule> <rule id="numbers" scope="public"> <one-of> <item>0</item> <item>1</item> </one-of> <tag>$._value = $recognized.text;</tag> </rule> </grammar> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /// <summary> /// Méthode utilisée lorsque la reconnaissance vocale est en cours /// </summary> private void ASREngine_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e) { recoText.Text = "Hypothèse : " + e.Result.Text; devine.Text = ""; affiche.Text = ""; commandText.Text = ""; } /// <summary> /// Méthode utilisée lorsque la reconnaissance vocale a échoué /// </summary> private void ASREngine_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e) { recoText.Text = "Reconnaissance impossible"; devine.Text = ""; affiche.Text = ""; commandText.Text = ""; } /// <summary> /// Méthode utilisée lorsque la reconnaissance vocale est réussi /// </summary> private void ASREngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { recoText.Text = e.Result.Text; devine.Text = ""; affiche.Text = ""; //Récupération de la commande de base utilisée (QUIT ou LEARN) string baseCommand = e.Result.Semantics["mouskie"].Value.ToString(); commandText.Text = baseCommand; if (baseCommand.Equals("QUIT")) Environment.Exit(0); else if (baseCommand.Equals("LEARN")) { string dataType = e.Result.Semantics["data_type"].Value.ToString(); commandText.Text += " " + dataType; string node = ""; //Choix du noeud en fonction de la commande trouvée if (dataType.Equals("NUMBER")) node = "numbers"; else if (dataType.Equals("LETTER")) node = "letters"; try { //Parcours des alternatives pour toutes les afficher for (int i = 0; i < e.Result.Alternates.ToArray().Length; i++) { string found = e.Result.Alternates.ToArray()[i].Semantics["data_type"][node].Value.ToString(); if (i != 0) affiche.Text += " ou "; affiche.Text += found; } } catch { } } } |
1 2 3 4 | //Spécification du nombre maximum d'alternatives //Par exemple : b ou p ou d ou t, t ou d, i ou j, etc. //Utile pour les sons qui se ressemblent ASREngine.MaxAlternates = 4; |