使用NAudio实现Wav转Mp3
转换成MP3:
using Microsoft.Win32;
using NAudio.MediaFoundation;
using NAudio.Wave;
using System.Windows; namespace NAudioDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*";
openFileDialog.FilterIndex = ;
if (openFileDialog.ShowDialog() == true)
{
var inputFileName = openFileDialog.FileName;
var outputFileName = inputFileName.Substring(, inputFileName.Length - ) + "mp3"; var mediaType = MediaFoundationEncoder.SelectMediaType(
AudioSubtypes.MFAudioFormat_MP3,
new WaveFormat(, ),
); using (var reader = new MediaFoundationReader(inputFileName))
{
using (var encoder = new MediaFoundationEncoder(mediaType))
{
encoder.Encode(outputFileName, reader);
}
}
}
MessageBox.Show("操作成功");
}
}
}
转换成WMA:
private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*";
openFileDialog.FilterIndex = ;
if (openFileDialog.ShowDialog() == true)
{
var inputFileName = openFileDialog.FileName;
var outputFileName = inputFileName.Substring(, inputFileName.Length - ) + "wma"; var mediaType = MediaFoundationEncoder.SelectMediaType(
AudioSubtypes.MFAudioFormat_WMAudioV8,
new WaveFormat(, ),
); using (var reader = new MediaFoundationReader(inputFileName))
{
using (var encoder = new MediaFoundationEncoder(mediaType))
{
encoder.Encode(outputFileName, reader);
}
}
}
MessageBox.Show("操作成功");
}
使用NAudio实现Wav转Mp3的更多相关文章
- WIN32下使用DirectSound接口的简单音频播放器(支持wav和mp3)
刚好最近接触了一些DirectSound,就写了一个小程序练练手,可以用来添加播放基本的wav和mp3音频文件的播放器.界面只是简单的GDI,dxsdk只使用了DirectSound8相关的接口. D ...
- 简单风格 在线音乐播放器(支持wav,MP3等)
找了两天终于找到了,支持wav,MP3,其他格式没有测试. 1.修复了jQuery判断ie的bug, 2.修复播放循环 下载地址: http://pan.baidu.com/s/1o6upwHs
- javaCV开发详解之7:让音频转换更加简单,实现通用音频编码格式转换、重采样等音频参数的转换功能(以pcm16le编码的wav转mp3为例)
javaCV系列文章: javacv开发详解之1:调用本机摄像头视频 javaCV开发详解之2:推流器实现,推本地摄像头视频到流媒体服务器以及摄像头录制视频功能实现(基于javaCV-FFMPEG.j ...
- 基于emWin的WAV,MP3软解软件播放器,带类似千千静听频谱,含uCOS-III和FreeRTOS两个版本
第9期:WAV,MP3软解播放器,带类似千千静听频谱配套例子:V6-916_STemWin提高篇实验_WAV,MP3软解播放器,带类似千千静听频谱(uCOS-III)V6-917_STemWin提高篇 ...
- c# Use NAudio Library to Convert MP3 audio into WAV audio(将Mp3格式转换成Wav格式)
Have you been in need of converting mp3 audios to wav audios? If so, the skill in this article prov ...
- C#文本转语音并保存wav和MP3文件
回顾上次写博客至今都有4个多月了,最近工作比较的忙没时间写博文.以后会多坚持写博文,与大家分享下最近遇到的问题.最近因为项目需要,研究了下用C#开发TTS.下面把大体的思路给大家说说,希望对大家有所帮 ...
- FFMPEG转换WAV到MP3
下载FFMPEG https://ffmpeg.zeranoe.com/builds/ Example to encode VBR MP3 audio with ffmpeg using the li ...
- 音频转换 wav to wav、mp3或者其它
1.首先介绍一种NAudio 的方式 需要导入 NAudio.dll 下面请看核心代码 using (WaveFileReader reader = new WaveFileReader(in_pat ...
- MP3/WAV 播放
一.编译libmad 1.先下载压缩包到本地,并解压 tar -xvzf libmad-0.15.1b.tar.gz -C ./ 2.进入源代码文件夹并配置 编写一个配置文件,便于< ...
随机推荐
- linux网络编程学习笔记之二 -----错误异常处理和各种碎碎(更新中)
errno 在unix系统中对大部分系统调用非正常返回时,通常返回值为-1.并设置全局变量errno(errno.h),如socket(), bind(), accept(), listen(). e ...
- [iOS]iOS开发人员账号申请与注冊流程
郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...
- amazeui中的js插件有哪些(详解功能)
amazeui中的js插件有哪些(详解功能) 一.总结 一句话总结: 二.amazeui中的js插件有哪些 1.UI 增强 警告框Alert 按钮交互Button 折叠面板Collapse 下拉组件D ...
- 概念的理解 —— 奇点(singularity point)、第一性原理(first principle)
奇点(singularity point)一词出现在不同的环境里,对应着不同的含义: wikipedia:Singularity 文艺作品: 未来学(Futurology):比如雷·库兹韦尔的< ...
- ZOJ Monthly, June 2014 解题报告
A.Another Recurrence Sequence problemId=5287">B.Gears 题目大意:有n个齿轮,一開始各自为一组.之后进行m次操作,包含下面4种类型: ...
- 【9102】&&【a102】求a/b的高精度值
Time Limit: 10 second Memory Limit: 2 MB 问题描述 计算a/b的精度值,设a,b以一般整数输入,计算结果精确到小数后20位(结果四舍五入). Input 文件输 ...
- JavaScript实现简单图片滚动 --9张图告诉你,C罗欲哭无泪
源代码下载:http://download.csdn.net/detail/u011043843/7510425 昨晚德国和葡萄牙的焦点之战你看了吗?北京时间凌晨的比赛中.C罗领衔的葡萄牙0-4德国被 ...
- 【bzoj2809】派遣 (左偏树)
传送门 题目分析 每个节点都是一颗(大根堆)左偏树,先按bfs序存入数组,然后倒着从底层开始:如果当前节点的子树sum > m 那么就把根节点删去,然后统计更新答案,并将这棵树和父节点合并. c ...
- Codeforces 39J Spelling Check hash
主题链接:点击打开链接 意甲冠军: 特定2弦 选择中删除一个字符串的第一个字母,得2个字符串全然同样 问哪些位置能够选 思路: hash求前缀后缀.然后枚举位置 #include <cstdio ...
- C# 获取Windows系统:Cpu使用率,内存使用率,Mac地址,磁盘使用率
一.获取CPU使用率: #region 获取CPU使用率 #region AIP声明 [DllImport("IpHlpApi.dll")] ...