简体   繁体   中英

Using NAudio for .NET how do I remove the silence wave at the end of mp3 file?

I am working on a C# WPF application that groups a group of words (from about 17,000 words) together and generates a playlist matching mp3 files (each mp3 file being a word).

Currently each mp3 file has a random silence between 1 second to 30 seconds at the end of its wave.

I want to be able to programmatically remove the silence wave from the end of the file.

Using NAudio for .NET how do I remove the silence wave from the end of mp3 file?

There are two ways to trim MP3 files. The first is by using the Mp3FileReader to read out audio as WAV, and only write the amount you want to a new WAV file using the WaveFileWriter. Then you would use a tool such as LAME.exe to convert back to MP3 as NAudio does not include an MP3 encoder.

The second is to discard Mp3Frames and has the benefit of not requiring a decode and re-encode. MP3 files consist of a series of Mp3Frames, (and optionally have metadata such as ID3 tags at the start or end). You could then create a new MP3 file by just appending the MP3 frames you want into a new file, skipping over the last ones (and optionally making sure your ID3 tags got included in the truncated file). Look at the source code for Mp3FileReader to see how the Mp3Frames can be read one by one out of an MP3 file.

I accomplished Using SoX

Doc for SoX Silence: http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/

Stackoverflow Help Reference for SoX Silence end of file: https://stackoverflow.com/a/11834671/677607

Command Line execution using C#: https://stackoverflow.com/a/1469790/677607

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM