Exemplo n.º 1
0
 //private ISpeechObjectTokens voiceInfo;
 /// <summary>
 /// constructor
 /// </summary>
 public HmfSpeechAssist()
 {
     this.tts = new SpVoice();
     this.tts.Volume = 100;
     this.tts.Rate = 0;
     this.speechFlg = SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak;
 }
Exemplo n.º 2
0
 /// <summary>
 /// constructor
 /// </summary>
 public UcommSpeaker()
 {
     voice = new SpVoice();
     voice.Volume = 100;
     voice.Rate = 0;
     voiceFlag = SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak;
     speaker = new SpeechSynthesizer(Properties.Settings.Default.AZURE_CLIENT_ID, Properties.Settings.Default.AZURE_CLIENT_SECRET);
 }
Exemplo n.º 3
0
 public MainForm()
 {
     InitializeComponent();
     mVoice = new SpVoice();
     mSpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
     mVoice.Priority = SpeechVoicePriority.SVPNormal;
     rbNormal.Checked = true;
     mPlaying = false;
     mNewStart = true;
 }
Exemplo n.º 4
0
        public TTSHelper(int volume, int rate)
        {
            //param
            spFileStream = new SpFileStream();     //declaring and Initializing fileStream obj
            spFileMode = SpeechStreamFileMode.SSFMCreateForWrite;  //declaring fileStreamMode as to Create or Write

            // SpeechVoiceSpeakFlags my_Spflag = SpeechVoiceSpeakFlags.SVSFlagsAsync; // declaring and initializing Speech Voice Flags
            my_Voice = new SpVoice();                   //declaring and initializing SpVoice Class
            sp_Rate = rate; sp_Volume = volume;
            my_Spflag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
        }
Exemplo n.º 5
0
        private void Speech(string message)
        {
#if SPEECH_API      //  using System.Speech.Synthesis;
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SpeakAsync("您有新的提交方案需签字");
#endif

#if SPEECH_COM      //  using SpeechLib
            //这些方法和对象到底是什么意思,可以自己去百度或者google一下,我也不是很清楚
            SpeechVoiceSpeakFlags ss = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice sp = new SpVoice();
            sp.Voice = sp.GetVoices(String.Empty, String.Empty).Item(0);
            sp.Speak("您有新的提交方案需签字", ss);//textBox1就是一个文本框,点击button1的时候系统读取该文本框的文字
#endif
        }
Exemplo n.º 6
0
        public void speak(object source, ElapsedEventArgs e)
        {
            DataSet ds  = new DataSet();
            string  sql = "select * from line";

            ds = sqlHelper.ExecuteDataSet(sql);
            SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice voice     = new SpVoice();
            string  b         = ds.Tables[0].Rows[0]["id"].ToString();
            string  voice_txt = string.Format("Please register for number {0} ", b);

            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
            voice.Speak(voice_txt, flag);
            timer.Stop();
        }
Exemplo n.º 7
0
        public void txtToFile(string value, string fileName)
        {
            GC.Collect();
            SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;

            SpeechLib.SpVoice    voice        = new SpVoiceClass();
            SpeechStreamFileMode SpFileMode   = SpeechStreamFileMode.SSFMCreateForWrite;
            SpFileStream         SpFileStream = new SpFileStream();

            SpFileStream.Open(fileName, SpFileMode, false);
            voice.AudioOutputStream = SpFileStream;
            voice.Speak(value, SpFlags);
            voice.WaitUntilDone(System.Threading.Timeout.Infinite);
            SpFileStream.Close();
        }
Exemplo n.º 8
0
        private void Text2speechBtn_Click(object sender, RoutedEventArgs e)
        {
            String text = inputText.Text.Trim();

            if (text == null || text == "")
            {
                MessageBox.Show("请输入要转为语音的汉字");
            }
            else
            {
                SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice voice = new SpVoice();
                voice.Speak(text, spFlags);
            }
        }
Exemplo n.º 9
0
        public static byte[] GetSound(string text)
        {
            const SpeechVoiceSpeakFlags speechFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            var synth  = new SpVoice();
            var wave   = new SpMemoryStream();
            var voices = synth.GetVoices();

            try
            {
                // synth setup
                synth.Volume = 100;
                synth.Rate   = -3;
                foreach (SpObjectToken voice in voices)
                {
                    if (voice.GetAttribute("Name") == "Microsoft Matej")
                    {
                        synth.Voice = voice;
                        break;
                    }
                }

                wave.Format.Type        = SpeechAudioFormatType.SAFT22kHz16BitMono;
                synth.AudioOutputStream = wave;
                synth.Speak(text, speechFlags);
                synth.WaitUntilDone(Timeout.Infinite);

                var waveFormat = new WaveFormat(22050, 16, 1);
                using (var ms = new MemoryStream((byte[])wave.GetData()))
                    using (var reader = new RawSourceWaveStream(ms, waveFormat))
                        using (var outStream = new MemoryStream())
                            using (var writer = new WaveFileWriter(outStream, waveFormat))
                            {
                                reader.CopyTo(writer);
                                //return o.Mp3 ? ConvertToMp3(outStream) : outStream.GetBuffer();

                                //var bytes = ConvertToMp3(outStream);
                                File.WriteAllBytes("speak.wav", outStream.GetBuffer());

                                return(null);
                            }
            }
            finally
            {
                Marshal.ReleaseComObject(voices);
                Marshal.ReleaseComObject(wave);
                Marshal.ReleaseComObject(synth);
            }
        }
Exemplo n.º 10
0
 public VoiceServiceImplByDotNetSpeech()
 {
     try
     {
         if (voice == null)
         {
             voice  = new SpVoice();
             sFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
             setDescription("VW Lily");
         }
     }
     catch (Exception e)
     {
         CLog4net.LogError("语音初始化错误" + e);
     }
 }
Exemplo n.º 11
0
        public SpeakVoice()
        {
            InitializeComponent();
            IntPtr i = this.Handle;

            _spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            _voice   = new SpVoice();
            InitialControl();
            _speakTextList            = new List <string>();
            lstLanguage.SelectedIndex = Convert.ToInt32(
                CXmlFile.GetStringFromXmlFile(configFile, "语音设置/语音类型", "0"));
            lstVoiceType.SelectedIndex = Convert.ToInt32(
                CXmlFile.GetStringFromXmlFile(configFile, "语音设置/格式类型", "0"));

            sliderValue.Value = Convert.ToInt32(CXmlFile.GetStringFromXmlFile(configFile, "语音设置/语速", "0"));
            playTimes.Value   = Convert.ToInt32(CXmlFile.GetStringFromXmlFile(configFile, "语音设置/播放次数", "1"));
            newThread         = new Thread(new ParameterizedThreadStart(doThread));
        }
Exemplo n.º 12
0
        private void Speak()
        {
            SpeechVoiceSpeakFlags flags =
                SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak | SpeechVoiceSpeakFlags.SVSFlagsAsync;

            flags |= SpeakPunctuationCheck.Checked ? SpeechVoiceSpeakFlags.SVSFNLPSpeakPunc : 0;
            flags |= PersistXmlCheck.Checked ? SpeechVoiceSpeakFlags.SVSFPersistXML : 0;
            flags |= IsNotXmlCheck.Checked ? SpeechVoiceSpeakFlags.SVSFIsNotXML : 0;
            flags |= IsXmlCheck.Checked ? SpeechVoiceSpeakFlags.SVSFIsXML : 0;
            flags |= IsFilenameCheck.Checked ? SpeechVoiceSpeakFlags.SVSFIsFilename : 0;
            try
            {
                Voice.Speak(InputTextBox.Text, flags);
            }
            catch (Exception)
            {
                AddEventMessage("ERROR: Error while trying to speak.");
            }
        }
Exemplo n.º 13
0
        private void Button_Click_3(object sender, RoutedEventArgs e)    //获得发音
        {
            string text = this.TB.Text.Trim();

            if (text.Length == 0)
            {
                return;
            }
            try
            {
                SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice voice = new SpVoice();
                voice.Speak(text, spFlags);
            }
            catch (Exception e1)
            {
                MessageBox.Show("发生错误" + e1.ToString());
            }
        }
Exemplo n.º 14
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                /*SpVoice voice = new SpVoice();
                 * voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3); //其中3为中文,024为英文
                 * voice.Speak(textspeechText.Text, SpeechVoiceSpeakFlags.SVSFDefault);
                 */

                SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice Voice = new SpVoice();
                Voice.Speak(this.textspeechText.Text, SpFlags);
            }
            catch (Exception er)
            {
                //MessageBox.Show("An Error Occured!", "SpeechApp", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Console.WriteLine(er.ToString());
            }
        }
