# NAudio **Repository Path**: weivyuan/NAudio ## Basic Information - **Project Name**: NAudio - **Description**: Audio and MIDI library for .NET - **Primary Language**: C# - **License**: MS-PL - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2019-02-27 - **Last Updated**: 2023-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Naudio是一个.Net平台的开源库,由 [Mark Heath](https://markheath.net) 开源. ![NAudio logo](naudio-logo.png) ## 特点 * API支持的播放模式 * WaveOut * DirectSound * ASIO * WASAPI * 支持音频格式 * WAV * AIFF * MP3 (ACM/DMO/MFT) * G.711 mu-law and a-law * ADPCM, G.722, Speex (NSpeex) * WMA, AAC, MP4 等媒体文件 * 在各种形式的未压缩音频之间转换 * 单声道和立体声转换 * 比特率转换 (如8bit/16bit/24bit/32bit等遵循IEEE标准的比特率) * 音频采样率转换 * 创建新的音频 * 创建 MP3 文件 (Windows 8 or latter) * 创建 AAC/MP4 音频文件 (Windows 7 or latter) * 创建 WMA 文件 * 创建 WAV 文件 包括 G.711, ADPCM, G.722, etc. * 使用32位浮动混合引擎混合和操作音频流 * construct signal chains * examine sample levels for the purposes of metering or waveform rendering * pass blocks of samples through an FFT for metering or DSP * 延迟/循环/淡入/淡出 * Perform EQ with a BiQuad filter (allowing low pass, high pass, peaking EQ, etc.) * Pitch shifting of audio with a phase vocoder * 使用各种捕获API录制音频 * WaveIn * WASAPI * ASIO * 使用WASAPI录制系统音频 * 声卡 * 列举音频设备 * 访问声卡控制和测量信息 * 完整的MIDI事件模型 * 读写MIDI文件 * 响应MIDI事件 * 发送MIDI事件 * 易于扩展 * 所有的基类都很容易从中继承,以便添加自定义组件 * 初步支持UWP应用 * 创建Windows商店应用程序和Windows通用应用程序 ## 入门 推荐使用 Nuget 方式获取 [NAudio NuGet](https://www.nuget.org/packages/NAudio/). 预发行版本也会在Nuget上提供.或者直接在[这里](https://github.com/naudio/NAudio/releases)下载动态库. NAudio 源码中附带了多个演示程序.您可以从中下载已编译的[演示应用程序](https://github.com/naudio/NAudio/releases),并浏览[源代码](https://github.com/naudio/NAudio/tree/master/NAudioDemo). ## 教程 ### 文档指引 - [在Winform程序中播放音频文件](Docs/PlayAudioFileWinForms.md) - [在控制台程序中播放音频文件](Docs/PlayAudioFileConsoleApp.md) - [播放网络中的音频文件](Docs/PlayAudioFromUrl.md) - [选择音频输出设备类型](Docs/OutputDeviceTypes.md) - [枚举并选择输出设备](Docs/EnumerateOutputDevices.md) - [创建和配置WasapiOut设备](Docs/WasapiOut.md) - [实现"Fire and Forget"回放 (e.g. game sound effects)](http://markheath.net/post/fire-and-forget-audio-playback-with) - [播放MP3流](http://markheath.net/post/how-to-play-back-streaming-mp3-using) - [播放和停止播放](Docs/PlaybackStopped.md) - [了解 WaveStream, IWavePlayer 和 ISampleProvider](Docs/WaveProviders.md) - [通过ASIO方式播放音频文件](Docs/AsioPlayback.md) ### 编码/解码器使用 - [MP3 转 WAV](Docs/ConvertMp3ToWav.md) - [使用MediaFoundationEncoder编码MP3和其他音频](Docs/MediaFoundationEncoder.md) - [其他样例](http://markheath.net/post/naudio-mediafoundationencoder) - [Understand how to convert between any audio formats you have codecs for](http://www.codeproject.com/Articles/501521/How-to-convert-between-most-audio-formats-in-NET) - [Enumerate Media Foundation Transforms (MFTs)](Docs/EnumerateMediaFoundationTransforms.md) - [Enumerate ACM Codecs](Docs/EnumerateAcmDrivers.md) - [Fix the NoDriver calling acmFormatSuggest issue](http://markheath.net/post/nodriver-calling-acmformatsuggest) ### 使用音频文件 - [混合两个音频文件为WAV](Docs/MixTwoAudioFilesToWav.md) - [裁剪WAV文件](http://markheath.net/post/trimming-wav-file-using-naudio) - [合并MP3文件](http://markheath.net/post/merging-mp3-files-with-naudio-in-c-and) - [AIFF转WAV](http://markheath.net/post/how-to-convert-aiff-files-to-wav-using) - [如何使用WavFileWriter类](http://markheath.net/post/how-to-use-wavefilewriter) - [创建ID3v2标记](http://naudio.codeplex.com/wikipage?title=Create%20an%20ID3v2%20Tag) ### 控制音频 - [单声道和立体声转换](Docs/ConvertBetweenStereoAndMono.md) - [Concatenating Audio](Docs/ConcatenatingAudio.md) - [Skip and Take Using OffsetSampleProvider](Docs/OffsetSampleProvider.md) - [循环播放](http://markheath.net/post/looped-playback-in-net-with-naudio) - [使用多声道音频](http://markheath.net/post/handling-multi-channel-audio-in-naudio) - [音频采样](Docs/Resampling.md) - [Input driven Audio Resampling](http://markheath.net/post/input-driven-resampling-with-naudio-using-acm) - [如何使用RawSourceWaveStream](Docs/RawSourceWaveStream.md) - [Adjust the pitch of audio using SmbPitchShiftingSampleProvider](Docs/SmbPitchShiftingSampleProvider.md) - [Varispeed playback with NAudio using SoundTouch](http://markheath.net/post/varispeed-naudio-soundtouch) - [淡入淡出音频](Docs/FadeInOutSampleProvider.md) ### 生成音频 - [播放正弦波和其他信号类型](Docs/PlaySineWave.md) - [Implement sine wave with portamento](http://markheath.net/post/naudio-sine-portamento) ### 录制 - [Recording a WAV file from a WinForms application](Docs/RecordWavFileWinFormsWaveIn.md) - [Capturing system audio with WasapiLoopbackCapture](Docs/WasapiLoopbackCapture.md) - [Play and Record audio at the same time](http://markheath.net/post/how-to-record-and-play-audio-at-same) - [Record Audio with ASIO](Docs/AsioRecording.md) ### 可视化 - [WaveForm Rendering to PNG](Docs/WaveFormRendering.md) - [Implement a Recording Level Meter](Docs/RecordingLevelMeter.md) ### MIDI - [Sending and Receiving MIDI Events](Docs/MidiInAndOut.md) - [Exploring MIDI Files with MidiFile](Docs/MidiFile.md) - [MIDI Event types](Docs/MidiEvent.md) ### 其他... Additional sources of documentation for NAudio are: - [Original Documentation on CodePlex](http://naudio.codeplex.com/documentation) - [NAudio articles on Mark Heath's blog](http://markheath.net/category/naudio) ## NAudio 培训 If you want to get up to speed as quickly as possible with NAudio programming, I recommend you watch these two Pluralsight courses. You will need to be a subscriber to access the content, but there is 10 hours of training material on NAudio, and it also will give you access to their vast training library on other programming topics. - [Digital Audio Fundamentals](http://pluralsight.com/training/Courses/TableOfContents/digital-audio-fundamentals) - [Audio Programming with NAudio](http://pluralsight.com/training/Courses/TableOfContents/audio-programming-naudio) To be successful developing applications that process digital audio, there are some key concepts that you need to understand. To help developers quickly get up to speed with what they need to know before trying to use NAudio, I have created the [Digital Audio Fundamentals](http://pluralsight.com/training/Courses/TableOfContents/digital-audio-fundamentals) course, which covers sample rates, bit depths, file formats, codecs, decibels, clipping, aliasing, synthesis, visualisations, effects and much more. In particular, the fourth module on signal chains is vital background information if you are to be effective with NAudio. [Audio Programming with NAudio](http://pluralsight.com/training/Courses/TableOfContents/audio-programming-naudio) is a follow-on course which contains seven hours of training material covering all the major features of NAudio. It is highly recommended that you take this course if you intend to create an application with NAudio. ## 我能做什么...? The best way to learn how to use NAudio is to download the source code and look at the two demo applications - [NAudioDemo](https://github.com/naudio/NAudio/tree/master/NAudioDemo) and [NAudioWpfDemo](https://github.com/naudio/NAudio/tree/master/NAudioWpfDemo). These demonstrate several of the key capabilities of the NAudio framework. They also have the advantage of being kept up to date, whilst some of the tutorials you will find on the internet refer to old versions of NAudio. ## FAQ **NAudio是什么?** NAudio is an open source audio API for .NET written in C# by Mark Heath, with contributions from many other developers. It is intended to provide a comprehensive set of useful utility classes from which you can construct your own audio application. **用NAudio的理由?** NAudio was created because the Framework Class Library that shipped with .NET 1.0 had no support for playing audio. The System.Media namespace introduced in .NET 2.0 provided a small amount of support, and the MediaElement in WPF and Silverlight took that a bit further. The vision behind NAudio is to provide a comprehensive set of audio related classes allowing easy development of utilities that play or record audio, or manipulate audio files in some way. **我能在项目中使用NAudio类库吗?** NAudio is licensed under the Microsoft Public License (Ms-PL) which means that you can use it in whatever project you like including commercial projects. Of course we would love it if you share any bug-fixes or enhancements you made to the original NAudio project files. **Is .NET Performance Good Enough for Audio?** While .NET cannot compete with unmanaged languages for very low latency audio work, it still performs better than many people would expect. On a fairly modest PC, you can quite easily mix multiple WAV files together, including pass them through various effects and codecs, play back glitch free with a latency of around 50ms. **遇到问题我能在哪里获取帮助及提问?** There are three main ways to get help. First, you can raise an issue here on GitHub. This is the best option when you've written some code and want to ask why it's not working as you expect. I attempt to answer all questions, but since this is a spare time project, occasionally I get behind. You can also ask on StackOverflow and [tag your question with naudio](http://stackoverflow.com/questions/tagged/naudio), if your question is a "how do I..." sort of question. This gives you a better chance of getting a quick answer. Please try to search first to see if your question has already been answered elsewhere. Finally, I am occasionally able to offer paid support for situations where you need quick advice, bugfixes or new features. Please contact Mark Heath directly if you wish to pursue this option. **How do I submit a patch?** I welcome contributions to NAudio and have accepted many patches, but if you want your code to be included, please familiarise yourself with the following guidelines: - Your submission must be your own work, and able to be released under the MS-PL license. - You will need to make sure your code conforms to the layout and naming conventions used elsewhere in NAudio. - Remember that there are many existing users of NAudio. A patch that changes the public interface is not likely to be accepted. - Try to write "clean code" - avoid long functions and long classes. Try to add a new feature by creating a new class rather than putting loads of extra code inside an existing one. - I don't usually accept contributions I can't test, so please write unit tests (using NUnit) if at all possible. If not, give a clear explanation of how your feature can be unit tested and provide test data if appropriate. Tell me what you did to test it yourself, including what operating systems and soundcards you used. - If you are adding a new feature, please consider writing a short tutorial on how to use it. - Unless your patch is a small bugfix, I will code review it and give you feedback. You will need to be willing to make the recommended changes before it can be integrated into the main code. - Patches should be provided using the Pull Request feature of GitHub. - Please also bear in mind that when you add a feature to NAudio, that feature will generate future support requests and bug reports. Are you willing to stick around on the forums and help out people using it?