Пример #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);
     }
 }
Пример #2
0
    /// <summary>
    /// Initializes the class
    /// </summary>
    private void ClassInit()
    {
        m_Index     = 0;
        m_EventSink = null;

        speechVoice = new SpeechLib.SpVoice();
        speechVoice.EventInterests = SpeechLib.SpeechVoiceEvents.SVEEndInputStream | SpeechLib.SpeechVoiceEvents.SVEStartInputStream;

        speechMMSysAudioOut = new SpeechLib.SpMMAudioOut();
    }
Пример #3
0
 private void tsbToSpeech_Click(object sender, EventArgs e)
 {
     try
     {
         SpeechLib.SpVoice sp = new SpeechLib.SpVoice();
         sp.Speak(lbxWyrazy.SelectedValue.ToString(), SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.Message);
     }
 }
Пример #4
0
 /// <summary>
 /// 文字转语音
 /// </summary>
 /// <param name="message">文字信息</param>
 /// <param name="speekType">声音类别 0:单词男声Sam,1:单词男声Mike,2:单词女声Mary,3:中文发音,如果是英文,就依单词字母一个一个发音</param>
 public static void Speek(string message)
 {
     try
     {
         //引入COM组件:Microsoft speech object Library
         SpeechLib.SpVoice voice = new SpeechLib.SpVoice();
         voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
         voice.Speak(message, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync);
     }
     catch (Exception ex)
     {
     }
 }
Пример #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.IO.StreamReader fsr = new System.IO.StreamReader(new System.IO.FileStream(".\\dict.txt", System.IO.FileMode.Open));
            while (!fsr.EndOfStream)
            {
                String str = fsr.ReadLine();

                Word w = new Word(str);
                wordList.addWord(w);
                comboBox1.Items.Add(w.getWord().ToLower());
                comboBox1.SelectedIndex = 0;
            }
            reader = new SpeechLib.SpVoice();
        }
Пример #6
0
 private static void initSpeechVoice()
 {
     if (speechVoice == null)
     {
         speechVoice        = new SpeechLib.SpVoice();
         speechVoice.Volume = volume;
         speechVoice.SynchronousSpeakTimeout = 30;
         speechVoice.Rate = -1;
     }
     else
     {
         speechVoice.Volume = volume;
     }
 }
Пример #7
0
        private void Speak(string s)
        {
#if USE_SYSTEM_SPEECH
            System.Speech.Synthesis.SpeechSynthesizer tts = new System.Speech.Synthesis.SpeechSynthesizer();
            tts.SpeakAsync(textTime.Text);
#else
            try
            {
                SpeechLib.SpVoice voice = new SpeechLib.SpVoice();
                voice.Speak(s, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechLib.SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
            }
            catch (Exception err)
            {
                System.Diagnostics.EventLog.WriteEntry("Clock", "Failed to use SAPI5 through COM: " + err.Message);
            }
#endif
        }
Пример #8
0
        private void frmReminder_Load(object sender, EventArgs e)
        {
#if USE_SYSTEM_SPEECH
            tts = new System.Speech.Synthesis.SpeechSynthesizer();
            tts.SpeakCompleted += new EventHandler <System.Speech.Synthesis.SpeakCompletedEventArgs>(tts_SpeakCompleted);
#else
            try
            {
                voice            = new SpeechLib.SpVoice();
                voice.EndStream += new SpeechLib._ISpeechVoiceEvents_EndStreamEventHandler(voice_EndStream);
            }
            catch (Exception err)
            {
                System.Diagnostics.EventLog.WriteEntry("Clock frmReminder_Load", "Error using SAPI5 through COM: " + err.Message);
            }
#endif
        }
Пример #9
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);
        }
Пример #10
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 **/
            }
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        public SoundSpeaker()
        {
            Type   comType = Type.GetTypeFromProgID("SAPI.SpVoice");
            object rVar    = null;

            if (comType != null)
            {
                rVar    = System.Activator.CreateInstance(comType);
                SpVoice = rVar as SpeechLib.SpVoice;
            }

            /*设定语音
             * if (SpVoice!=null)
             * {
             * var voices = SpVoice.GetVoices();
             * var voice = voices.Item(0);
             * var name = voice.GetDescription();
             * var to = voice as SpeechLib.SpObjectToken;
             * SpVoice.Voice = to;
             * }
             * //*/
        }
Пример #12
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);
            }
        }
 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;
     }
 }
Пример #14
0
 private TTSSpeech()
 {
     _Voice = new SpeechLib.SpVoice();
 }