Exemplo n.º 15
0
 private void PlayVoice(string message)
 {
     try
     {
         if (VoiceFlag)
         {
             if (Voice == null)
             {
                 Voice = new SpVoice();
             }
             SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
             Voice.Speak(message, SpFlags);
         }
     }
     catch (Exception ex)
     {
         PLogger.LogError(ex);
     }
 }
 private void SpeakVoicemainFrom_Load(object sender, EventArgs e)
 {
     _voice        = new SpVoice();
     _spFlags      = SpeechVoiceSpeakFlags.SVSFlagsAsync;
     _voice.Rate   = Int16.Parse(ConfigurationManager.AppSettings["VoiceRate"]);
     _voice.Volume = 100;
     try
     {
         _voice.Voice = _voice.GetVoices(string.Empty, string.Empty).Item(Int16.Parse(ConfigurationManager.AppSettings["VoicePackage"]));
     }
     catch
     {
         _voice.Voice = _voice.GetVoices(string.Empty, string.Empty).Item(0);
     }
     finally
     {
         button1.PerformClick();
     }
 }
Exemplo n.º 17
0
        static bool say(string filename, string sent, SpVoice voice)
        {
            SpFileStream fileStream = null;
            bool         success    = true;

            try
            {
                SpeechVoiceSpeakFlags flags = SpeechVoiceSpeakFlags.SVSFIsXML;
                //SpeechVoiceSpeakFlags flags = SpeechVoiceSpeakFlags.SVSFIsNotXML;
                //SpVoice voice = new SpVoice();
                SpeechStreamFileMode fileMode = SpeechStreamFileMode.SSFMCreateForWrite;

                fileStream = new SpFileStream();
                fileStream.Open(filename, fileMode, false);

                // audio output

                /*
                 * voice.Speak(sent, flags);
                 * voice.WaitUntilDone(Timeout.Infinite);
                 */
                // file output
                voice.AudioOutputStream = fileStream;
                voice.Speak(sent, flags);
                voice.WaitUntilDone(Timeout.Infinite);
            }
            catch (Exception error)
            {
                success = false;
                Console.Error.WriteLine("Error speaking sentence: " + error);
                Console.Error.WriteLine("error.Data: " + error.Data);
                Console.Error.WriteLine("error.HelpLink: " + error.HelpLink);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
            return(success);
        }
Exemplo n.º 18
0
        private void btnSpeak_Click(object sender, System.EventArgs e)
        {
            //Create a TTS voice and speak.
            try
            {
                SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice Voice = new SpVoice();
                if (chkSaveToWavFile.Checked)
                {
                    SaveFileDialog sfd = new SaveFileDialog();

                    sfd.Filter           = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
                    sfd.Title            = "Save to a wave file";
                    sfd.FilterIndex      = 2;
                    sfd.RestoreDirectory = true;

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;

                        SpFileStream SpFileStream = new SpFileStream();
                        SpFileStream.Open(sfd.FileName, SpFileMode, false);

                        Voice.AudioOutputStream = SpFileStream;
                        Voice.Speak(txtSpeakText.Text, SpFlags);
                        Voice.WaitUntilDone(Timeout.Infinite);

                        SpFileStream.Close();
                    }
                }
                else
                {
                    Voice.Speak(txtSpeakText.Text, SpFlags);
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Speak error", error.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw;
            }
        }
Exemplo n.º 19
0
 private void speak(string a)
 {
     if (mindInstance == null)
     {
         return;
     }
     try
     {
         SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
         SpVoice speech = new SpVoice();
         if (isSpeaking)
         {
             speech.Speak(a, SpFlags);
         }
     }
     catch
     {
         MessageBox.Show("Speech Engine error");
     }
 }
Exemplo n.º 20
0
 public void speak(string a)
 {
     if (mindInstance == null)
     {
         return;
     }
     try
     {
         SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
         SpVoice speech = new SpVoice();
         if (isSpeaking)
         {
             speech.Speak(a, SpFlags);
         }
     }
     catch
     {
         ;
     }
 }
Exemplo n.º 21
0
        }//public static void Main()

        ///<summary>SpeechVoiceSpeakFlagsEnum</summary>
        public static SpeechVoiceSpeakFlags SpeechVoiceSpeakFlagsEnum
        (
            bool filename,
            bool xml
        )
        {
            SpeechVoiceSpeakFlags speechVoiceSpeakFlags = SpeechVoiceSpeakFlagsDefault;

            if (filename == true)
            {
                speechVoiceSpeakFlags += (int)SpeechVoiceSpeakFlags.SVSFIsFilename;
            }
            if (xml == true)
            {
                speechVoiceSpeakFlags += (int)SpeechVoiceSpeakFlags.SVSFIsXML;
            }
   #if (DEBUG)
            System.Console.WriteLine("SpeechVoiceSpeakFlags: {0}", speechVoiceSpeakFlags);
   #endif
            return(speechVoiceSpeakFlags);
        }
        private void SpeakToOutputDevice(string message, string language)
        {
            const SpeechVoiceSpeakFlags speechFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice             synth  = new SpVoice();
            SpMemoryStream      wave   = new SpMemoryStream();
            ISpeechObjectTokens voices = synth.GetVoices();

            try
            {
                synth.Rate   = 0;
                synth.Volume = 100;

                wave.Format.Type        = SpeechAudioFormatType.SAFT44kHz16BitStereo;
                synth.AudioOutputStream = wave;

                if (language != null)
                {
                    foreach (SpObjectToken voice in voices)
                    {
                        if (voice.GetAttribute("Name") == language)
                        {
                            synth.Voice = voice;
                        }
                    }
                }

                synth.Speak(message, speechFlags);
                synth.WaitUntilDone(Timeout.Infinite);

                OutputWaveStream(wave);
            }
            finally
            {
                Marshal.ReleaseComObject(voices);
                Marshal.ReleaseComObject(wave);
                Marshal.ReleaseComObject(synth);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// 语音播放
        /// </summary>
        public static void NewRead()
        {
            try
            {
                //读取已有文件
                string            wavPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Sounds\\ring.wav";//要读的音频文件地址
                SpVoiceClass      pp      = new SpVoiceClass();
                SpFileStreamClass spFs    = new SpFileStreamClass();
                spFs.Open(wavPath, SpeechStreamFileMode.SSFMOpenForRead, true);
                ISpeechBaseStream Istream = spFs as ISpeechBaseStream;

                //文字转语音播放
                SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice spVoice = new SpVoice();                                                                                  //声源
                spVoice.Rate   = Convert.ToInt32(System.Configuration.ConfigurationManager.ConnectionStrings["Rate"].ToString()); //速度
                spVoice.Volume = 100;
                spVoice.WaitUntilDone(-1);
                spVoice.SpeakStream(Istream, spFlags);
                //循环播放
                for (int i = 0; i < readCount; i++)
                {
                    spVoice.WaitUntilDone(-1);
                    spVoice.Speak(readTxt, spFlags);//文字转语音播放
                }
                spFs.Close();
                //直接读取音频文件
                //SoundPlayer soundPlayer = new SoundPlayer();
                //soundPlayer.SoundLocation = wavPath;
                //soundPlayer.Load();
                //soundPlayer.Play();
            }
            catch (Exception err)
            {
                MessageBox.Show("语音播报失败!");
                CommonalityEntity.WriteTextLog(err.ToString());
            }
        }
Exemplo n.º 24
0
        private void chkVoiceFlag_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice Voice = new SpVoice();

                string message = "";
                if (this.chkVoiceFlag.Checked)
                {
                    message = "启用声音提示";
                }
                else
                {
                    message = "取消声音提示";
                }
                Voice.Speak(message, SpFlags);
            }
            catch (Exception ex)
            {
                chkVoiceFlag.Checked = false;
                PLogger.LogError(ex);
            }
        }
Exemplo n.º 25
0
        public static void NewRead(string content)
        {
            string       wavPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ring.wav";//要读的音频文件地址
            SpVoiceClass pp      = new SpeechLib.SpVoiceClass();

            SpeechLib.SpFileStreamClass spFs = new SpFileStreamClass();
            spFs.Open(wavPath, SpeechLib.SpeechStreamFileMode.SSFMOpenForRead, true);
            SpeechLib.ISpeechBaseStream Istream = spFs as SpeechLib.ISpeechBaseStream;
            //SoundPlayer soundPlayer = new SoundPlayer();
            //soundPlayer.SoundLocation = wavPath;
            //soundPlayer.Load();
            //soundPlayer.Play();
            SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice spVoice = new SpVoice(); //声源

            spVoice.Rate   = -5;             //速度
            spVoice.Volume = 100;
            //播放
            spVoice.SpeakStream(Istream, spFlags);
            spVoice.WaitUntilDone(-1);
            spVoice.Speak(content, spFlags);
            spFs.Close();
            //生成文件
            //try
            //{
            //    SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            //    SpFileStream SpFileStream = new SpFileStream();
            //    SpFileStream.Open(@"C:\Users\EMEWE\Desktop\Test.wav", SpFileMode, false);
            //    spVoice.AudioOutputStream = SpFileStream;//设定voice的输出为Stream
            //    spVoice.Speak(txtContent.Text.Trim(), spFlags);
            //    spVoice.WaitUntilDone(Timeout.Infinite);//Using System.Threading;
            //    SpFileStream.Close();
            //    MessageBox.Show("生成成功!");
            //}
            //catch { MessageBox.Show("生成失败!"); }
        }
