Ejemplo n.º 1
0
        /// <summary>Short Summary of Program.WriteText</summary>
        /// <param name="inTextToSpeak">A String containing the text to speak</param>
        private bool WriteText(string inTextToSpeak)
        {
            try
            {
                SpeechLib.SpFileStream speakStream = new SpeechLib.SpFileStream();
                speakStream.Format.Type = SpeechLib.SpeechAudioFormatType.SAFT22kHz16BitMono;

                speakStream.Open(AppDomain.CurrentDomain.BaseDirectory + @"\" + outputFilename, SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite, false);
                voice.AllowAudioOutputFormatChangesOnNextSet = false;
                voice.AudioOutputStream = speakStream;

                SpeechLib.ISpeechObjectTokens tokens = voice.GetVoices("", "");
                voice.Voice = tokens.Item(0);

                voice.Rate = 8;
                //voice.EventInterests = SpeechLib.SpeechVoiceEvents.SVESentenceBoundary;
                //voice.Sentence += new SpeechLib._ISpeechVoiceEvents_SentenceEventHandler(sentence_Event);

                speakFlag = SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault
                            | SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync
                            | SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak
                            //| SpeechLib.SpeechVoiceSpeakFlags.SVSFNLPSpeakPunc
                            //| SpeechLib.SpeechVoiceSpeakFlags.SVSFIsXML;
                ;

                voice.Speak(inTextToSpeak, speakFlag);
                voice.WaitUntilDone(Timeout.Infinite);

                speakStream.Close();
                speakStream = null;

                SpeechLib.ISpeechObjectTokens Atokens = voice.GetAudioOutputs(null, "");
                voice.AudioOutput = Atokens.Item(0);
                voice.AudioOutputStream.Format.Type = SpeechLib.SpeechAudioFormatType.SAFT22kHz16BitMono;
                voice.AudioOutputStream             = voice.AudioOutputStream;

                voice.Speak("Speech has been completly written to the file, " + outputFilename, speakFlag);
                voice.WaitUntilDone(Timeout.Infinite);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public TextToSpeech5(ISpeechModule speechModule)
        {
            // Do Component
            _speechModule = speechModule;
            _speechModule.TextToSpeech = this;
            _speechModule.Add(this);

            // Initialize Voice
            spVoice = new SpeechLib.SpVoice();

            spVoice.Viseme += SpVoice_Viseme;
            spVoice.Word   += SpVoice_Word;

            _phonemes = Speech.Phonemes.GetPhonemesSapi5();

            // From VB
            speakFlags = SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync
                         & SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak
                         & SpeechLib.SpeechVoiceSpeakFlags.SVSFIsXML;

            // Get Voices
            var voices = spVoice.GetVoices();

            foreach (SpeechLib.SpObjectToken v in voices)
            {
                string vname = null;
                vname = v.GetDescription();

                if (vname != null)
                {
                    _voices.Add(new Tts5Voice {
                        Gender = Gender.Other, Name = vname, VoiceObject = v
                    });
                }
            }

            //// Turn off Listener events
            //paused = false;
            //speaking = false;
            //this._speechModule.IsSpeaking = false;

            // Write Debug Log
            speechModule.LanguageModel.AI.Engine.Debugger.Log(DebuggerLogLevel.Log, Resources.TTS_Initialized);
        }
Ejemplo n.º 3
0
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            System.String path = System.IO.Path.GetDirectoryName(Context.Parameters["assemblypath"]);

            SpeechLib.SpeechVoiceSpeakFlags SpFlags =
                SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechLib.SpeechVoiceSpeakFlags.SVSFIsXML;
            SpeechLib.SpVoice speech = new SpeechLib.SpVoice();
            SpeechLib.SpeechStreamFileMode SpFileMode   = SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite;
            SpeechLib.SpFileStream         SpFileStream = new SpeechLib.SpFileStream();
            SpFileStream.Open(System.String.Concat(path, "\\Welcome Message.wav"), SpFileMode, false);
            speech.AudioOutputStream = SpFileStream;
            System.String introText =
                "Thank-you for installing the play-out server from the broadcasting and presenting suite. " +
                "By default the server accepts connections on port 1350, the default login is username: admin and password: 1234. " +
                "The version of the server service is " +
                System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ". " +
                "The version of the server components is " +
                System.Reflection.Assembly.GetAssembly(typeof(BAPSServerAssembly.Utility)).GetName().Version
                .ToString() + ". " +
                "Please refer to the documentation included with this application for further assistance.";
            speech.Speak(introText, SpFlags);
            speech.WaitUntilDone(System.Threading.Timeout.Infinite);
            SpFileStream.Close();

            System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
            xd.Load(System.String.Concat("file://", path, "\\serverstate.xml"));
            System.Xml.XmlNode xn = xd.SelectSingleNode("/bapsserverstate/channel/playlist/entry[2]/filename");
            xn.FirstChild.Value = System.String.Concat(path, "\\Welcome Message.wav");
            xn = xd.SelectSingleNode("/bapsserverstate/channel/playlist/entry[1]/textdata");
            xn.FirstChild.Value = introText;
            xd.Save(System.String.Concat(path, "\\serverstate.xml"));
            try
            {
                bapsServiceController.Start();
            }
            catch (System.Exception)
            {
                /** ignore it **/
            }
        }
Ejemplo n.º 4
0
        /// <summary>Short Summary of Program.InitSpeech</summary>
        private bool InitSpeech()
        {
            try
            {
                voice = new SpeechLib.SpVoice();

                SpeechLib.ISpeechObjectTokens tokens = voice.GetVoices("", "");
                voice.Voice = tokens.Item(0);
                SpeechLib.ISpeechObjectTokens Atokens = voice.GetAudioOutputs(null, "");
                voice.AudioOutput = Atokens.Item(0);

                voice.AudioOutputStream.Format.Type = SpeechLib.SpeechAudioFormatType.SAFT22kHz16BitMono;
                voice.AudioOutputStream             = voice.AudioOutputStream;
                voice.Rate = 8;
                voice.AllowAudioOutputFormatChangesOnNextSet = false;
                //voice.EventInterests = SpeechLib.SpeechVoiceEvents.SVESentenceBoundary;
                //voice.Sentence += new SpeechLib._ISpeechVoiceEvents_SentenceEventHandler(sentence_Event);

                speakFlag = SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault
                            | SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync
                            | SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak
                            //| SpeechLib.SpeechVoiceSpeakFlags.SVSFNLPSpeakPunc
                            //| SpeechLib.SpeechVoiceSpeakFlags.SVSFIsXML;
                ;
                //int rate = voice.Rate;
                //SpeechLib.SpObjectToken audio = voice.AudioOutput;
                //int volume = voice.Volume;
                //SpeechLib.SpObjectToken thevoice = voice.Voice;
                //SpeechLib.ISpeechObjectToken token;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }