本文介绍了机器人如何从Facebook Messenger(MP4)接收语音文件并将其转换为Bing或Google等语音引擎可以识别的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Microsoft的Bot Framework为Facebook Messenger创建一个机器人,该机器人将执行以下操作:

I'm trying to make a bot for Facebook Messenger using Microsoft's Bot Framework that will do this:

  • 获取通过Facebook Messenger发送的用户语音消息
  • 将语音转换为文本
  • 用它做点事

从Messenger中获取语音消息没有问题(可以从漫游器收到的消息中提取URL),也可以将音频文件转换为语音(使用Bing Speech API或Google的类似API)也没有问题.

There's no problem with getting the voice message from Messenger (the URL can be extracted from the message the bot receives), and there's also no problem with converting an audio file to speech (using Bing Speech API or Google's similar API).

但是,这些API需要PCM(WAV)文件,而Facebook Messenger可以为您提供MP4文件.

However, these APIs require PCM (WAV) files, while Facebook Messenger gives you an MP4 file.

是否存在一种流行的/标准的方式,可以将一种格式转换为编写机器人时所使用的另一种格式?

Is there a popular/standard way of converting one format into another that is used in writing the bots?

到目前为止,我最好的主意是在服务器上作为控制台作业运行vlc.exe并转换文件,但这听起来并不是最好的解决方案.

So far my best idea is to run vlc.exe as a console job on my server and convert the file, but that doesn't sound like the best solution.

推荐答案

开发了一种如下工作的解决方案:

Developed a solution that works as follows:

  1. 从Facebook接收语音消息
  2. 使用Activity.Attachments
  3. 中的链接将MP4文件下载到本地磁盘
  4. 使用MediaToolKit(FFMPEG的包装器)将MP4/AAC转换为本地服务器上的WAV
  5. 将WAV发送到Bing Speech API
  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

所以我的问题的答案是:使用MediaToolKit + ffmpeg转换文件格式.

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

此处提供示例实现和代码: https://github.com/J3QQ4/Facebook-Messenger-Voice-Message-Converter

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;
    }

这篇关于机器人如何从Facebook Messenger(MP4)接收语音文件并将其转换为Bing或Google等语音引擎可以识别的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 02:31