How can a bot receive a voice file from Facebook Messenger (MP4) and convert it to a format that is recognized by speech engines like Bing or Google?

拈花ヽ惹草 提交于 2019-12-06 12:48:36

Developed a solution that works as follows:

  1. Receive voice message from facebook
  2. Download the MP4 file to local disk using the link inside Activity.Attachments
  3. Use MediaToolKit (wrapper for FFMPEG) to convert MP4/AAC to WAV on local server
  4. Send the WAV to Bing Speech API

So the answer to my question is: use MediaToolKit+ffmpeg to convert the file format.

Sample implementation and code here: https://github.com/J3QQ4/Facebook-Messenger-Voice-Message-Converter

    public string ConvertMP4ToWAV()
    {
        var inputFile = new MediaFile { Filename = SourceFileNameAndPath };
        var outputFile = new MediaFile { Filename = ConvertedFileNameAndPath };

        using (var engine = new Engine(GetFFMPEGBinaryPath()))
        {
            engine.Convert(inputFile, outputFile);
        }

        return ConvertedFileNameAndPath;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!