public override int runCommand(XdmNode node)
        {
            Speech sp = Speech.instance;
            //SpeechSynthesizer sp = new SpeechSynthesizer();

            /*
             * Store values
             */
            SpObjectToken prevVoice  = sp.speech.Voice;
            int           prevVolume = sp.speech.Volume;
            int           prevRate   = sp.speech.Rate;


            foreach (string key in getProperties().Keys)
            {
                string value = getProperties()[key];
                switch (key)
                {
                case "voice":
                    ISpeechObjectToken voice = sp.getVoice(value);
                    if (voice != null)
                    {
                        sp.speech.Voice = (SpObjectToken)voice;
                    }
                    break;

                case "volume":
                    int volume = Int32.Parse(value);
                    if (volume > -1 && volume < 101)
                    {
                        sp.speech.Volume = volume;
                    }
                    break;

                case "rate":
                    int rate = Int32.Parse(value);
                    if (rate > -11 && rate < 11)
                    {
                        sp.speech.Rate = rate;
                    }
                    break;
                }
            }
            runChilds(node);
            if (commands.Count > 0)
            {
                sp.speech.Voice  = prevVoice;
                sp.speech.Volume = prevVolume;
                sp.speech.Rate   = prevRate;
            }
            return(0);
        }
Beispiel #2
0
        /// <summary>
        /// cTor.
        /// </summary>
        /// <param name="tok"></param>
        internal Recognizer(ISpeechObjectToken tok)
        {
#if DEBUG
            logfile.Log("Recognizer() cTor");
#endif
            Tok = tok;

            Id = Tok.Id;
            int pos = Id.LastIndexOf('\\');
            Id = Id.Substring(pos + 1);
#if DEBUG
            logfile.Log(". Id= " + Id);
#endif
            Label = Tok.GetDescription();
#if DEBUG
            logfile.Log(". Label= " + Label);
#endif
            Langids = "n/a";

            string keyid = @"SOFTWARE\Microsoft\Speech\Recognizers\Tokens\"
                           + Id
                           + @"\Attributes";

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyid))
            {
                if (key != null)
                {
                    Object o = key.GetValue("Language");
                    if (o != null)
                    {
                        string val = o as String;

                        Langids = String.Empty;

                        string[] langids = val.Split(';');
                        foreach (var langid in langids)
                        {
                            if (Langids != String.Empty)
                            {
                                Langids += " | ";
                            }
                            Langids += Int32.Parse(langid, NumberStyles.HexNumber).ToString();
                        }
                    }
                }
            }
#if DEBUG
            logfile.Log(". Langids= " + Langids);
#endif
        }
Beispiel #3
0
        public ISpeechObjectToken getVoice(string name)
        {
            ISpeechObjectToken result = null;

            foreach (ISpeechObjectToken voice in voices)
            {
                if (voice.GetDescription().Equals(name))
                {
                    result = voice;
                    break;
                }
            }

            return(result);
        }