Example #1
0
        private void StartSpeech(AssignedVoice vb, string outputfile)
        {
            WinAvailableVoice wv = (WinAvailableVoice)vb.root;

            // Find the best audio format to use for this voice.
            System.Collections.ObjectModel.ReadOnlyCollection <SpeechAudioFormatInfo> formats =
                wv.winVoice.VoiceInfo.SupportedAudioFormats;

            format = formats.FirstOrDefault();

            if (format == null)
            {
                // The voice did not tell us its parameters, so we pick some.
                format = new SpeechAudioFormatInfo(
                    16000,      // Samples per second
                    AudioBitsPerSample.Sixteen,
                    AudioChannel.Mono);
            }

            // First set up to synthesize the message into a WAV file.
            mstream = new FileStream(outputfile, FileMode.Create, FileAccess.Write);

            syn.SetOutputToWaveStream(mstream);

            pb        = new PromptBuilder();
            mainStyle = new PromptStyle();
            //            mainStyle.Volume = promptVol;
            syn.SelectVoice(wv.winVoice.VoiceInfo.Name);
            pb.StartStyle(mainStyle);
        }
Example #2
0
        /// <summary>
        /// Get the list of available installed voices.
        /// </summary>
        /// <returns></returns>
        internal Dictionary <string, AvailableVoice> GetVoices()
        {
            Dictionary <string, AvailableVoice> names = new Dictionary <string, AvailableVoice>();
            bool AnnaPresent = false;
            bool SamPresent  = false;

            // Query the synthesizer for the voices installed.
            System.Collections.ObjectModel.ReadOnlyCollection <InstalledVoice> installed
                = syn.GetInstalledVoices();

            // Copy that information into a Dictionary we can update.
            foreach (InstalledVoice v in installed)
            {
                if (v.Enabled)
                {
                    bool skip = false;

                    // Check for additional information about this voice
                    string propString = voiceProperties?[v.VoiceInfo.Name].AsString();
                    if (propString != null)
                    {
                        // Properties are a series of blank-separated keywords
                        string[] props = propString.Split(' ');

                        foreach (string key in props)
                        {
                            switch (key)
                            {
                            case "ignore":
                                skip = true;
                                break;
                            }
                        }
                    }

                    // If this voice is not blocked add it to the list.
                    if (!skip)
                    {
                        WinAvailableVoice wav = new WinAvailableVoice(v);
                        names[v.VoiceInfo.Name] = (AvailableVoice)wav;
                    }
                }
                // Notice certain Microsoft voices.
                if (v.VoiceInfo.Name.Equals("Microsoft Anna"))
                {
                    AnnaPresent = true;
                }
                else if (v.VoiceInfo.Name.StartsWith("Microsoft "))
                {
                    SamPresent = true;
                }
            }

            // We have all the voices.  Remove the old Microsoft voices
            // if this is Vista or later.  This is because they do not work.
            if (AnnaPresent && SamPresent)
            {
                RemoveIf(names, "Microsoft Sam");
                RemoveIf(names, "Microsoft Mike");
                RemoveIf(names, "Microsoft Mary");
            }
            //says "Blah to Blah Blah the Blah Blah"
            RemoveIf(names, "SampleTTSVoice");

            return(names);
        }
Example #3
0
        /// <summary>
        /// Get the list of available installed voices.
        /// </summary>
        /// <returns></returns>
        internal Dictionary<string, AvailableVoice> GetVoices()
        {
            Dictionary<string, AvailableVoice> names = new Dictionary<string, AvailableVoice>();
            bool AnnaPresent = false;
            bool SamPresent = false;

            // Query the synthesizer for the voices installed.
            System.Collections.ObjectModel.ReadOnlyCollection<InstalledVoice> installed
                = syn.GetInstalledVoices();

            // Copy that information into a Dictionary we can update.
            foreach (InstalledVoice v in installed)
            {
                if (v.Enabled)
                {
                    bool skip = false;

                    // Check for additional information about this voice
                    if (voiceProperties != null)
                    {
                        string propString = voiceProperties[ v.VoiceInfo.Name ].AsString();
                        if (propString != null)
                        {
                            // Properties are a series of blank-separated keywords
                            string[] props = propString.Split(' ');

                            foreach (string key in props)
                            {
                                switch (key)
                                {
                                    case "ignore":
                                        skip = true;
                                        break;
                                }
                            }
                        }
                    }

                    // If this voice is not blocked add it to the list.
                    if (!skip)
                    {
                        WinAvailableVoice wav = new WinAvailableVoice(v);
                        names[v.VoiceInfo.Name] = (AvailableVoice)wav;
                    }
                }
                // Notice certain Microsoft voices.
                if (v.VoiceInfo.Name.Equals("Microsoft Anna")) AnnaPresent = true;
                else if (v.VoiceInfo.Name.StartsWith("Microsoft ")) SamPresent = true;
            }

            // We have all the voices.  Remove the old Microsoft voices
            // if this is Vista or later.  This is because they do not work.
            if (AnnaPresent && SamPresent)
            {
                RemoveIf(names, "Microsoft Sam");
                RemoveIf(names, "Microsoft Mike");
                RemoveIf(names, "Microsoft Mary");
            }
            //says "Blah to Blah Blah the Blah Blah"
            RemoveIf(names, "SampleTTSVoice");

            return names;
        }