zoukankan      html  css  js  c++  java
  • .net录音和播放音频文件代码

    方法:

    //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();  
            }  
  • 相关阅读:
    SAP函数生成测试数据
    ABAP——编码规范
    展BOM清单——CS_BOM_EXPL_MAT_V2
    Java使用JCO实现调用SAP接口(建立采购单)
    ECN变更单建立——CCAP_ECN_CREATE
    SmartForms——插入复选框
    SmartForms——属性框被拖拽到左边不能复原
    SmartForms——实例
    SmartForms——基础知识
    SAP PP——生产订单的状态
  • 原文地址:https://www.cnblogs.com/tuyile006/p/12572475.html
Copyright © 2011-2022 走看看