Ejemplo n.º 1
0
        //This method exists so that it can be easily called and return safely if the speech prereqs aren't installed.
        //We isolate the try/catch inside this class, and don't impose the need on the caller.
        public static SpeechRecognizer Create()
        {
            SpeechRecognizer recognizer = null;

            try
            {
                recognizer = new SpeechRecognizer();
            }
            catch (Exception)
            {
                //speech prereq isn't installed. a null recognizer will be handled properly by the app.
            }
            return recognizer;
        }
Ejemplo n.º 2
0
 void recognizer_SaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
 {
     FlyingText.NewFlyingText(screenRect.Width / 30, new Point(screenRect.Width / 2, screenRect.Height / 2), e.Matched);
     switch (e.Verb)
     {
         case SpeechRecognizer.Verbs.Pause:
             fallingThings.SetDropRate(0);
             fallingThings.SetGravity(0);
             break;
         case SpeechRecognizer.Verbs.Resume:
             fallingThings.SetDropRate(dropRate);
             fallingThings.SetGravity(dropGravity);
             break;
         case SpeechRecognizer.Verbs.Reset:
             dropRate = DefaultDropRate;
             dropSize = DefaultDropSize;
             dropGravity = DefaultDropGravity;
             fallingThings.SetPolies(PolyType.All);
             fallingThings.SetDropRate(dropRate);
             fallingThings.SetGravity(dropGravity);
             fallingThings.SetSize(dropSize);
             fallingThings.SetShapesColor(Color.FromRgb(0, 0, 0), true);
             fallingThings.Reset();
             break;
         case SpeechRecognizer.Verbs.DoShapes:
             fallingThings.SetPolies(e.Shape);
             break;
         case SpeechRecognizer.Verbs.RandomColors:
             fallingThings.SetShapesColor(Color.FromRgb(0, 0, 0), true);
             break;
         case SpeechRecognizer.Verbs.Colorize:
             fallingThings.SetShapesColor(e.RGBColor, false);
             break;
         case SpeechRecognizer.Verbs.ShapesAndColors:
             fallingThings.SetPolies(e.Shape);
             fallingThings.SetShapesColor(e.RGBColor, false);
             break;
         case SpeechRecognizer.Verbs.More:
             dropRate *= 1.5;
             fallingThings.SetDropRate(dropRate);
             break;
         case SpeechRecognizer.Verbs.Fewer:
             dropRate /= 1.5;
             fallingThings.SetDropRate(dropRate);
             break;
         case SpeechRecognizer.Verbs.Bigger:
             dropSize *= 1.5;
             if (dropSize > MaxShapeSize)
                 dropSize = MaxShapeSize;
             fallingThings.SetSize(dropSize);
             break;
         case SpeechRecognizer.Verbs.Biggest:
             dropSize = MaxShapeSize;
             fallingThings.SetSize(dropSize);
             break;
         case SpeechRecognizer.Verbs.Smaller:
             dropSize /= 1.5;
             if (dropSize < MinShapeSize)
                 dropSize = MinShapeSize;
             fallingThings.SetSize(dropSize);
             break;
         case SpeechRecognizer.Verbs.Smallest:
             dropSize = MinShapeSize;
             fallingThings.SetSize(dropSize);
             break;
         case SpeechRecognizer.Verbs.Faster:
             dropGravity *= 1.25;
             if (dropGravity > 4.0)
                 dropGravity = 4.0;
             fallingThings.SetGravity(dropGravity);
             break;
         case SpeechRecognizer.Verbs.Slower:
             dropGravity /= 1.25;
             if (dropGravity < 0.25)
                 dropGravity = 0.25;
             fallingThings.SetGravity(dropGravity);
             break;
     }
 }