博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用winmm.dll 获取麦克风声音数据
阅读量:5223 次
发布时间:2019-06-14

本文共 3546 字,大约阅读时间需要 11 分钟。

//录音        ///         /// 初始化录音环境        ///         /// 
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; } /// /// 开始录音 /// ///
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; } /// /// 保存录音 /// /// 保存路径 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(); } } /// /// 停止录音 /// 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(); } } /// /// 暂停录音 /// 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(); } } /// /// 继续录音 /// 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); }

  

转载于:https://www.cnblogs.com/zhao-yi/p/6225940.html

你可能感兴趣的文章
20172319 《Java程序设计教程》第8周学习总结
查看>>
从操作系统拖拽图片到指定区域进行预览
查看>>
HBase常用命令
查看>>
shell编程 学好内功(一)
查看>>
ThreadPoolExecutor使用详解
查看>>
Swift - 给图片添加文字水印(图片上写文字,并可设置位置和样式)
查看>>
Android 开发中 iBeacon的使用
查看>>
hdu 1828 Picture(线段树扫描线矩形周长并)
查看>>
按钮function关闭子页面刷新父页面中部分控件数据
查看>>
产品微软K2+微软平台集成解决方案
查看>>
备份数据库CMD命令操作MSSQL2005数据库
查看>>
jUnit4初探(1)
查看>>
SAX解析xml characters方法要注意的问题
查看>>
第3章 表、栈和队列
查看>>
faceswap安装说明
查看>>
【转】OpenCV对图片中的RotatedRect进行填充
查看>>
pymysql模块
查看>>
API查询利器-Zeal
查看>>
c#运算符
查看>>
C# 之泛型详解
查看>>