Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert WAV to WMA using .NET

Tags:

.net

audio

wma

What is the best solution for converting WAV files to WMA (and vice versa) in C#? I have actually implemented this once already using the Windows Media Encoder SDK, but having to distribute Windows Media Encoder with my application is cumbersome to say the least. The Windows Media Format SDK has large sections of the API marked as deprecated. It looks like there might be some DirectX Media Objects (DMOs) I could use from the Windows SDK, but there would be an awful lot of interop to write.

I am wondering if there perhaps is a good managed wrapper for an unmanaged library that can perform the conversions. It would need a license that allows it to be distributed as part of a closed source commercial application.

like image 826
Mark Heath Avatar asked Sep 15 '08 16:09

Mark Heath


3 Answers

I haven't tried it personally (so not sure if it's the 'best' solution), but http://www.codeproject.com/KB/audio-video/WmaCompressor.aspx looks like it should meet your requirements...

like image 200
mdb Avatar answered Sep 27 '22 23:09

mdb


You can take a look at the BASS library. It has add-ons, such as BASSWMA and BASSEnc for doing encoding/decoding. All its API's are accessible from .NET using the BASS.Net wrapper.

Both BASS and BASS.Net could be licensed for commercial use, with a reasonable fee (€100 each).

like image 42
Magnus Johansson Avatar answered Sep 28 '22 00:09

Magnus Johansson


If you're comfortable writing a bit of C++/CLI then you don't need much code to create a wrapper around DirectShow to do this. This can then be called directly from a C# assembly with no need to mess about with interop. Doing it with DirectShow is much easier than using WMF directly because you don't have to do any file parsing or I/O - it's all done for you. For reference, I have code in a commercial app that can encode/decode WMA to/from WAV files in less than 100 lines of C++, all wrapped up in a friendly .Net class. Judicious use of smart pointers helps if you go down this route...

like image 27
Stu Mackellar Avatar answered Sep 27 '22 22:09

Stu Mackellar