Exemplo n.º 1
0
 public SpeechHandler()
 {
     /*if (File.Exists(Environment.GetEnvironmentVariable("SystemRoot")+@"\Speech\Xvoice.dll")) {
      *  SAPI4Supported = true;
      * } else {
      *  SAPI4Supported = false;
      * }*/
     voice  = new SpeechLib.SpVoiceClass();
     tokens = voice.GetVoices("", "");
     sd     = new SpeakDelegate(voice.Speak);
 }
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
        /// <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);
            }
        }