How to merge two or more mp3 files programmatically in C#

Photo by: Dan Stark

As part of the Music Tech Fest #MTFLabs event (25–28 November, 2017), I created a simple mashup program using C# and the naudio library.

The overall idea was about registering music on blockchain for attribution to the respective music creators. To showcase this, we used a simple flow of creating mashups by merging audio (mp3) files using this program, uploading the mashed-up files to a cloud based storage (we used Azure blob storage in this case) and then finally creating assets on a BigchainDB based blockchain, having links of the respective mashup files.

Here’s the GitHub gist showing how to merge mp3 files using C#.

The list of files (to be merged) was selected by individuals in the live audience using a simple React-Redux web app. This web app then sent the selected track names to an ASP.Net API which passed them to this mp3 merge method via the input array.

The input files were pre-uploaded music tracks created by artists participating at the #MTFLabs. The mp3 merge method then picked up the selected files from a local directory, merged them using the naudio C# library, and then returned the path of the mashed-up output mp3 file (after writing it in a local folder).

This mashed-up mp3 file was then uploaded to Azure blob storage. The uploaded blob’s URI was recorded in a BigchainDB transaction along with the details of the creator.

Every audience member who submitted selections through this web app, created music and registered it on blockchain, on the fly.

The full code for all three applications (web app, mashup API and BigchainDB client API) is available at my mtf-mashup GitHub repository. The method to merge mp3 files is in the AudioService.cs class. Please check the readme.md file of this repository for more technical details on the overall solution.

Audio Editing, C#, MP3 Merge, NAudio, .Net
comments powered by Disqus