5

My goal is to write C# that turns Microsoft LYNC meeting audio into text. Here is my project so far. Initially I was trying to record from microphone, save it to WAV then convert WAV to FLAC and using GoogleSpeechAPI, convert FLAC to text. But I got stuck recording microphone audio to WAV format.

The problem is it needs to be in a very specific WAV format, i.e. int16 or int24 for the WAV to work with the WAV to FLAC convertion method. I kept recording 8 bits per sample instead of (16 or 24 bits) per sample.

So, starting over. Microsoft Lync directly records meetings and saves it as a video in MP4 format. If I can somehow write code to convert MP4 to FLAC, that would also solve my problem. Any code example?

Ian
  • 1,152
  • 1
  • 14
  • 27
Awesome_girl
  • 434
  • 3
  • 8
  • 28

1 Answers1

6

I recently had a ASP.NET MVC 5 application where I needed to convert .mp4 to .webm and this worked successfully, so this is an idea to apply the same concept that worked with video files but in this instance they would be audio files.

First, you would download the FFMPEG executable and copy it to a folder inside your project/solution.

The command to convert your audio file to a FLAC would be something like this:

ffmpeg -i audio.xxx -c:a flac audio.flac

You can wrap this inside a C# method to execute FFMPEG like this:

public string PathToFfmpeg { get; set; }    

public void ToFlacFormat(string pathToMp4, string pathToFlac)
{
    var ffmpeg = new Process
    {
        StartInfo = {UseShellExecute = false, RedirectStandardError = true, FileName = PathToFfmpeg}
    };

    var arguments =
        String.Format(
            @"-i ""{0}"" -c:a flac ""{1}""", 
            pathToMp4, pathToFlac);

    ffmpeg.StartInfo.Arguments = arguments;

    try
    {
        if (!ffmpeg.Start())
        {
            Debug.WriteLine("Error starting");
            return;
        }
        var reader = ffmpeg.StandardError;
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            Debug.WriteLine(line);
        }
    }
    catch (Exception exception)
    {
        Debug.WriteLine(exception.ToString());
        return;
    }

    ffmpeg.Close();
}
Jonathan Kittell
  • 5,833
  • 12
  • 42
  • 79