Example #1
0
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (synth == null)
            {
                return;
            }

            if (!na.GetNeuronAt(0).Fired())
            {
                return;
            }

            ModuleUKSN nmKB = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));

            if (nmKB == null)
            {
                return;
            }
            List <Thing> words  = nmKB.GetChildren(nmKB.Labeled("Word"));
            bool         paused = true;

            //TODO: replace this direct access into the KB with synapses...then we can eliminate the storage of the words in the things values.
            foreach (Thing word in words)
            {
                if (nmKB.Fired(word, 2, false))
                {
                    paused         = false;
                    phraseToSpeak += " " + word.V.ToString();
                }
            }
            if (paused && phraseToSpeak != "")
            {
                ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn));
                if (msi != null)
                {
                    msi.PauseRecognition(); //if there is a recognizer active
                }
                synth.SpeakAsync(phraseToSpeak + ".");
                phraseToSpeak = "";
            }
        }
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (synth == null)
            {
                return;
            }

            bool paused = true;

            for (int i = 1; i < na.NeuronCount; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (n.Fired())
                {
                    if (n.Label.Length == 1)
                    {
                        phraseToSpeak += n.Label;
                        paused         = false;
                    }
                    if (n.Synapses.Count == 0)
                    {
                        //if a neuron fired and it has no connection, connect it to the knowledge store
                        //connection to KB
                        ModuleUKSN nmKB = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN));
                        if (nmKB != null)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = nmKB.Labeled("Phoneme").Children;
                            Thing        pn       = nmKB.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = nmKB.AddThing(label, new Thing[] { nmKB.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = nmKB.GetNeuron(pn);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n1.SetValue(1);
                            }
                        }
                    }
                }
            }
            if (phonemesToFire != "")
            {
                char c     = phonemesToFire[0];
                bool fired = false;
                for (int i = 0; i < na.NeuronCount; i++)
                {
                    Neuron n = na.GetNeuronAt(i);
                    if (n.Label == c.ToString())
                    {
                        n.SetValue(1);
                        fired = true;
                        break;
                    }
                }
                if (!fired)
                {
                    Utils.Noop();
                }
                phonemesToFire = phonemesToFire.Substring(1);
            }

            if (paused && phraseToSpeak != "")
            {
                if (dlg != null)
                {
                    ((ModuleSpeakPhonemesDlg)dlg).SetLabel(phraseToSpeak);
                }

                if (na.GetNeuronAt("Enable").Fired())
                {
                    ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn));
                    if (msi != null)
                    {
                        msi.PauseRecognition(); //if there is a recognizer active
                    }
                    //synth.SpeakAsync(phraseToSpeak + ".");
                    //phraseToSpeak = "";

                    PromptBuilder pb1 = new PromptBuilder();
                    if (typedIn)
                    {
                        pb1.StartVoice("Microsoft David Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Medium));
                    }
                    else
                    {
                        pb1.StartVoice("Microsoft Zira Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.ExtraSlow));
                    }

                    pb1.AppendTextWithPronunciation("not used", phraseToSpeak);
                    pb1.EndStyle();
                    pb1.EndVoice();
                    string x = pb1.ToXml();
                    Debug.WriteLine(debugString(phraseToSpeak));
                    //synth.Speak(pb1);
                    synth.SpeakAsync(pb1);
                }
                //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine
                phraseToSpeak = "";
                typedIn       = false;
            }
        }
