zoukankan      html  css  js  c++  java
  • .net简单录音和播放音频文件,不用DirectX ,对于C/S 、B/S都适用

    方法:

            //mciSendStrin.是用来播放多媒体文件的API指令,可以播放MPEG,AVI,WAV,MP3,等等,下面介绍一下它的使用方法:
            //第一个参数:要发送的命令字符串。字符串结构是:[命令][设备别名][命令参数].
            //第二个参数:返回信息的缓冲区,为一指定了大小的字符串变量.
            //第三个参数:缓冲区的大小,就是字符变量的长度.
            //第四个参数:回调方式,一般设为零
            //返回值:函数执行成功返回零,否则返回错误代码
            [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
            private static extern int mciSendString(
                string lpstrCommand,
                string lpstrReturnString,
                int uReturnLength,
                int hwndCallback);
    
            private static void mciSendString(String cmd)
            {
                mciSendString(cmd, "", 0, 0);
            }
    
            private static void StartRecord()
            {
                mciSendString("close movie");
                mciSendString("open new type WAVEAudio alias movie");
                mciSendString("record movie");
            }
    
            private static void StopRecord(string filename)
            {
                mciSendString("stop movie");
                mciSendString("save movie " + filename);
                mciSendString("close movie");
            }

    用法举例:

            protected void btStart_Click(object sender, EventArgs e)
            {   
                //开始录音
                StartRecord();
            }
    
            protected void btStop_Click(object sender, EventArgs e)
            {
                //停止录音
                StopRecord(@"C:	est.wav");
            }
    
            protected void btPlay_Click(object sender, EventArgs e)
            {
                //播放录音   也可以适用window系统带的TTS(Text To Speech)播放录音
                SoundPlayer sp = new SoundPlayer(@"c:	est.wav");
                sp.PlaySync();
            }
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    idea 文件名乱码问题的解决
    <context:component-scan>使用说明
    <mvc:annotation-driven />
    mac下的一些常识
    centos下的防火墙配置
    mac 下安装nginx
    centos下安装nginx
    Centos-统计文件或目录占用磁盘空间-du
    Centos-查看磁盘分区占用情况-df
    Centos-重定向方式打包、备份、还原、恢复工具-cpio
  • 原文地址:https://www.cnblogs.com/ful1021/p/4804501.html
Copyright © 2011-2022 走看看