Пример #1
0
        public static void Speak(string str, bool isForce = false)
        {
            if (g_VoiceSpeeach == null)
            {//未初期化
                return;
            }

            str = U.table_replace(str, ConvertTable);
            if (str.Length <= 0)
            {
                return;
            }
            if (isForce == false)
            {
                if (g_CurrentString == str)
                {//既に読み上げた文字列は再度読み上げしない
                    return;
                }
            }
            if (str.Length < g_ShortLength)
            {//短すぎ
                return;
            }
            g_CurrentString = str;

            bool isSpeech = !g_VoiceSpeeach.WaitUntilDone(0);

            if (isSpeech)
            {
                g_VoiceSpeeach.Speak(" ", SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
            }
            g_VoiceSpeeach.Speak(g_CurrentString, SpeechVoiceSpeakFlags.SVSFlagsAsync);
        }
Пример #2
0
 static void speek(string strMessage)
 {
     if (strMessage.Trim() != null && strMessage.Trim() != "")
     {
         flvoice.Speak(strMessage, SpeechVoiceSpeakFlags.SVSFDefault);
     }
 }
 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);
 }
Пример #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
        /// <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秒
        }
Пример #6
0
 // 指定番の読み上げ番号テキストを再生
 private void startSpeech(int num)
 {
     // 読み上げフラグが立っていない場合は何もしない
     if (!this.SettingInstanse.talker || !boolTalkable || !boolSpeechPlayFlag)
     {
         return;
     }
     if (this.VoiceSpeech == null)
     {
         if (!initVoiceSpeech())
         {
             return;
         }
     }
     if (VoiceSpeech.Status.RunningState == SpeechRunState.SRSEIsSpeaking)
     {
         return;
     }           //使用中
     if (speechList.Count <= 0 || num > speechList.Count - 1)
     {
         return;
     }                                                                    // なし
     if (num >= 0 && speechList[num] != null && speechList[num].Length > 0)
     {
         // 読み上げ
         boolSkipFlag            = false; // フラグ戻す
         speechNum               = num;   // 現在番号で上書き
         textBox_talker_num.Text = num.ToString();
         // タグ入れ
         string speechBody = "<volume level=\"" +
                             this.SettingInstanse.talkVolume + "\"><rate absspeed=\"" +
                             this.SettingInstanse.talkSpeed + "\"><pitch absmiddle=\"" +
                             this.SettingInstanse.talkPitch + "\">" +
                             speechList[num] +
                             "</volume></rate></pitch>";
         VoiceSpeech.Speak(speechBody, SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFIsXML);
     }
 }
Пример #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 void btnOku_Click(object sender, EventArgs e)
 {
     SpeechLib.SpeechVoiceSpeakFlags flg = SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync;
     SpeechLib.SpVoice ses = new SpeechLib.SpVoice();
     ses.Speak(txtIng.Text);
 }