I want to convert a WAV file into a M4A file.
I could not find any reference or any example of how to achieve that.
Naudio should do the trick i assume, but i havent figured out how to do this yet.
I am writing a WebAPI2 project, and i need to return an m4a audio file to the user upon request. Been using a PushStreamContent in order to provide the user with the file, but using an MP3 as the conversion target, lead to many difficulties with browser support and Seek/Pause/Stop support.
Thanks in advance,
Nokky.
M4A files simply contain AAC encoded audio. Have a look at the Media Foundation Encoder demo in the NAudio WPF demo application to see an example of using MediaFoundationEncoder to create AAC files. It will let you encode as aac if you have an appropriate Media Foundation Codec on your machine (you should have with Win 7 and above, although note that it doesn't do low bitrates).
Related
I am writing a cross-platform application for Android, iOS and Windows (Universal) with Xamarin.Forms. Within the application i am trying to implement speech-to-text (in the Dutch language).
At this point i have that my application can record audio files on all platforms however the audio files are not recorded in the correct format for the Cloud Speech API that i am working with. For the API you need to send audio files in the format .Flac, however the audio recorders on the mobile platforms don't support audio recording in the format .Flac.
I am trying to convert the audio recording that is now recorded as a .Wav file the audio file to the .Flac format, however i have not had any success as of jet.
i am trying to use the JavaFlacEncoder, however i am not sure if it would work on within Xamarin on all platforms because it is a Java class.
Could someone help me or give me advise with converting a audio file from .Wav to .Flac?
Thanks in advance.
Michael
There are number of open source C# managed encoders, please check FlacBox or C# Flake. See also Discussion on the latter
You do not need to send flac files to the Google Speech engine. It reads LPCM files as well. LPCM files are WAV files. All you need to know is the bitrate at which your WAV file is sampling. The the basic options can be set as follows:
encoding: 'LINEAR16',
sampleRate: 16000 //<- whatever your sample rate is
I am developing a windows phone 7 application and it does video recording. I would like to get the sound portion of the video file (MP4) and do some enhancements on the sound. I believe sound is saved as AAC frames in MP4. (Right?) How can I extract sound of a videa MP4 file?
Since this is a video file, it can be huge file. So uploading to cloud and processing there is not a good option. Since this WP7 application I cannot use unmaged dlls :( Is there a way to do in pure C#? Any open source tools/samples?
Thanks!
MP4 is a container format and realistically the sound portion isn't always AAC. It could be MP3 or any other number of different audio formats. You may be thinking of M4A, which I believe requires either AAC or ALAC.
On the subject of audio extraction, it should be possible to extract the audio from an MP4 using just managed code. You'll have to read up on the MP4 format (here, for example - this question is also worth reading) and then search through the file for the location of the audio and then either copy it to its own buffer or do your manipulations in chunks. Even then, you'll have to be able to recognize when it isn't an audio format that your app won't support.
It's possible that there already exists a .net library that can do all of this but I don't know of any. It's probably not very popular because managed code is definitely not the best angle to approach this from, but considering this is Windows Phone, it is, as you noted, your only avenue of approach.
Good luck!
I've written a basic SL4 application to capture audio data from the microphone using CaptureSource. The trouble is, it's raw PCM output - which means huge and uncompressed.
Given that I need this application to run purely within a SL4 environment, how can I compress the PCM audio data into something that can be delivered to a remote server more easily?
Essentially I need a solution that I can also deploy/include in a Windows Phone Series 7 application as well as one that will work in the browser environment - so managed code solutions only, I think?
In conversation, people have suggested Speex and WMA for instance, but I haven't found any libraries or examples that work without requiring reference to DLL's that won't work in a SL4 project.
Just a small addition to Jason's post:
There is another port of Speex to .Net and Silverlight 4 called NSpeex.
Please see the WavFileHelper class in Silverlight 4 Rough Notes: Camera and Microphone Support on Mike Taulty's blog (a bit lower than the middle of the page, but the full article is worthwhile) in which he compresses the PCM file to WAV.
Here's another example of when writing to WAV you can change values such as Mono/Stereo, which will directly change the size of the WAV file: Audio recorder Silverlight 4 sample. And one more that gives more details about writing to WAV: Creating Sound using MediaStreamSource in Silverlight 3 Beta
Take a look at this. It looks like he has ported the Speex encoder to C# for the exact problem you are trying to solve. It is available here. Speex is designed for speech and should perform better than wma, mp3, or other audio codecs that are designed to handle music if you are just encoding speech, which I assume since you are grabbing from the mic.
This article http://alvas.net/alvas.audio,articles.aspx#how-to-save-audio-to-mp3-on-silverlight about save audio on client. To send audio data to a server you can use WebClient, for example.
You can do encoding thru the server, by send all stream to WCF service and do your encoding thru Microsoft Expression Encoding SDK API.
Please, see this url that i have asked before:
http://forums.silverlight.net/forums/t/181141.aspx
Regards
I want to transcode a lot of audio from its source format to PCM without resampling or messing with the sample size. I figure if Windows Media Player can play the file and it doesn't use a legacy ACM codecs it must be using DirectSound to do so (this is on Windows XP and Windows Server 2k3). So is it possible to access DirectSound from C# and do so? I've tried searching the web but all the examples have been about playback which I have no interest in doing.
DirectSound is an audio playback API, you mean DirectShow. Windows Media player does use DirectShow to play audio files. In theory, all you need to do is build the same playback graph that media player uses, but replace the audio driver on the end with a .WAV writer filter.
This is somewhat easier to do in C++ code, since the DirectShow graph object is really designed to be called from C++, but with a good set of interop definitions, you can do this in C#.
There's http://directshownet.sourceforge.net/ for serious hacking with DirectShow in .NET, but that's probably overkill for your problem.
I would suggest getting a copy of GraphEdit if you don't already have one. You can use it to "prototype" direct show graphs interactively. drop a file into graphedit. then delete the filter on the end and replace it with a file writer filter.
One problem you will have is that there is no .WAV file writer filter in the default set of o DirectShow filters, you will have to find or write one.
If you just want to get the files converted, and could care less about learning how to write code using DirectShow, I would suggest that you just get a copy of Sound Forge (possibly even a demo version). It has a scripting language (C#,vb) that can be used to easily batch process most audio file formats.
Conversion to WAV can be done from the Windows command line using SoX (Sound eXchange, http://sox.sourceforge.net/). You could write a batch file or a C# application that calls SoX with the proper attributes. I'm not sure how WinAMP's feature works specifically, but it has a file writer output option built in as well. You can stream the entire playlist to wave files.
Have a look at this article on CodeProject about audio conversion here and here.
I want to change an audio file format into another. Specifically, I want to convert any audio file into 6khz, 16 bit, mono, PCM wav format.
How can I cope with this problem.
Thanks again in advance.
You can also do this using the open source C# audio library NAudio. Have a look at the NAudioDemo project for an example of passing WAV files through the ACM codecs installed on your machine to convert to another format. If your input file is not WAV or MP3, you will first need something that converts it to WAV though.
I would use the BASS Library. It has many possibilities to do format conversions using the built in encoding/decoding capabilities. It also has a .NET wrapper availabe.
I'm not entirely sure whether you'll be able to do this as well as you may like.
To start with refer to the windows API for dealing with RIFF files (that's the file group for WAV files.)
You'll need to read the headers, extract the data and uncompress it to get the raw data format. I beleive that the header data will tell you what codec was used for compression.
You'll need to perform some processing on the raw data. Conversion to mono and 16bit may not be a problem, but I'm not too sure about changes to the sampling rate.
You can then recompress using your specified codec.