
下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
private SoundRecord m_Record = new SoundRecord(); private voID MainForm_Load(object sender,EventArgs e) { this.m_Record.OpenRecord(); // 打开录音 this.m_Record.StartRecord(); // 开始录音 } private voID BtnStopAndSave_Click(object sender,EventArgs e) { this.m_Record.StopRecord(); // 停止录音 this.m_Record.SaveRecord(@"C:\Users\windo\Desktop.wav"); // 保存录音 this.m_Record.CloseRecord(); // 关闭录音 } 上面的代码只是一个简单的录音并保存的过程,不过该类本身就很简单 而且我也附 public partial class SoundRecord { [Dllimport("WinMm.dll",CharSet = CharSet.auto,CallingConvention = CallingConvention.Cdecl)] private static extern int mciSendString(string lpstrCommand,string lpstrReturnString,int uReturnLength,int hwndCallback); private const int ERROR_SUCCESS = 0; private const string MODE_UNKNowN = "unkNown"; private static bool mciSendString(string strCommand) { return mciSendString(strCommand,null,0) != ERROR_SUCCESS; } } public partial class SoundRecord { private int m_channels; private int m_sample_spersec; private string m_format_tag; private int m_bits_per_sample; public SoundRecord() { this.Channels = 2; this.FormatTag = "pcm"; this.BitsPerSample = 8; this.SampleSpersec = 11025; } // 采样位数 public virtual int BitsPerSample { set { if (mciSendString("set wave bitpersample " + value)) this.m_bits_per_sample = value; } get { return this.m_bits_per_sample; } } // 采样频率 public virtual int SampleSpersec { get { return this.m_sample_spersec; } set { if (mciSendString("set wave samplespersec " + value)) this.m_sample_spersec = value; } } // 声道 public virtual int Channels { get { return m_channels; } set { if (mciSendString("set wave channels " + value)) this.m_channels = value; } } // 格式标签 public virtual string FormatTag { get { return this.m_format_tag; } set { if (mciSendString("set wave format tag " + value)) this.m_format_tag = value; } } // 打开录音 public virtual bool OpenRecord() { return mciSendString("open new type waveaudio alias movIE"); } // 开始录音 public virtual bool StartRecord() { return mciSendString("record movIE"); } // 停止录音 public virtual bool StopRecord() { return mciSendString("stop movIE"); } // 保存录音 public virtual bool SaveRecord(string savefilename) { return mciSendString("save movIE " + savefilename); } // 关闭录音 public virtual bool CloseRecord() { return mciSendString("close movIE"); } // 暂停录音 public virtual bool PauseRecord() { return mciSendString("pause movIE"); } // 恢复录音 public virtual bool ResumeRecord() { return mciSendString("resume movIE"); } // 执行状态 public virtual string Status { get { string strBuffer = new string('',12); if (mciSendString("status movIE mode",strBuffer,12,0) != ERROR_SUCCESS) return MODE_UNKNowN; if ((strBuffer = strBuffer.Remove(strBuffer.IndexOf(''))).Length <= 0) return MODE_UNKNowN; return strBuffer; } } } 以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的C# mci SoundRecord / 录音全部内容,希望文章能够帮你解决C# mci SoundRecord / 录音所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)