当前位置: 首页 > news >正文

上市公司网站推广方案化学试剂网站建设

上市公司网站推广方案,化学试剂网站建设,制作高端app开发公司,p2p理财网站开发要求C# NAudio 音频库 NAudio安装NAudio简述简单示例1录制麦克风录制系统声卡WAV格式播放MP3格式播放AudioFileReader读取播放音频MediaFoundationReader 读取播放音频 NAudio安装 项目NuGet包管理器 搜索NAudio点击安装#xff0c;自动安装依赖库。 安装成功后工具箱会新增… C# NAudio 音频库 NAudio安装NAudio简述简单示例1录制麦克风录制系统声卡WAV格式播放MP3格式播放AudioFileReader读取播放音频MediaFoundationReader 读取播放音频 NAudio安装 项目NuGet包管理器 搜索NAudio点击安装自动安装依赖库。 安装成功后工具箱会新增NAudio.WinForms控件 NAudio简述 NAudio为.NET平台下的开源库采用ML-PL协议开源地址https://github.com/naudio/NAudio支持多种音频操作可实现多种API播放与录制、多种不同音频格式、音频格式转换重采样、位深、声道等、音频编码、多通道播放、音频效果处理等等。 快速入门 深入研究 常用类 WaveIn 表示波形输入, 继承了 IWaveIn, 例如麦克风输入, 或者计算机正在播放的音频流。WaveOut 表示波形输出, 继承了 IWavePlayer, 用来播放音频, 以 IWaveProvider 作为播放源播放音频, 通过拓展方法也支持以 ISampleProvider 作为播放源播放音频。WaveStream 表示波形流, 它继承了 IWaveProvider, 可以用来作为播放源。WaveFileReader 继承了 WaveStream, 用来读取波形文件。WaveFileWriter 继承了Stream, 用来写入文件, 常用于保存音频录制的数据。AudioFileReader 通用的音频文件读取器, 可以读取波形文件, 也可以读取其他类型的音频文件例如 Aiff, MP3 常用接口 IWaveProvider 波形提供者, 上面已经提到, 是音频播放的提供者, 通过拓展方法可以转换为 ISampleProvider。ISampleProvider 采样提供者, 上面已经提到, 通过拓展方法可以作为 WaveOut 的播放源。 简单示例1 自定义录音机类Recorder.cs using NAudio.Wave; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace NAudioDemo {internal class Recorder{public WaveIn mWaveIn;public WaveFileWriter mWaveFileWriter;public int secondsRecorded;/// summary/// 开始录音/// /summary/// param namefilePath/parampublic void RecorderStart(string filePath){// 创建WaveIn对象mWaveIn new WaveIn();// 添加DataAvailable事件处理回调mWaveIn.DataAvailable OnDataAvailable;// 创建WaveFileWriter对象mWaveFileWriter new WaveFileWriter(filePath, mWaveIn.WaveFormat);// 开始录音mWaveIn.StartRecording();}/// summary/// 停止录音/// /summarypublic void RecorderStop(){mWaveIn?.StopRecording();mWaveIn?.Dispose();mWaveFileWriter?.Close();mWaveFileWriter null;}/// summary/// 录音数据回调/// /summary/// param namesender/param/// param namee/paramprivate void OnDataAvailable(object sender, WaveInEventArgs e){// 写入录音数据mWaveFileWriter.Write(e.Buffer, 0, e.BytesRecorded); // 计算已录制的秒数secondsRecorded (int)mWaveFileWriter.Length / mWaveFileWriter.WaveFormat.AverageBytesPerSecond;}} } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;using System.IO; using NAudio.Wave; using System.Drawing.Text; using System.Media; using NAudio.Dsp;namespace NAudioDemo {public partial class Form1 : Form{ // 创建录音机类实例Recorder recorder new Recorder();public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){button1.Enabled false;button2.Enabled true;recorder.RecorderStart(D:\1.wav);}private void button2_Click(object sender, EventArgs e){button1.Enabled true;button2.Enabled false;recorder.RecorderStop();}private void button3_Click(object sender, EventArgs e){SoundPlayer player new SoundPlayer(D:\1.wav);player.Play(); }} } 录制麦克风 借助 WaveIn 类, 我们可以轻易的捕获麦克风输入, 在每一次录制到数据时, 将数据写入到文件或其他流, 这就实现了保存录音 在保存波形文件时需要借助 WaveFileWriter, 当然, 如果你想保存为其他格式, 也可以使用其它的 Writer, 例如 CurWaveFileWriter 以及AiffFileWriter, 美中不足的是没有直接写入到 MP3 的 FileWriter 需要注意的是, 桌面程序可以直接使用 WaveIn, 其回调基于 Windows 消息, 所以无法在控制台应用中使用 WaveIn 如果要在控制台应用中实现录音, 只需要使用 WaveInEvent, 它的回调基于事件而不是 Windows 消息, 所以可以通用 示例代码 WaveIn cap new WaveIn(); // cap, capture WaveFileWriter writer new WaveFileWriter(); cap.DataAvailable (s, args) writer.Write(args.Buffer, 0, args.BytesRecorded); // 订阅事件 cap.StartRecording(); // 开始录制 cap.StopRecording(); // 停止录制 writer.Close(); // 关闭 FileWriter, 保存数据 另外, 除了使用 WaveIn, 你还可以使用 WasapiCapture, 它与 WaveIn 的使用方式是一致的, 可以用来录制麦克风 Wasapi 全称 Windows Audio Session Application Programming Interface (Windows音频会话应用编程接口) 具体 WaveIn, WaveInEvent, WasapiCapture 的性能, 笔者还没有测试过, 但估计不会有太大差异. 提示: WasapiCapture 和 WasapiLoopbackCapture 位于 NAudio.Wave 命名空间下 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;using NAudio; using NAudio.Wave;namespace NAudioDemo2 {public partial class Form2 : Form{private WaveIn waveIn null;private WaveFileWriter writer null;public Form2(){InitializeComponent();button2.Enabled false;button3.Enabled false;}/// summary/// 设置保存文件名称/// /summary/// param namesender/param/// param namee/paramprivate void button1_Click(object sender, EventArgs e){saveFileDialog1.InitialDirectory Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);saveFileDialog1.Filter audio files (*.wav)|*.wav| all files (*.*)|*.*; // 文件类型过滤saveFileDialog1.DefaultExt *.wav; // 默认文件扩展名//saveFileDialog1.FileName 1.wav; // 默认文件名if (saveFileDialog1.ShowDialog() DialogResult.OK){ string fName saveFileDialog1.FileName; // 获取文件名textBox1.Text fName;button2.Enabled true;}}/// summary/// 开始录音/// /summary/// param namesender/param/// param namee/paramprivate void button2_Click(object sender, EventArgs e){//waveIn new WaveIn { WaveFormat new WaveFormat(44100, 1) };waveIn new WaveIn();waveIn.WaveFormat new WaveFormat(44100, 1);writer new WaveFileWriter(textBox1.Text.Trim(), waveIn.WaveFormat);waveIn.DataAvailable (s, args) writer.Write(args.Buffer, 0, args.BytesRecorded);waveIn.StartRecording();button2.Enabled false;button3.Enabled true;}/// summary/// 停止录音/// /summary/// param namesender/param/// param namee/paramprivate void button3_Click(object sender, EventArgs e){waveIn.StopRecording();waveIn.Dispose();waveIn null;writer.Flush();writer.Close();writer.Dispose();button2.Enabled true;button3.Enabled false;}} } 录制系统声卡 录制声卡输出, 也就是录制计算机正在播放的声音, 借助 WasapiLoopbackCapture 即可简单实现, 使用方式与 WasapiCapture 无异 WasapiLoopbackCapture cap new WasapiLoopbackCapture(); WaveFileWriter writer new WaveFileWriter(); cap.DataAvailable (s, args) writer.Write(args.Buffer, 0, args.BytesRecorded); cap.StartRecording(); using NAudio.Wave; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace NAudioDemo2 {public partial class Form3 : Form{private WasapiLoopbackCapture loopCap new WasapiLoopbackCapture();private WaveFileWriter fileWriter;public Form3(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog new SaveFileDialog();saveFileDialog.Filter wave file *.wav|*.wav|all filse *.*|*.*;saveFileDialog.DefaultExt .wav;if (saveFileDialog.ShowDialog() DialogResult.OK){string fName saveFileDialog.FileName;textBox1.Text fName; }}/// summary/// 录制声卡开始/// /summary/// param namesender/param/// param namee/paramprivate void button2_Click(object sender, EventArgs e){fileWriter new WaveFileWriter(textBox1.Text.Trim(), loopCap.WaveFormat) ;loopCap.DataAvailable (s, args) fileWriter.Write(args.Buffer, 0, args.BytesRecorded);loopCap.StartRecording();}/// summary/// 录制声卡停止/// /summary/// param namesender/param/// param namee/paramprivate void button3_Click(object sender, EventArgs e){loopCap.StopRecording();fileWriter.Flush();fileWriter.Close();fileWriter.Dispose();}} } WAV格式播放 NAudio 中, 通过 WaveFileReader 来读取波形数据, 在实例化时, 你可以指定文件名或者是输入流, 这意味着你可以读取内存流中的音频数据. WaveFileReader reader new WaveFileReader(filepath); WaveOut wout new WaveOut(); wout.Init(reader); // 通过 IWaveProvider 为音频输出初始化 wout.Play(); // 至此, wout 将从指定的 reader 中提供的数据进行播放 using NAudio.Wave; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace NAudioDemo2 {public partial class Form4 : Form{private WaveOut wout_wav;WaveFileReader reader;public Form4(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd new OpenFileDialog();ofd.Filter audio file *.wav|*.wav;ofd.DefaultExt *.wav;if (ofd.ShowDialog() DialogResult.OK){string fName ofd.FileName;textBox1.Text fName;}}private void button2_Click(object sender, EventArgs e){reader new WaveFileReader(textBox1.Text.Trim());wout_wav new WaveOut();wout_wav.Init(reader);wout_wav.Play();}private void button3_Click(object sender, EventArgs e){wout_wav.Pause();}private void button4_Click(object sender, EventArgs e){wout_wav.Resume();}private void button5_Click(object sender, EventArgs e){wout_wav.Stop();wout_wav.Dispose();reader.Close();}} } MP3格式播放 播放 MP3 音乐其实与播放波形音乐没有太大区别, 只不过将 WaveFileReader 换成Mp3FileReader 罢了 Mp3FileReader reader new Mp3FileReader(filepath); WaveOut wout new WaveOut(); wout.Init(reader); wout.Play(); using NAudio.Wave; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace NAudioDemo2 {public partial class Form5 : Form{Mp3FileReader reader;WaveOut wout_mp3;public Form5(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd new OpenFileDialog();ofd.Filter audio file *.mp3|*.mp3;ofd.DefaultExt *.mp3;if (ofd.ShowDialog() DialogResult.OK){ string fName ofd.FileName;textBox1.Text fName;}}private void button2_Click(object sender, EventArgs e){reader new Mp3FileReader(textBox1.Text);wout_mp3 new WaveOut();wout_mp3.Init(reader);wout_mp3.Play();}private void button3_Click(object sender, EventArgs e){wout_mp3.Pause();}private void button4_Click(object sender, EventArgs e){wout_mp3.Resume();}private void button5_Click(object sender, EventArgs e){wout_mp3.Stop();wout_mp3.Dispose();reader.Close();reader.Dispose();}} } AudioFileReader读取播放音频 通过AudioFileReader读取音频文件可以播放.mp3, .wav, .flac等多种格式 AudioFileReader reader new AudioFileReader (“d:\1.mp3”); WaveOut wout new WaveOut (); wout.Init(reader ); wout.Play(); wout.Pause(); wout.Resume(); wout.Stop(); using NAudio.Wave; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace NAudioDemo2 {public partial class Form6 : Form{AudioFileReader reader;WaveOut wout;public Form6(){InitializeComponent();}private void Form6_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd new OpenFileDialog();ofd.Filter audio file *.mp3|*.mp3|all files *.*|*.*;if (ofd.ShowDialog() DialogResult.OK){ string fName ofd.FileName;textBox1.Text fName; }}private void button2_Click(object sender, EventArgs e){reader new AudioFileReader(textBox1.Text.Trim());wout new WaveOut();wout.Init(reader);wout.Play();}private void button3_Click(object sender, EventArgs e){wout.Pause(); }private void button4_Click(object sender, EventArgs e){wout.Resume();}private void button5_Click(object sender, EventArgs e){wout.Stop();wout.Dispose();reader.Close();reader.Dispose();}} } MediaFoundationReader 读取播放音频 通过MediaFoundationReader 读取音频文件可以播放.mp3, .wav, .flac等多种格式 MediaFoundationReader reader new MediaFoundationReader (“d:\1.mp3”); WaveOut wout new WaveOut (); wout.Init(reader ); wout.Play(); wout.Pause(); wout.Resume(); wout.Stop(); using NAudio.Wave; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace NAudioDemo2 {public partial class Form7 : Form{MediaFoundationReader reader;WaveOut wout;public Form7(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd new OpenFileDialog();ofd.Filter audio file *.mp3|*.mp3|all files *.*|*.*;ofd.DefaultExt *.mp3;if (ofd.ShowDialog() DialogResult.OK){string fName ofd.FileName;textBox1.Text fName;}}private void button2_Click(object sender, EventArgs e){reader new MediaFoundationReader(textBox1.Text.Trim());wout new WaveOut();wout.Init(reader);wout.Play();}private void button3_Click(object sender, EventArgs e){wout.Pause();}private void button4_Click(object sender, EventArgs e){wout.Resume();}private void button5_Click(object sender, EventArgs e){wout.Stop();wout.Dispose();reader.Close();reader.Dispose();}} }
文章转载自:
http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn
http://www.morning.xbdd.cn.gov.cn.xbdd.cn
http://www.morning.rgxcd.cn.gov.cn.rgxcd.cn
http://www.morning.nwljj.cn.gov.cn.nwljj.cn
http://www.morning.rkgyx.cn.gov.cn.rkgyx.cn
http://www.morning.kwqt.cn.gov.cn.kwqt.cn
http://www.morning.rnyhx.cn.gov.cn.rnyhx.cn
http://www.morning.qphdp.cn.gov.cn.qphdp.cn
http://www.morning.yrctp.cn.gov.cn.yrctp.cn
http://www.morning.ksbmx.cn.gov.cn.ksbmx.cn
http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn
http://www.morning.rnytd.cn.gov.cn.rnytd.cn
http://www.morning.brlgf.cn.gov.cn.brlgf.cn
http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn
http://www.morning.llyqm.cn.gov.cn.llyqm.cn
http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn
http://www.morning.mlyq.cn.gov.cn.mlyq.cn
http://www.morning.juju8.cn.gov.cn.juju8.cn
http://www.morning.piekr.com.gov.cn.piekr.com
http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn
http://www.morning.ljyqn.cn.gov.cn.ljyqn.cn
http://www.morning.cpljq.cn.gov.cn.cpljq.cn
http://www.morning.kmjbs.cn.gov.cn.kmjbs.cn
http://www.morning.ndnhf.cn.gov.cn.ndnhf.cn
http://www.morning.rlnm.cn.gov.cn.rlnm.cn
http://www.morning.qqnp.cn.gov.cn.qqnp.cn
http://www.morning.grjh.cn.gov.cn.grjh.cn
http://www.morning.qpntn.cn.gov.cn.qpntn.cn
http://www.morning.pybqq.cn.gov.cn.pybqq.cn
http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn
http://www.morning.fmznd.cn.gov.cn.fmznd.cn
http://www.morning.mrttc.cn.gov.cn.mrttc.cn
http://www.morning.gediba.com.gov.cn.gediba.com
http://www.morning.bssjz.cn.gov.cn.bssjz.cn
http://www.morning.ktblf.cn.gov.cn.ktblf.cn
http://www.morning.zypnt.cn.gov.cn.zypnt.cn
http://www.morning.qwmpn.cn.gov.cn.qwmpn.cn
http://www.morning.hsjfs.cn.gov.cn.hsjfs.cn
http://www.morning.hphrz.cn.gov.cn.hphrz.cn
http://www.morning.smfbw.cn.gov.cn.smfbw.cn
http://www.morning.dyxlm.cn.gov.cn.dyxlm.cn
http://www.morning.jzccn.cn.gov.cn.jzccn.cn
http://www.morning.dlhxj.cn.gov.cn.dlhxj.cn
http://www.morning.bqdpy.cn.gov.cn.bqdpy.cn
http://www.morning.tqdqc.cn.gov.cn.tqdqc.cn
http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn
http://www.morning.dskzr.cn.gov.cn.dskzr.cn
http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn
http://www.morning.dqrhz.cn.gov.cn.dqrhz.cn
http://www.morning.skrcn.cn.gov.cn.skrcn.cn
http://www.morning.rtryr.cn.gov.cn.rtryr.cn
http://www.morning.xtrzh.cn.gov.cn.xtrzh.cn
http://www.morning.xmhpq.cn.gov.cn.xmhpq.cn
http://www.morning.lbywt.cn.gov.cn.lbywt.cn
http://www.morning.mdxwz.cn.gov.cn.mdxwz.cn
http://www.morning.dkqr.cn.gov.cn.dkqr.cn
http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn
http://www.morning.jgcyn.cn.gov.cn.jgcyn.cn
http://www.morning.wbxr.cn.gov.cn.wbxr.cn
http://www.morning.nhzxr.cn.gov.cn.nhzxr.cn
http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com
http://www.morning.pxbky.cn.gov.cn.pxbky.cn
http://www.morning.trqsm.cn.gov.cn.trqsm.cn
http://www.morning.khdw.cn.gov.cn.khdw.cn
http://www.morning.kwblwbl.cn.gov.cn.kwblwbl.cn
http://www.morning.zwgrf.cn.gov.cn.zwgrf.cn
http://www.morning.kvzvoew.cn.gov.cn.kvzvoew.cn
http://www.morning.smfbw.cn.gov.cn.smfbw.cn
http://www.morning.jnvivi.com.gov.cn.jnvivi.com
http://www.morning.xtrzh.cn.gov.cn.xtrzh.cn
http://www.morning.gmswp.cn.gov.cn.gmswp.cn
http://www.morning.mytmx.cn.gov.cn.mytmx.cn
http://www.morning.rmxk.cn.gov.cn.rmxk.cn
http://www.morning.pngdc.cn.gov.cn.pngdc.cn
http://www.morning.ghqyr.cn.gov.cn.ghqyr.cn
http://www.morning.mwzt.cn.gov.cn.mwzt.cn
http://www.morning.yfffg.cn.gov.cn.yfffg.cn
http://www.morning.slzkq.cn.gov.cn.slzkq.cn
http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn
http://www.morning.rqlqd.cn.gov.cn.rqlqd.cn
http://www.tj-hxxt.cn/news/252389.html