Exemplo n.º 26
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();

            currentTime = System.DateTime.Now;

            label3.Text = currentTime.ToString("HH:mm:ss");


            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (label3.Text == listView1.Items[i].SubItems[1].Text.ToString())
                {
                    for (int j = 0; j < Convert.ToInt32(textBox2.Text); j++)
                    {
                        SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                        SpVoice voice     = new SpVoice();
                        string  voice_txt = listView1.Items[i].SubItems[3].Text.ToString();
                        voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
                        voice.Speak(voice_txt, flag);
                    }
                }
            }
        }
 public HRESULT SpeakAudio([NativeTypeName("long")] int StartElement, [NativeTypeName("long")] int Elements, SpeechVoiceSpeakFlags Flags, [NativeTypeName("long *")] int *StreamNumber)
 {
     return(((delegate * unmanaged <ISpeechRecoResult2 *, int, int, SpeechVoiceSpeakFlags, int *, int>)(lpVtbl[14]))((ISpeechRecoResult2 *)Unsafe.AsPointer(ref this), StartElement, Elements, Flags, StreamNumber));
 }
Exemplo n.º 28
0
        private void SaveFile(string FileName, string Content)
        {
            try
            {
                DelFile(FileName);

                if (SingletonInfo.GetInstance().IsNationFlag)
                {
                    string[] FileNamesp = FileName.Split('.');
                    FileName = FileNamesp[0] + ".wav";
                }


                SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice Voice = new SpVoice();
                Voice.Rate = SingletonInfo.GetInstance()._rate;
                string filename    = FileName;
                string filenametmp = FileName.Split('.')[0] + "tmp.wav";

                string texttxt = Content;
                SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;

                SpFileStream SpFileStream = new SpFileStream();

                SpFileStream.Open(filenametmp, SpFileMode, false);

                Voice.AudioOutputStream = SpFileStream;
                Voice.Speak(texttxt, SpFlags);
                Voice.WaitUntilDone(Timeout.Infinite);

                SpFileStream.Close();

                int nFrontPackCnt = SingletonInfo.GetInstance()._nFrontPackCnt;
                int nTailPackCnt  = SingletonInfo.GetInstance()._nTailPackCnt;
                int de            = NativeMethods.InsertBlankAudio(filename, filenametmp, nFrontPackCnt, nTailPackCnt);


                DelFile(filenametmp);
                FileInfo MyFileInfo = new FileInfo(filename);
                float    dirTime    = (float)MyFileInfo.Length / 32000;

                string[] filepathname   = FileName.Split('\\');
                string   filenamesignal = "";
                if (SingletonInfo.GetInstance().IsNationFlag)
                {
                    filenamesignal = filepathname[filepathname.Length - 1].Split('.')[0] + ".mp3";
                }
                else
                {
                    filenamesignal = filepathname[filepathname.Length - 1];
                }



                string senddata = "PACKETTYPE~TTS|FILE~" + filenamesignal + "|TIME~" + ((uint)dirTime).ToString();
                LogMessage(senddata);

                #region  如果是需要mp3文件  则需要调用ffmepg
                if (SingletonInfo.GetInstance().IsNationFlag)
                {
                    //转换MP3
                    string wavfilename = filenamesignal.Replace(".mp3", ".wav");
                    string fromMusic   = SingletonInfo.GetInstance()._path + "\\" + wavfilename;    //转换音乐路径
                    string toMusic     = SingletonInfo.GetInstance()._path + "\\" + filenamesignal; //转换后音乐路径
                    int    bitrate     = 128 * 1000;                                                //恒定码率
                    string Hz          = "44100";                                                   //采样频率
                    ExcuteProcess("ffmpeg.exe", "-y -ab " + bitrate + " -ar " + Hz + " -i \"" + fromMusic + "\" \"" + toMusic + "\"");

                    //  Thread.Sleep(100);
                    File.Delete(fromMusic);
                    //转换完成
                }
                #endregion


                #region ftp文件传输  20190107新增
                if (SingletonInfo.GetInstance().FTPEnable)
                {
                    string ftppath = filenamesignal;
                    string path    = SingletonInfo.GetInstance()._path + "\\" + filenamesignal;
                    SingletonInfo.GetInstance().ftphelper.UploadFile(path, ftppath);//阻塞式非线程模式
                }
                #endregion
                SendMQMessage(senddata);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(MainForm), "SaveFile处理异常:" + ex.ToString() + "----------" + ex.InnerException + "-------" + ex.StackTrace + "-------" + ex.Message, "2");
            }
        }
        private void InitializePrivates()
        {
            Console.WriteLine("Init the privates ...");
            //init the privates
            _dataObject = new FgfsDataObject();
            _dataHelper = new FgfsDataHelper(_dataObject);
            _registredDisplays = new ArrayList();
            //_display = new FgfsDisplay();

            #if USING_MS_SAPI
            // MS Speech SDK
            //SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            ms_Voice = null;
            //this._speechObj = null;
            #else
            this._soundCheckBox.Enabled = false;
            #endif

            this._sPort = null;
            this._swLog = null;

            //prepare the gui
            IpComboBox.DataSource = FgfsServer.DeterminePossibleIPs();

            // initialize pitch/roll max/min
            _max_pitch = -1;
            _min_pitch = 999999;
            _max_roll = -1;
            _min_roll = 999999;

            pitch_max = this.PitchBar.Maximum;
            pitch_min = this.PitchBar.Minimum;
            roll_max = this.RollBar.Maximum;
            roll_min = this.RollBar.Minimum;
            pitch_scale = pitch_max - pitch_min;
            roll_scale = roll_max - roll_min;
            pitch_scale2 = pitch_scale / 2;
            roll_scale2 = roll_scale / 2;
            Console.WriteLine("pitch {0} {1} {2} {3} roll {4} {5} {6} {7}",
                pitch_min, pitch_max, pitch_scale, pitch_scale2,
                roll_min, roll_max, roll_scale, roll_scale2);
        }
