In this post I am going to explain how the NAudio WaveFileReader class can be used to get wave audio
length.
NAudio
is an open source .NET audio and MIDI library, containing dozens of useful
audio related classes intended to speed development of audio related utilities
in .NET.
Below
are the simple steps to get audio duration of any audio or video file.
·
Install
NAudio using nuget package manager console using below command in your .Net
Application.
·
PM>
Install-Package NAudio
·
In
your c# code download the file using web client:
WebClient wc = new WebClient();
var bytes= wc.DownloadData(“Your AudioFile URL”) ;
Stream downloadedStream= new MemoryStream(bytes);
NAudio.Wave.WaveFileReader reader= new NAudio.Wave.WaveFileReader(downloadedStream)
Var audioLength=reader.TotalTime; //we can get audio duration here…
Apart from
the audio length feature NAudio has many more contrasting features.
NAudio Features
·
Play back audio using a variety of
APIs
o WaveOut
o DirectSound
o ASIO
o WASAPI (Windows Vista and above)
·
Decompress audio from different Wave
Formats
o MP3 decode using ACM or DMO codec
o AIFF
o G.711 mu-law and a-law
o ADPCM
o G.722
o Speex (using NSpeex)
o SF2 files
o Decode using any ACM codec installed on your computer
·
Record audio using WaveIn, WASAPI or
ASIO
·
Read and Write standard .WAV files
·
Mix and manipulate audio streams
using a 32 bit floating mixing engine
·
Extensive support for reading and
writing MIDI files
·
Full MIDI event model
·
Basic support for Windows Mixer APIs
·
A collection of useful Windows Forms
Controls
·
Some basic audio effects, including a
compressor
No comments:
Post a Comment