Exemplo n.º 1
0
        /// <summary>
        /// 创建音频采集类事例
        /// </summary>
        /// <param name="wfx">采集音频使用的格式类型,注意:某些音频格式不支持采集</param>
        /// <param name="writer">写入的流对象</param>
        /// <returns>失败返回null</returns>
        public static AudioRecorder Create(WaveFormat wfx, BinaryWriter writer)
        {
            if (writer == null)
            {
                return(null);
            }

            MemoryStream wfxbs = new MemoryStream();

            wfx.Serialize(new BinaryWriter(wfxbs));

            AudioRecorder recoder = new AudioRecorder();

            recoder._writer   = writer;
            recoder._callback = new ReadyCallBack(recoder.CallBackProc);

            int result = OpenRecorder(ref recoder._hd, wfxbs.GetBuffer(), recoder._callback);

            if (result != 0)
            {
                return(null);
            }

            return(recoder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建音频采集类事例
        /// </summary>
        /// <param name="wfx">采集音频使用的格式类型,注意:某些音频格式不支持采集</param>
        /// <param name="callback">采集到数据后的回调函数</param>
        /// <param name="errcode">错误码</param>
        /// <returns></returns>
        public static AudioRecorder Create(WaveFormat wfx, ReadyCallBack callback, ref int errcode)
        {
            MemoryStream wfxbs = new MemoryStream();

            wfx.Serialize(new BinaryWriter(wfxbs));

            AudioRecorder recoder = new AudioRecorder();

            recoder._callback = callback;

            errcode = OpenRecorder(ref recoder._hd, wfxbs.GetBuffer(), recoder._callback);
            if (errcode != 0)
            {
                return(null);
            }

            return(recoder);
        }