Exemplo n.º 1
0
 private unsafe bool ConvertWithSpeechLib(string FileContent, string voiceName, int rate, string tempfile)
 {
     Console.WriteLine("Converting with: SpeechLib");
     try
     {
         //process with Interop.Speech
         var SpVoice = new SpeechLib.SpVoice();
         foreach (SpeechLib.SpObjectToken t in SpVoice.GetVoices("", ""))
         {
             string a = t.GetDescription(0);
             if (a.Contains(voiceName))
             {
                 SpVoice.Voice = t;
                 break;
             }
         }
         SpVoice.Rate = rate;
         var cpFileStream = new SpeechLib.SpFileStream();
         cpFileStream.Format.Type = SpeechLib.SpeechAudioFormatType.SAFT22kHz16BitMono;
         cpFileStream.Open(tempfile, SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite, false);
         SpVoice.AudioOutputStream = cpFileStream;
         SpVoice.Speak(FileContent, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
         SpVoice = null;
         cpFileStream.Close();
         cpFileStream = null;
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo 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 **/
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Speak text into a file.
        /// </summary>
        /// <param name="s">The text to be saved.</param>
        /// <param name="path">The file to save to.</param>
        /// <returns>false if a file write fails, true otherwise.</returns>
        public bool SpeakToFile(string s, string path)
        {
            try
            {
                SpeechLib.SpFileStream  stream = new SpeechLib.SpFileStream();
                SpeechLib.SpAudioFormat format = new SpeechLib.SpAudioFormat();

                format.Type = SpeechLib.SpeechAudioFormatType.SAFT32kHz16BitStereo;

                stream.Format = format;
                stream.Open(path, SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite, false);
                voice.AudioOutputStream = stream;

                voice.Speak(s, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
                stream.Close();
                voice.AudioOutputStream = null;
                return(true);
            } catch (Exception) {
                return(false);
            }
        }
 private unsafe bool ConvertWithSpeechLib(string FileContent,int rate,string tempfile)
 {
     Console.WriteLine("Converting with: SpeechLib");
     try
     {
         //process with Interop.Speech
         var SpVoice = new SpeechLib.SpVoice();
         foreach (SpeechLib.SpObjectToken t in SpVoice.GetVoices("", ""))
         {
             string a = t.GetDescription(0);
             if (a.IndexOf("Gergana") >= 0)
             {
                 SpVoice.Voice = t;
                 break;
             }
         }
         SpVoice.Rate = rate;
         var cpFileStream = new SpeechLib.SpFileStream();
         cpFileStream.Format.Type = SpeechLib.SpeechAudioFormatType.SAFT22kHz16BitMono;
         cpFileStream.Open(tempfile, SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite, false);
         SpVoice.AudioOutputStream = cpFileStream;
         SpVoice.Speak(FileContent, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
         SpVoice = null;
         cpFileStream.Close();
         cpFileStream = null;
         return true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return false;
     }
 }