基本信息
源码名称:C#完成的声音(音频)采集使用
源码大小:0.67M
文件格式:.rar
开发语言:C#
更新时间:2019-05-10
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
C#完成的声音(音频)采集使用

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using LumiSoft.Media;
using LumiSoft.Media.Wave;
namespace 声音采集
{
	public partial class FormMain : Form
	{
		private WaveIn wavein = null;	//声音输入设备
		private WaveOut waveout = null;	//声音输出设备
		private bool started = false;	//程序状态

		public FormMain()
		{
			InitializeComponent();

			//添加输入设备选择
			foreach (WavInDevice device in WaveIn.Devices)
			{
				this.cbIn.Items.Add(device.Name);
			}
			if (this.cbIn.Items.Count > 0)
			{
				this.cbIn.SelectedIndex = 0;
			}

			//添加输出设备选择
			foreach (WavOutDevice device in WaveOut.Devices)
			{
				this.cbOut.Items.Add(device.Name);
			}
			if (this.cbOut.Items.Count > 0)
			{
				this.cbOut.SelectedIndex = 0;
			}
		}

		private void Start()
		{
			//开始
			//创建输入设备
			this.wavein = new WaveIn(WaveIn.Devices[this.cbIn.SelectedIndex], 8000, 16, 1, 1024);
			//创建输出设备
			this.waveout = new WaveOut(WaveOut.Devices[this.cbOut.SelectedIndex], 8000, 16, 1);

			//添加缓冲器采集满事件
			this.wavein.BufferFull  = new BufferFullHandler(WhenWaveDataFull);
			this.wavein.Start();
			this.started = true;
			this.btnStart.Text = "停止";
		}

		private void Stop()
		{
			//停止
			if (this.wavein != null)
			{
				this.wavein.Stop();
				this.wavein.Dispose();
				this.wavein = null;
			}

			if (this.waveout != null)
			{
				this.waveout.Dispose();
				this.waveout = null;
			}
			this.started = false;
			this.btnStart.Text = "开始";
		}

		private void btnStart_Click(object sender, EventArgs e)
		{
			if (started)
			{
				this.Stop();
			}
			else
			{
				this.Start();
			}
		}

		//缓冲器采集满事件
		private void WhenWaveDataFull(byte[] buffer)
		{
			//播放
			this.waveout.Play(buffer, 0, buffer.Length);
		}
	}
}