コード例 #1
0
ファイル: AudioManager.cs プロジェクト: xiaomailong/CMS
        public void StartRecord()
        {
            Parent.Log.WriteLog("客户{0}启用语音输出", Parent.Name);
            if (!RequestConstants.VoiceFromFile)
            {
                //Lame init
                _lameConfig = new BE_CONFIG(new LameWaveFormat(SAMPLE_RATE, BITS, CHANNELS));
                Lame.beInitStream(_lameConfig, ref _lameInSamples, ref _lameOutBufferSize, ref _lameStream);
                _lameInBuffer  = new byte[_lameInSamples * 2]; //Input buffer is expected as short[]
                _lameOutBuffer = new byte[_lameOutBufferSize];

                WaveIn = new WaveIn();
                //waveIn.BufferMilliseconds = 50;
                //waveIn.DeviceNumber = inputDeviceNumber;
                WaveIn.WaveFormat = new WaveFormat(SAMPLE_RATE, CHANNELS);
                //配置waveIn以优化发送间隔
                //font
                WaveIn.DataAvailable += waveIn_DataAvailable;
                ////background
                //WaveInEvent waveInE = new WaveInEvent();
                //waveInE.DataAvailable += waveIn_DataAvailable;
                //waveIn.DataAvailable = waveInE;
                WaveIn.StartRecording();
            }
            else
            {
                //模拟持续录入
                byte[] buffer = File.ReadAllBytes(RequestConstants.FilePath);
                Parent.Log.WriteLog("音频数据已加载");
                int length   = buffer.Length;
                int position = 0;

                #region WriteData需要的初始化内容
                ////Lame init
                //_lameConfig = new BE_CONFIG(new LameWaveFormat(SAMPLE_RATE, BITS, CHANNELS));
                //Lame.beInitStream(_lameConfig, ref _lameInSamples, ref  _lameOutBufferSize, ref _lameStream);
                //_lameInBuffer = new byte[_lameInSamples * 2]; //Input buffer is expected as short[]
                //_lameOutBuffer = new byte[_lameOutBufferSize];
                //WriteData(buffer, 0, length);
                #endregion
                try
                {
                    while (length - position > 0)
                    {
                        int sendLength = Math.Min(length, Parent.TargetClient.SendBufferSize);
                        Parent.TargetClient.Send(buffer, sendLength, SocketFlags.None);
                        Thread.Sleep(100);
                        position += sendLength;
                        Parent.Log.WriteLog("{0}已传输{1}位数据", Parent.Name, sendLength);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                int j = 1;
            }
        }
コード例 #2
0
ファイル: Lame.cs プロジェクト: xiaomailong/CMS
 public static extern uint beInitStream(BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);