Exemplo n.º 30
0
        public frmStarter()
        {
            InitializeComponent();
            this.EnableGlass = false;

            LOCAL_ADDRESS = new IPEndPoint(_GetLocalIP(), PORT);
            m_udpClient = new UdpClient(LOCAL_ADDRESS);

            BreakInAlert += new SensorDataRcvEventHandler(OnBreakInAlert);
            ShowAlertForm = new ShowAlertFormEventHandler(OnShowAlertForm);
            CloseAlertForm = new ShowAlertFormEventHandler(OnCloseAlertForm);

            m_tmrAlert = new System.Threading.Timer(
                TmrAlertTick, "", Timeout.Infinite,	Timeout.Infinite);

            m_spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            m_voice = new SpVoice();
        }
Exemplo n.º 31
0
 public HRESULT SpeakStream(ISpeechBaseStream *Stream, SpeechVoiceSpeakFlags Flags, [NativeTypeName("long *")] int *StreamNumber)
 {
     return(((delegate * unmanaged <ISpeechVoice *, ISpeechBaseStream *, SpeechVoiceSpeakFlags, int *, int>)(lpVtbl[29]))((ISpeechVoice *)Unsafe.AsPointer(ref this), Stream, Flags, StreamNumber));
 }
Exemplo n.º 32
0
        //扫码
        private void AddGoods()
        {
            SpeechVoiceSpeakFlags speakflag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice voice = new SpVoice();
            string  num   = numberTextBox.Text;

            ///18位条码和13位条码混合
            if (string.IsNullOrEmpty(num) || (num.Length != 13 && num.Length != 18))
            {
                voice.Speak("错误", speakflag);
                MessageBox.Show("请确认扫码的条码是否正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                numberTextBox.Text = "";
                return;
            }
            ///以后的13的条码
            //if(string.IsNullOrEmpty(num) || num.Length != 13)
            //{
            //    MessageBox.Show("请确认扫码的条码是否正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    numberTextBox.Text = "";
            //    return;
            //}
            ///扫码扫出来的结果
            string serialNumber = "";
            float  weigth       = 0;

            if (num.StartsWith("28"))
            {
                ///13位的条码
                //serialNumber = num.Substring(2, 5);
                //string weightString = num.Substring(7, 5);
                //weigth = float.Parse(weightString.Insert(2, "."));

                ///18位的条码和13位码都有
                if (num.Length == 18)
                {
                    serialNumber = num.Substring(2, 5);
                    string weightString = num.Substring(12, 5);
                    weigth = float.Parse(weightString.Insert(2, "."));
                }
                else     //肉类的13位码
                {
                    serialNumber = num.Substring(2, 5);
                    string weightString = num.Substring(7, 5);
                    weigth = float.Parse(weightString.Insert(2, "."));
                }
            }
            else
            {
                serialNumber = num;
            }

            DataSet ds   = (DataSet)this.goodDataGridView.DataSource;
            bool    flag = false;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string serialNum = this.goodDataGridView[0, i].Value == null ? "" : this.goodDataGridView[0, i].Value.ToString();
                if (serialNum.Equals(serialNumber))
                {
                    string nums      = this.goodDataGridView[4, i].Value == null || "".Equals(this.goodDataGridView[4, i].Value) ? "0" : this.goodDataGridView[4, i].Value.ToString();
                    string orderNums = this.goodDataGridView[3, i].Value.ToString();

                    flag = true;
                    ///start 减去判断
                    if ((string.IsNullOrEmpty(nums) || "0".Equals(nums)) && !calFlag)
                    {
                        voice.Speak("错误", speakflag);
                        MessageBox.Show("此商品份数为0无法进行减去操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        numberTextBox.Text   = "";
                        calFlag              = true;
                        calculateButton.Text = "加(F1)";
                        return;
                    }
                    else
                    {
                        orderSorte orderSorte = new orderSorte();
                        orderSorte.createTime = DateTime.Now;
                        orderSorte.updateTime = DateTime.Now;
                        orderSorte.address    = ConstantUtil.street;
                        orderSorte.goods_id   = this.goodDataGridView.Rows[i].Cells[5].Value == null ? "" : this.goodDataGridView.Rows[i].Cells[5].Value.ToString();
                        orderSorte.id         = Guid.NewGuid().ToString();
                        orderSorte.goods_name = this.goodDataGridView.Rows[i].Cells[2].Value == null ? "" : this.goodDataGridView.Rows[i].Cells[2].Value.ToString();
                        //订单份数
                        orderSorte.orderNum = this.goodDataGridView.Rows[i].Cells[3].Value == null ? "" : this.goodDataGridView.Rows[i].Cells[3].Value.ToString();

                        orderSorte.weight = weigth.ToString();
                        sorteDao sortedao = new sorteDao();
                        if (calFlag)
                        {
                            orderSorte.sorteNum = "1";
                            sortedao.AddtransitItem(orderSorte);
                        }
                        else
                        {
                            List <string> list = sortedao.FindBy(orderSorte.goods_id, weigth.ToString(), ConstantUtil.street);
                            if (list.Count == 0)
                            {
                                voice.Speak("错误", speakflag);
                                MessageBox.Show("没有此商品对应得分拣记录,无需进行减去操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                numberTextBox.Text = "";
                                return;
                            }
                            sortedao.DeleteBy(list[0]);
                            calFlag = true;
                            calculateButton.Text = "加(F1)";
                        }
                    }
                    numberTextBox.Text = "";
                }
                else
                {
                }
            }
            if (!flag)
            {
                voice.Speak("错误", speakflag);
                MessageBox.Show("没有此商品,请确认商品或者货号是否正确", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                numberTextBox.Text = "";
                return;
            }
        }
Exemplo n.º 33
0
        private void msgTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                //显示的字数长度
                int length = (int)((msgStartX - msgCurntX) / (msgStep * 4));

                if (ExtendAppContext.Current.StaticMsgList == null)
                {
                    ExtendAppContext.Current.StaticMsgList = new List <string>();
                    ExtendAppContext.Current.StaticMsgList.Add("暂无公告信息。");
                }
                string msg = "";
                //非紧急公告,即静态公告
                if (!isEmgrcMsg)
                {
                    if (msgIndex == ExtendAppContext.Current.StaticMsgList.Count)
                    {
                        msgIndex  = 0;
                        msgCurntX = msgStartX;
                    }
                    msg = ExtendAppContext.Current.StaticMsgList[msgIndex];
                    //修正起始位置偏移的问题
                    while ((length <= msg.Length) &&
                           (this.CreateGraphics().MeasureString(msg.Substring(0, length), MsgFont).Width < (msgStartX - msgCurntX)))
                    {
                        length++;
                    }
                    if (length > ExtendAppContext.Current.StaticMsgList[msgIndex].Length)
                    {
                        length = ExtendAppContext.Current.StaticMsgList[msgIndex].Length;
                    }
                    //截取需要显示的字符串
                    curntMsg = ExtendAppContext.Current.StaticMsgList[msgIndex].Substring(0, length);
                }
                else
                {
                    //修正起始位置偏移的问题
                    while ((length <= noticeMsg.Length) &&
                           (this.CreateGraphics().MeasureString(noticeMsg.Substring(0, length), MsgFont).Width < (msgStartX - msgCurntX)))
                    {
                        length++;
                    }
                    if (length > noticeMsg.Length)
                    {
                        length = noticeMsg.Length;
                    }
                    //截取需要显示的字符串
                    curntMsg = noticeMsg.Substring(0, length);
                }
                //计算需要显示的字符长度
                int msgLength = (int)this.CreateGraphics().MeasureString(curntMsg, MsgFont).Width;
                if (msgCurntX + msgLength > 0)
                {
                    screenBottomPnl.Refresh();
                    msgCurntX -= msgStep;
                }
                //转完一圈,重新获取公告信息
                if (msgCurntX + msgLength <= 0)
                {
                    //msgTimer.Stop();
                    if (!isEmgrcMsg)
                    {
                        //重新获取静态播报信息列表
                        QueryParams queryParams = new QueryParams();
                        queryParams.AddQueryDefines("ScreenNo", OperationEnum.Equal, ExtendAppContext.Current.CurntScreenNo);
                        DataTable     staticMsgTable = DataOperator.HttpWebApi <DataResult>(ApiUrlEnum.GetValidMsgData, queryParams).ToDataTable();
                        List <string> staticListMsg  = new List <string>();
                        if (staticMsgTable != null && staticMsgTable.Rows.Count > 0)
                        {
                            foreach (DataRow row in staticMsgTable.Rows)
                            {
                                if (!row.IsNull("MSG_CONTENT") && !string.IsNullOrEmpty(row["MSG_CONTENT"].ToString()))
                                {
                                    staticListMsg.Add(row["MSG_CONTENT"].ToString());
                                }
                            }
                            ExtendAppContext.Current.StaticMsgList = staticListMsg;
                        }
                        msgIndex++;
                    }
                    // Dictionary<string, string> noticeMsgDict = GetMsgNoticInfo();
                    if (noticeMsgDict != null && noticeMsgDict.Count > 0 && ExtendAppContext.Current.IsBroadCast)
                    {
                        isEmgrcMsg = true;
                        foreach (KeyValuePair <string, string> kvp in noticeMsgDict)
                        {
                            string[] Info_Count = kvp.Value.Split(',');//通告信息,播报次数
                            string   msgID      = kvp.Key;
                            noticeMsg = Info_Count[0];
                            int count = Convert.ToInt32(Info_Count[1]);
                            SpFlags    = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;
                            Voice      = new SpVoice();
                            Voice.Rate = -4;
                            Voice.Speak(noticeMsg, SpFlags);
                            //Voice.WaitUntilDone(System.Threading.Timeout.Infinite);
                            //可播报次数-1
                            count -= 1;
                            //更新剩余可播报次数
                            UpdateMsgDataTable(msgID, count);
                            if (count == 0)
                            {
                                noticeMsgDict.Remove(msgID);
                            }
                            else
                            {
                                noticeMsgDict[msgID] = noticeMsg + "," + count;
                            }
                            break;//一次只播一条
                        }
                    }
                    else
                    {
                        isEmgrcMsg = false;
                    }
                    msgCurntX = msgStartX;
                    //msgTimer.Start();
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Exemplo n.º 34
0
        public void PlaySpeak(string text)
        {
            SpeechVoiceSpeakFlags flg = SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak;

            sv1.Speak(text, flg);
        }
Exemplo n.º 35
0
        private static void VoiceReportFun()
        {
            try
            {
                SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFDefault; //.SVSFlagsAsync;

                var voice = new SpVoice();


                while (_isVoiceReport)
                {
                    try
                    {
                        if (_voiceReportItems.Count > 0)
                        {
                            string speaktext = "";
                            if (_voiceReportItems.TryDequeue(out speaktext))
                            {
                                if (string.IsNullOrEmpty(speaktext))
                                {
                                    continue;
                                }
                                voice.Speak(speaktext, SpFlags);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Wlst.Cr.Core.UtilityFunction.WriteLog.WriteLogError("语音报警出错:" + ex);
                    }
                    Thread.Sleep(1000);
                }
                //System.Speech.Synthesis.SpeechSynthesizer
                //var  speechSynthesizer = new SpeechSynthesizer();
                // speechSynthesizer.SetOutputToDefaultAudioDevice();


                // while (_isVoiceReport)
                //{
                //    try
                //    {
                //        if (_voiceReportItems.Count > 0)
                //        {
                //            string speaktext = "";
                //            if (_voiceReportItems.TryDequeue(out speaktext))
                //            {
                //                if (string.IsNullOrEmpty(speaktext))
                //                    continue;
                //                speechSynthesizer.Speak(speaktext);

                //            }

                //        }
                //    }
                //    catch (Exception ex)
                //    {
                //        Wlst.Cr.Core.UtilityFunction.WriteLog.WriteLogError("语音报警出错:" + ex);
                //    }
                //    Thread.Sleep(1000);
                //}
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 36
0
 public HRESULT Speak([NativeTypeName("BSTR")] ushort *Text, SpeechVoiceSpeakFlags Flags, [NativeTypeName("long *")] int *StreamNumber)
 {
     return(((delegate * unmanaged <ISpeechVoice *, ushort *, SpeechVoiceSpeakFlags, int *, int>)(lpVtbl[28]))((ISpeechVoice *)Unsafe.AsPointer(ref this), Text, Flags, StreamNumber));
 }