http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5468|回复: 1

[例子源码] 使用winmm.dll 获取麦克风声音数据

[复制链接]
发表于 2016-12-27 15:47:05 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
//录音
        /// <summary>
        /// 初始化录音环境
        /// </summary>
        /// <returns></returns>
        public static bool InitalDevice()
        {
            durLength = "";
            durLength = durLength.PadLeft(128, Convert.ToChar(" "));//11025
            ilong = APIClass.mciSendString("set media bitpersample 8", durLength, durLength.Length, 0);
            ilong = APIClass.mciSendString("set media samplespersec 11025", durLength, durLength.Length, 0);
            ilong = APIClass.mciSendString("set media channels 2", durLength, durLength.Length, 0);
            ilong = APIClass.mciSendString("set media format tag pcm", durLength, durLength.Length, 0);
            return true;
        }
 
        /// <summary>
        /// 开始录音
        /// </summary>
        /// <returns></returns>
        public static bool BeginRecord()
        {
            durLength = "";
            durLength = durLength.PadLeft(128, Convert.ToChar(" "));
            ilong = APIClass.mciSendString("close My", durLength, durLength.Length, 0);
            try
            {
                ilong = APIClass.mciSendString("open new type waveaudio alias My", durLength, durLength.Length, 0);
                ilong = APIClass.mciSendString("record My", durLength, durLength.Length, 0);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return true;
        }
 
        /// <summary>
        /// 保存录音
        /// </summary>
        /// <param name="path">保存路径</param>
        public static void SaveMusic(string path)
        {
            durLength = "";
            durLength = durLength.PadLeft(128, Convert.ToChar(" "));
            try
            {
                ilong = APIClass.mciSendString("save My " + path, durLength, durLength.Length, 0);
                APIClass.mciSendString("close My", durLength, durLength.Length, 0);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
 
        /// <summary>
        /// 停止录音
        /// </summary>
        public void StopRecord()
        {
            durLength = "";
            durLength = durLength.PadLeft(128, Convert.ToChar(" "));
            try
            {
                APIClass.mciSendString("stop My", durLength, durLength.Length, 0);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
 
        /// <summary>
        /// 暂停录音
        /// </summary>
        public void PauseRecord()
        {
            durLength = "";
            durLength = durLength.PadLeft(128, Convert.ToChar(" "));
            try
            {
                APIClass.mciSendString("pause My", durLength, durLength.Length, 0);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
 
        /// <summary>
        /// 继续录音
        /// </summary>
        public void ResumeRecord()
        {
            durLength = "";
            durLength = durLength.PadLeft(128, Convert.ToChar(" "));
            try
            {
                APIClass.mciSendString("resume My", durLength, durLength.Length, 0);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
 
public class APIClass
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern int GetShortPathName(string lpszLongPath, string shortFile, int cchBuffer);
 
        [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
        public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
    }




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2016-12-27 16:47:05 | 显示全部楼层
我只是路过打酱油的。
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-16 02:39

© 2014-2021

快速回复 返回顶部 返回列表