Пример #1
0
        bool Init()
        {
            if (g_VoiceSpeeach == null)
            {//nullなら初期化する.
                try
                {
                    //合成音声エンジンを初期化する.
                    g_VoiceSpeeach      = new SpeechLib.SpVoice();
                    g_VoiceSpeeach.Rate = 0;

                    if (Program.ROM.RomInfo.is_multibyte())
                    {
                        g_ShortLength = 10;
                    }
                    else
                    {
                        g_ShortLength = 20;
                    }
                }
                catch (Exception ee)
                {
                    R.ShowStopError(ee.ToString());
                    return(false);
                }
            }
            return(true);
        }
 public string getoutput(string Input)
 {
     SpeechLib.SpVoice synth = new SpeechLib.SpVoice();
     Request request = new Request(Input, user, bot);
     Result result = bot.Chat(request);
     synth.Speak(result.Output, (SpeechVoiceSpeakFlags.SVSFDefault));
     return(result.Output);
 }
Пример #3
0
 public static void Stop()
 {
     if (g_VoiceSpeeach == null)
     {
         return;
     }
     g_VoiceSpeeach.Speak(" ", SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
     g_VoiceSpeeach = null;
 }
Пример #4
0
        /// <summary>
        /// Convert xml to WAV bytes. WAV won't have the header, so you have to add it separatelly.
        /// </summary>
        byte[] ConvertSapiXmlToWav(string xml, int sampleRate, int bitsPerSample, int channelCount)
        {
            SpeechAudioFormatType t = SpeechAudioFormatType.SAFT48kHz16BitMono;

            switch (channelCount)
            {
            case 1:                     // Mono
                switch (sampleRate)
                {
                case 11025: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT11kHz8BitMono : SpeechAudioFormatType.SAFT11kHz16BitMono; break;

                case 22050: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT22kHz8BitMono : SpeechAudioFormatType.SAFT22kHz16BitMono; break;

                case 44100: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT44kHz8BitMono : SpeechAudioFormatType.SAFT44kHz16BitMono; break;

                case 48000: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT48kHz8BitMono : SpeechAudioFormatType.SAFT48kHz16BitMono; break;
                }
                break;

            case 2:                     // Stereo
                switch (sampleRate)
                {
                case 11025: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT11kHz8BitStereo : SpeechAudioFormatType.SAFT11kHz16BitStereo; break;

                case 22050: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT22kHz8BitStereo : SpeechAudioFormatType.SAFT22kHz16BitStereo; break;

                case 44100: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT44kHz8BitStereo : SpeechAudioFormatType.SAFT44kHz16BitStereo; break;

                case 48000: t = bitsPerSample == 8 ? SpeechAudioFormatType.SAFT48kHz8BitStereo : SpeechAudioFormatType.SAFT48kHz16BitStereo; break;
                }
                break;
            }
            byte[] bytes;
            var    voice = new SpeechLib.SpVoice();
            // Write into memory.
            var stream = new SpeechLib.SpMemoryStream();

            stream.Format.Type      = t;
            voice.AudioOutputStream = stream;
            try
            {
                voice.Speak(xml, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
            }
            catch (Exception ex)
            {
                ex.Data.Add("Voice", "voiceName");
                LastException = ex;
                return(null);
            }
            var spStream = (SpMemoryStream)voice.AudioOutputStream;

            spStream.Seek(0, SpeechStreamSeekPositionType.SSSPTRelativeToStart);
            bytes = (byte[])(object)spStream.GetData();
            return(bytes);
        }
Пример #5
0
        private bool initVoiceSpeech()
        {
            // talker http://d.hatena.ne.jp/rti7743/20111215/1323965483 からコピペ
            //合成音声エンジンを初期化する.
            try
            {
                this.VoiceSpeech = new SpeechLib.SpVoice();
            }
            catch (COMException)
            {
                MessageBox.Show(
                    "合成音声が利用できません。" + Environment.NewLine
                    + "Microsoft Speech Platform - Runtime (Version 11) をインストールしてください。"
                    );
                return(false);
            }
            //合成音声エンジンで日本語を話す人を探す。(やらなくても動作はするけど、念のため)
            Boolean hit = false;

            foreach (SpObjectToken voiceperson in this.VoiceSpeech.GetVoices())
            {
                string language = voiceperson.GetAttribute("Language");
                if (language == "411")
                {                                         //日本語を話す人だ!
                    this.VoiceSpeech.Voice = voiceperson; //君に読みあげて欲しい
                    hit = true;
                    break;
                }
            }
            if (!hit)
            {
                MessageBox.Show("日本語合成音声が利用できません。\r\n日本語合成音声 MSSpeech_TTS_ja-JP_Haruka をインストールしてください。\r\n");
                this.VoiceSpeech = null;
                return(false);
            }
            boolTalkable = true;
            // event handler
            this.VoiceSpeech.EventInterests = SpeechVoiceEvents.SVEEndInputStream;                                  // 終了時イベントを発生させるようになる
            this.VoiceSpeech.EndStream     += new _ISpeechVoiceEvents_EndStreamEventHandler(VoiceSpeech_EndStream); // イベントハンドラ登録
            return(true);
        }
Пример #6
0
        /// <summary>
        /// 语音报警延迟线程
        /// </summary>
        /// <param name="text"></param>
        void SpeekText(string text)
        {
            SpeechLib.SpeechVoiceSpeakFlags SpFlags =

                SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync;

            SpeechLib.SpVoice Voice = new SpeechLib.SpVoice();


            try
            {
                Voice.Speak(text, SpFlags);
            }
            catch (Exception)
            {
                //报警
                //Voice.Speak("对不起语音系统发生故障", SpFlags);
                //MessageBox.Show(e.Message.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }

            thread.Join(5000);//阻塞线程5秒
        }
Пример #7
0
        public static void Speak(string Text)
        {
            var runningProcs = from proc in Process.GetProcesses(".") orderby proc.Id select proc;

            if (runningProcs.Count(p => p.ProcessName.Contains("nvda")) > 0)
            {
                nvdaController_cancelSpeech();
                nvdaController_speakText(Text);
            }
            else if (runningProcs.Count(p => p.ProcessName.Contains("jhookldr")) > 0)
            {
                Type   jfwApi = Type.GetTypeFromProgID("FreedomSci.JawsApi");
                object o      = Activator.CreateInstance(jfwApi);
                jfwApi.InvokeMember("SayString",
                                    System.Reflection.BindingFlags.InvokeMethod, null, o, new Object[1] {
                    Text
                });
            }
            else
            {
                SpeechLib.SpVoice synth = new SpeechLib.SpVoice();
                synth.Speak(Text, (SpeechVoiceSpeakFlags.SVSFDefault));
            }
        }
Пример #8
0
        /// <summary>
        /// ��������ӳ��߳�
        /// </summary>
        /// <param name="text"></param>
        void SpeekText(string text)
        {
            SpeechLib.SpeechVoiceSpeakFlags SpFlags =

            SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync;

            SpeechLib.SpVoice Voice = new SpeechLib.SpVoice();

            try
            {
                Voice.Speak(text, SpFlags);
            }
            catch (Exception)
            {
                //����
                //Voice.Speak("�Բ�������ϵͳ��������", SpFlags);
                //MessageBox.Show(e.Message.ToString(),"��ʾ",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }

            thread.Join(5000);
        }
Пример #9
0
 private bool initVoiceSpeech()
 {
     // talker http://d.hatena.ne.jp/rti7743/20111215/1323965483 からコピペ
     //合成音声エンジンを初期化する.
     try
     {
         this.VoiceSpeech = new SpeechLib.SpVoice();
     }
     catch (COMException)
     {
         MessageBox.Show(
             "合成音声が利用できません。" + Environment.NewLine
             + "Microsoft Speech Platform - Runtime (Version 11) をインストールしてください。"
         );
         return false;
     }
     //合成音声エンジンで日本語を話す人を探す。(やらなくても動作はするけど、念のため)
     Boolean hit = false;
     foreach (SpObjectToken voiceperson in this.VoiceSpeech.GetVoices())
     {
         string language = voiceperson.GetAttribute("Language");
         if (language == "411")
         {//日本語を話す人だ!
             this.VoiceSpeech.Voice = voiceperson; //君に読みあげて欲しい
             hit = true;
             break;
         }
     }
     if (!hit)
     {
         MessageBox.Show("日本語合成音声が利用できません。\r\n日本語合成音声 MSSpeech_TTS_ja-JP_Haruka をインストールしてください。\r\n");
         this.VoiceSpeech = null;
         return false;
     }
     boolTalkable = true;
     // event handler
     this.VoiceSpeech.EventInterests = SpeechVoiceEvents.SVEEndInputStream; // 終了時イベントを発生させるようになる
     this.VoiceSpeech.EndStream += new _ISpeechVoiceEvents_EndStreamEventHandler(VoiceSpeech_EndStream); // イベントハンドラ登録
     return true;
 }
Пример #10
0
 private void btnOku_Click(object sender, EventArgs e)
 {
     SpeechLib.SpeechVoiceSpeakFlags flg = SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync;
     SpeechLib.SpVoice ses = new SpeechLib.SpVoice();
     ses.Speak(txtIng.Text);
 }
Пример #11
0
        private int fnGetPPATatipNumber()
        {
            SpeechLib.SpVoice V = new SpeechLib.SpVoice();
            int intNumOfVoice = 0; //start at 0 because, in DLL, index is zero based

            foreach (ISpeechObjectToken Token in V.GetVoices())
            {
                if (Token.GetDescription() == "PPA ตาทิพย์")
                    break;
                else
                    intNumOfVoice++;
            }

            return intNumOfVoice;
        }