相关文章:

  • 有没有做网站的团队关于网站建设费用的报告
  • 推广app大全怎么做seo关键词优化
  • 校企合作网站建设广州有什么好玩的地方推荐一下
  • 摄影网站有哪些功能建设一个类似于京东的网站
  • 西安 网站托管专科网站开发就业方向
  • 做电商网站前端用什么框架微信手机网站三合一
  • 中山中小企业网站制作中国铁建统一企业门户网站
  • wordpress网站前端高端文化网站
  • win8风格网站开发实例liferay做网站好吗
  • 贵阳经济技术开发区网站如何给自己的公司做网站
  • 济源市网站建设网页设计公司网易企业邮箱
  • 室内设计网站 知乎现在个人网站怎么备案
  • 注册公司制作网站网站建设字体颜色代码
  • 网站设计模式有哪些关于网站建设的英文歌
  • 岚山网站建设报价wordpress滑块
  • 企业制作网站哪家好上线了做网站怎么查看
  • 网站建设开题报告书品牌策划公司一般有什么职位
  • wordpress做企业网站wordpress uc点赞
  • 鞍山晟宇网站建设做影视后期应该关注哪些网站
  • 网站文件夹怎么做平谷手机网站建设
  • 做网站开发钱北京数据优化公司
  • 网页设计 网站维护广东省自然资源厅招聘
  • 百度深圳网站开发搜索详情页设计图片
  • 乌海网站建设公司wordpress评论楼
  • 做外贸有什么免费网站电子商务网站建设基础项目实训报告
  • 网站建设所采用的技术在线名片设计
  • 1网站建设logo标志设计图片
  • 东莞百度网站优化html制作一个电影介绍页面
  • 前端网站默认登录怎么做建立自我追求无我
  • 贵池区城乡与住房建设网站做网站时怎么让边框细一点