Exemplo n.º 1
0
 /// <summary>
 /// 结束喊话
 /// </summary>
 private void StopCollectSound()
 {
     try
     {
         if (!IsRecoding)
         {
             return;
         }
         //停止音频采集
         var rtn = PcmAudio.waveInStop(hRecord);
         if (rtn == 0) //停止采集成功,立即重置设备,重置设备将会导致所有的buffer反馈给程序
         {
             IsRecoding = false;
             //ShowMsg("停止采集音频数据。");
             rtn = PcmAudio.waveInReset(hRecord);  //重置设备
         }
         Thread.Sleep(500);
         if (rtn == 0)                            //重置设备成功,立即关闭设备
         {
             rtn = PcmAudio.waveInClose(hRecord); //关闭设备
         }
         //GC.Collect();
     }
     catch (Exception ex)
     {
         //ShowMsg(ex.Message);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 开始喊话
        /// </summary>
        private void StartCollectSound()
        {
            try
            {
                if (IsRecoding)
                {
                    return;
                }

                ////初始化音频编码解码
                //EvrcProtocal.InitEncoder();
                //EvrcProtocal.InitDecoder();
                EvrcProtocal.StartSpeech();
                var rtn = 0;
                hRecord = IntPtr.Zero;
                rtn     = PcmAudio.waveInOpen(out hRecord, -1, ref lpFormat, _wd, 0, 0x00030000);

                if (rtn == 0)//成功返回0
                {
                    //将准备好的buffer提供给音频输入设备
                    for (int i = 0; i < MAXRECBUFFER; i++)
                    {
                        //准备一个bufrer给输入设备
                        PcmAudio.waveInPrepareHeader(hRecord, ref globalhdr[i], (UInt32)Marshal.SizeOf(typeof(PcmAudio.WaveHdr)));
                        //发送一个buffer给指定的输入设备,当buffer填满将会通知程序
                        PcmAudio.waveInAddBuffer(hRecord, ref globalhdr[i], (UInt32)Marshal.SizeOf(typeof(PcmAudio.WaveHdr)));
                    }
                    //开启指定的输入采集设备
                    rtn = PcmAudio.waveInStart(hRecord);
                    if (rtn == 0)
                    {
                        IsRecoding = true;
                        //ShowMsg("正在采集音频数据...");
                    }
                    else
                    {
                        //ShowMsg("采集音频失败");
                    }
                }
            }
            catch (Exception ex)
            {
                //ShowMsg(ex.Message);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 喊话处理
 /// </summary>
 /// <param name="hdr"></param>
 private void OnSoundData(PcmAudio.WaveHdr hdr)
 {
     if (!IsRecoding)
     {
         return;
     }
     if (hdr.dwBytesRecorded == 0)
     {
         return;
     }
     //使采集过程,直到此buffer已经沾满,不能再填充
     PcmAudio.waveInUnprepareHeader(hRecord, ref hdr, (UInt32)Marshal.SizeOf(typeof(PcmAudio.WaveHdr)));
     //将采集到的声音发送给播放线程
     if (hdr.lpData != IntPtr.Zero)
     {
         DataProc(hdr.dwBytesRecorded, hdr.lpData);
     }
 }