c#获取麦克风数据并播放
来源:互联网 发布:图片清晰化软件 编辑:程序博客网 时间:2024/05/06 19:23
本程序使用了第三方(傲瑞科技)开发库:
- ESBasic.dll
- ESBasic.xml
- Oraycn.MCapture.dll
- Oraycn.MCapture.xml
- Oraycn.MPlayer.dll
- Oraycn.MPlayer.xml
访问官方网址
将以上文件拷贝到项目Debug目录下,并在项目中添加引用
捕获音频数据类
using Oraycn.MCapture;using RemoteDiagnosis.net;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace RemoteDiagnosis.audio{ public class MicrophoneHelper { private static MicrophoneHelper micphoneHelper = new MicrophoneHelper(); private IMicrophoneCapturer microphoneCapturer; public bool started = false; private MicrophoneHelper() { } public static MicrophoneHelper getIns() { return micphoneHelper; } public bool start() { try { this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric<byte[]>(microphoneCapturer_AudioCaptured); //this.audioPlayer = PlayerFactory.CreateAudioPlayer(0, 16000, 1, 16, 3); this.microphoneCapturer.Start(); started = true; } catch (Exception ) { started = false; } return started; } //捕获麦克风的音频数据 void microphoneCapturer_AudioCaptured(byte[] audioData) { MyAudioClient.getIns().send(audioData); //SpeakerHelper.getIns().speak(audioData); } public void stop() { if (this.microphoneCapturer != null) { this.microphoneCapturer.Stop(); this.microphoneCapturer.Dispose(); this.microphoneCapturer = null; } } }}
播放捕获的音频数据
using Oraycn.MPlayer;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace RemoteDiagnosis.audio{ public class SpeakerHelper { private static SpeakerHelper speaker = new SpeakerHelper(); private IAudioPlayer audioPlayer; private SpeakerHelper() { this.audioPlayer = PlayerFactory.CreateAudioPlayer(0, 16000, 1, 16, 3); //this.audioPlayer = PlayerFactory.CreateAudioPlayer(0, 16000, 2, 16, 3); } public static SpeakerHelper getIns() { return speaker; } /// <summary> /// 播放数据 /// </summary> /// <param name="buffer"></param> public void speak(byte[] buffer) { if (this.audioPlayer != null) { //Debug.WriteLine("audioData :" + audioData.Length); this.audioPlayer.Play(buffer); } } public void stop() { if (this.audioPlayer != null) { this.audioPlayer.Clear(); this.audioPlayer.Dispose(); this.audioPlayer = null; } } }}
如果音频播放没有声音,请查看麦克风与扬声器的音量是否为零或禁用了,查看方式为进入控制面板-声音-扬声器(如果没有接设备可能没有)-属性-级别
0 0
- c#获取麦克风数据并播放
- 获取麦克风声音数据
- C#实现麦克风采集与播放
- android开发(18) 调用手机的麦克风录音,并播放。
- android开发(18) 调用手机的麦克风录音,并播放。
- c# Winform 获取麦克风音量 控制麦克风音量大小 (自用笔记未测试)
- 麦克风播放器
- 获取麦克风音量
- iOS获取麦克风权限
- c# 获取FTP文件,并将数据导入ORACLE数据库
- C# 获取xml数据,并转换为dataset
- C#中如何连接SQL数据库 并获取数据
- C#获取SharePoint中列表的数据并进行修改
- C#笔记(3)获取json数据并解析
- 使用C#实现通过网络发送和播放麦克风的声音
- 调用麦克风录音及播放
- 获取并显示数据
- C#局域网内UDP广播获取获取JSON数据并解析
- Elastic-Job目录结构说明
- Struts2典型应用
- 编写一个程序,读入个数不确定的(<=100个)考试分数,并且判断有多少个分数是大于或等于平均分,多少个分数是低于平均分的。输入一个负数表示输入的结束。假设成绩的最高分为10分。
- 随机生成字符串
- 并查集-201412-4 最优灌溉
- c#获取麦克风数据并播放
- docker镜像制作之Dockerfile文件---snort
- java.lang.ArrayIndexOutOfBoundsException: 24444
- JDBC操作数据库
- python安装步骤详解
- 2016年10月22日上午图片加载
- VR优化
- JDBC操作数据库的批处理
- 适应式导航