C# winfrom 录音

导入API函数:          

        [DllImport("winmm.dll")]
        public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

开始录音:

                    mciSendString("set wave bitpersample 8", "", 0, 0);  //设为8
                mciSendString("set wave samplespersec 11025", "", 0, 0);//设置每个声道播放和记录时的样本频率为20Hz-20000Hz
                mciSendString("set wave channels 2", "", 0, 0);  //设为立体声

                mciSendString("set wave format tag pcm", "", 0, 0);//设置PCM(脉冲编码调制)
                mciSendString("open new type WAVEAudio alias movie", "", 0, 0); //打开一个新的录音文件
                mciSendString("record movie", "", 0, 0);  //开始录音


停止并保存录音文:

                mciSendString("stop movie", "", 0, 0);//停止录音
                mciSendString("save movie" + " " + "recordvoice.wav", "", 0, 0);//保存录音文件,recordvoice.wav为录音文件
                mciSendString("close movie", "", 0, 0);   //关闭录音

你可能感兴趣的:(asp.net)