Example #3
0
        public override void Fire()
        {
            Init();  //be sure to leave this here
            if (synth == null)
            {
                return;
            }

            if (GetNeuronValue("Cancel") == 1)
            {
                synth.SpeakAsyncCancelAll();
            }
            if (GetNeuronValue("Validate") == 1)
            {
                if (!validating)
                {
                    hitWords.Clear();
                    missWords.Clear();
                    missPhrase.Clear();
                    hit  = 0;
                    miss = 0;
                }
                validating = true;
            }
            else
            {
                if (validating)
                {
                    if (hit + miss == 0)
                    {
                        Debug.WriteLine("No Validation Data");
                    }
                    else
                    {
                        Debug.WriteLine("Validation: " + hit + " / " + miss + " = " + 100 * hit / (hit + miss));
                        Debug.WriteLine("Validation: " + hitWords.Count + " / " + missWords.Count + " = " + 100 * hitWords.Count / (hitWords.Count + missWords.Count));
                    }
                }
                validating = false;
            }

            bool paused = true;

            for (int i = 3; i < na.NeuronCount; i++)
            {
                Neuron n = na.GetNeuronAt(i);
                if (n.Fired())
                {
                    if (n.Label.Length == 1)
                    {
                        phraseToSpeak += n.Label;
                        paused         = false;
                    }
                    if (n.Synapses.Count == 0)
                    {
                        //connect it to the knowledge store
                        //connection to KB
                        //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS");
                        if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = UKS.Labeled("Phoneme").Children;
                            Thing        pn       = UKS.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = UKS.GetNeuron(pn);
                            Neuron n2 = UKS.GetNeuron(pn, false);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n1.SetValue(1);
                                n2.AddSynapse(n.Id, 1);
                            }
                        }
                    }
                }
            }
            if (phonemesToFire != "")
            {
                char c     = phonemesToFire[0];
                bool fired = false;
                if (c != ' ')
                {
                    for (int i = 0; i < na.NeuronCount; i++)
                    {
                        Neuron n = na.GetNeuronAt(i);
                        if (n.Label == c.ToString())
                        {
                            n.SetValue(1);
                            fired = true;
                            break;
                        }
                    }
                    if (!fired)
                    {
                        Neuron n = AddLabel(c.ToString());
                        //connect it to the knowledge store
                        //connection to KB
                        //ModuleUKS2 nmKB = (ModuleUKS2)FindModuleByName("AudibleUKS");
                        if (FindModuleByName("AudibleUKS") is ModuleUKS2 UKS)
                        {
                            string       label    = "pn" + n.Label;
                            List <Thing> phonemes = UKS.Labeled("Phoneme").Children;
                            Thing        pn       = UKS.Labeled(label, phonemes);
                            if (pn == null) //this should always be null
                            {
                                pn = UKS.AddThing(label, new Thing[] { UKS.Labeled("Phoneme") }, pn);
                            }
                            Neuron n1 = UKS.GetNeuron(pn);
                            Neuron n2 = UKS.GetNeuron(pn, false);
                            if (n1 != null)
                            {
                                n.AddSynapse(n1.Id, 1);
                                n2.AddSynapse(n.Id, 1);
                                n.SetValue(1);
                            }
                        }
                    }
                }
                phonemesToFire = phonemesToFire.Substring(1);
            }

            if (paused && phraseToSpeak != "")
            {
                if (dlg != null)
                {
                    ((ModuleSpeakPhonemes2Dlg)dlg).SetLabel(phraseToSpeak);
                }

                if (na.GetNeuronAt("Enable").Fired())
                {
                    ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn));
                    if (msi != null)
                    {
                        msi.PauseRecognition(); //if there is a recognizer active
                    }
                    //synth.SpeakAsync(phraseToSpeak + ".");
                    //phraseToSpeak = "";

                    PromptBuilder pb1 = new PromptBuilder();
                    if (typedIn)
                    {
                        pb1.StartVoice("Microsoft David Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Medium));
                    }
                    else
                    {
                        pb1.StartVoice("Microsoft Zira Desktop");
                        pb1.StartStyle(new PromptStyle(PromptRate.Slow));
                    }

                    pb1.AppendTextWithPronunciation("not used", phraseToSpeak.Trim());
                    pb1.EndStyle();
                    pb1.EndVoice();
                    string x = pb1.ToXml();
                    Debug.WriteLine(debugString(phraseToSpeak));
                    //synth.Speak(pb1);
                    synth.SpeakAsync(pb1);
                }
                //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine
                phraseToSpeak = "";
                typedIn       = false;
            }
        }
        public override void Fire()
        {
            Init();
            if (synth == null)
            {
                Initialize();
            }
            foreach (Neuron n in mv.Neurons)
            {
                if (n.LastCharge > .9)
                {
                    if (n.Label == "")
                    {
                        ModuleView msi = theNeuronArray.FindModuleByLabel("ModuleSpeechIn");
                        int        i   = mv.GetNeuronOffset(n);
                        if (msi != null)
                        {
                            mv.GetNeuronAt(i).Label = msi.GetNeuronAt(i).Label;
                        }
                    }
                    toSpeak    += prePend + n.Label + " ";
                    prePend     = "";
                    anyNewWords = 5;
                }
            }
            //builds up a phrase to be spoken, and passes it all at once to the synthisizer
            //this is much better than individual words
            anyNewWords--;
            if (anyNewWords == 0)
            {
                if (toSpeak != "")
                {
                    toSpeak = toSpeak.Trim();
                    if (toSpeak.IndexOf(' ') != -1)
                    {
                        toSpeak = toSpeak.Insert(toSpeak.Trim().LastIndexOf(' '), " " + insertAnd);
                    }
                    toSpeak = toSpeak + " " + postPend;
                    ModuleSpeechIn msi = (ModuleSpeechIn)FindModleu(typeof(ModuleSpeechIn));
                    if (msi != null)
                    {
                        msi.PauseRecognition(); //if there is a recognizer active
                    }
                    synth.SpeakAsync(toSpeak + ".");

                    //use this when we want to work with phonetics instead of words
                    //string[] words = toSpeak.Split(' ');
                    //PromptBuilder pb = new PromptBuilder();
                    //foreach (string p in words)
                    //    if (p != "")
                    //        pb.AppendTextWithPronunciation("NotUsed", p);
                    //pb.AppendText("."); //this improves the prosidy
                    //synth.SpeakAsync(pb);

                    toSpeak   = "";
                    prePend   = "";
                    postPend  = "";
                    insertAnd = "";
                }
            }
        }