private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            string text     = textBox.Text;
            string phonemes = ModuleSpeakPhonemes.GetPronunciationFromText(text);

            labelIn.Text = phonemes;
            ((ModuleSpeakPhonemes)ParentModule).FirePhonemes(phonemes);
        }
예제 #2
0
        private void HandleTalking()
        {
            //hack to prevent mixed phrases
            if (activeSequences.Count != 0)
            {
                return;
            }
            if (Fired(Labeled("Say"), immediateMemory))
            {
                List <Thing> phrasesToSay = AnyChildrenFired(Labeled("Phrase"));
                if (phrasesToSay.Count != 0)
                {
                    Thing newUtterance = AddThing("uu" + EventCount++, new Thing[] { Labeled("Utterance") }, null, null);
                    foreach (Link l in phrasesToSay[0].References)
                    {
                        //if the link is to a word, get the pronunciation of the word
                        if (l.T.Parents[0] == Labeled("Word"))
                        {
                            foreach (Link l1 in l.T.References)
                            {
                                newUtterance.AddReference(l1.T);
                            }
                            //newUtterance.AddReference(FindBestReference(l1.T));
                        }
                        else
                        {
                            //if the link is to a phoneme, add it
                            newUtterance.AddReference(l.T);
                        }
                    }
                    ModuleSpeakPhonemes nm = (ModuleSpeakPhonemes)FindModuleByType(typeof(ModuleSpeakPhonemes));

                    //what's the closest phrase we can say based on the phonemes we've learned to say so we can speak the phrase
                    foreach (Link l in newUtterance.References)
                    {
                        Thing t = l.T;
                        if (t.References.Count == 0)
                        {
                            //we've heard a phoneme we haven't learned how to speak
                            float bestDist = 100;
                            Thing closest  = null;
                            foreach (Thing t1 in Labeled("Phoneme").Children)
                            {
                                if (t1.References.Count > 0)
                                {
                                    char  p1   = t.Label[2];
                                    char  p2   = t1.Label[2];
                                    float dist = nm.PhonemeDistance(p1, p2);
                                    if (dist > -1 && dist < bestDist)
                                    {
                                        closest  = t1;
                                        bestDist = dist;
                                    }
                                }
                            }
                            Thing t2 = FindBestReference(closest);
                            if (t2 != null)
                            {
                                l.T = t2;
                            }
                        }
                        else
                        {
                            l.T = FindBestReference(t);
                        }
                    }
                    newUtterance.AddReference(Labeled("End"));
                    activeSequences.Add(newUtterance);
                }
            }
            if (Fired(Labeled("SayRnd"), 0))
            {
                //say a random utterance  (there is a hack to handle combiners which is needed to work with TTS)
                List <Thing> vowels     = Labeled("Vowel").Children;
                List <Thing> consonants = Labeled("Consonant").Children;
                if (consonants.Count == 0)
                {
                    return;
                }
                Thing consonant = consonants[rand.Next(consonants.Count - 2)];
                Thing vowel1    = vowels[rand.Next(vowels.Count)];
                Thing combiner  = Labeled("spk\u0361");

                int useCombiner = rand.Next(20);

                int repeatCount = rand.Next(3);
                repeatCount++;

                Thing newUtterance = AddThing("uu" + EventCount++, new Thing[] { Labeled("Utterance") }, null, null);
                for (int i = 0; i < repeatCount; i++)
                {
                    if (useCombiner < ModuleSpeakPhonemes.combiners.Count)
                    {
                        string s = ModuleSpeakPhonemes.combiners[useCombiner];
                        if (useCombiner == 0)
                        {
                            newUtterance.AddReference(Labeled("spk" + s[0]));
                            newUtterance.AddReference(combiner);
                            newUtterance.AddReference(Labeled("spk" + s[2]));
                            newUtterance.AddReference(vowel1);
                        }
                        else
                        {
                            newUtterance.AddReference(consonant);
                            newUtterance.AddReference(Labeled("spk" + s[0]));
                            newUtterance.AddReference(combiner);
                            newUtterance.AddReference(Labeled("spk" + s[2]));
                        }
                    }
                    else
                    {
                        newUtterance.AddReference(consonant);
                        newUtterance.AddReference(vowel1);
                    }
                }
                newUtterance.AddReference(Labeled("End"));
                Forget(Labeled("Utterance"));
                activeSequences.Add(newUtterance);
                Fire(newUtterance);
            }

            /*//TODO select a phrase to say
             * //things you can say are children of "Say".  They can contain sequences of words OR word-parameters which are affected by the Event
             * List<Thing> sayPhrases = Labeled("Say").Children;
             * Thing bestPhrase = null;
             * foreach (Thing phrase in sayPhrases)
             * {
             *  if (Fired(phrase, immediateMemory))
             *  {
             *      bestPhrase = phrase;
             *      activeSequences.Add(new Thing())
             *      {
             *          References = bestPhrase.References
             *      };
             *      return;
             *  }
             * }
             * if (bestPhrase == null)
             * {
             *  //no good phrase exists, try to create a new one
             *  //did anything fire we know words for?
             *  List<Thing> colors = Labeled("Color").Children; //change this to all sensory inputs
             *  foreach (Thing color in colors)
             *  {
             *      if (Fired(color, immediateMemory)) //a sensory thing fired
             *      {
             *          //do we have a word associated?
             *          Thing word = color.MostLikelyReference(Thing.ReferenceDirection.referenceBy, Labeled("Word"));
             *
             *          { Fire(word, false);
             *          };
             *          word = word;
             *      }
             *  }
             *
             *  //}
             *  return;
             * if (lastPhraseHeard != null)
             * {
             *  List<Link> similarPhrases = lastPhraseHeard.FindSimilar(Labeled("Phrase").Children, false, 5);
             *  if (similarPhrases.Count > 0)
             *  {
             *      activeSequence = new Thing()
             *      {
             *          References = new List<Link>(similarPhrases[0].T.References)
             *      };
             *  }
             *  else
             *  {
             *      List<Thing> allPhrases = Labeled("Say").Children;
             *      Thing randomPhrase = allPhrases[r.Next(0, allPhrases.Count)];
             *      {
             *          activeSequence = new Thing()
             *          {
             *              References = new List<Link>(randomPhrase.References)
             *          };
             *      }
             *  }
             * }
             */
        }