WhatsApp 音频媒体消息 (MediaUrl0) 转录为文本

时间:2021-04-27 12:00:33

标签: twilio dialogflow-es chatbot whatsapp voice-recognition

我有一个对话流聊天机器人,可以通过 Twilio 与 Whatsapp 进行通信,供企业用户使用。

我想增强“聊天”聊天机器人的功能,并允许 whatsapp 用户也能够发送语音消息。

发送到 Twilio 的 WhatsApp 语音媒体消息具有包含媒体文件位置的 URI 参数,但此 URI 没有文件扩展名。我如何提取文件以将其发送到语音转文本服务(Google 或 AWS)以将其转录为文本,然后将其发送到 Dialogflow 以进行意图识别

有什么想法我会怎么做吗?

媒体消息的 Twilio 消息日志:

    Request Inspector
    + Expand All
    POST
    https://xxxxxxxxxxxx
    2021-04-27 08:35:39 UTC502
    Request
    URL
    ParametersShow Raw
    MediaContentType0   "audio/ogg"
    SmsMessageSid   "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
    NumMedia    "1"
    ProfileName "xxxxx"
    SmsSid  "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
    WaId    "xxxxxxxxx"
    SmsStatus   "received"
    Body    ""
    To  "whatsapp:+32460237475"
    NumSegments "1"
    MessageSid  "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
    AccountSid  "ACef27744806d8f8e68f25211b2ba8af60"
    From    "whatsapp:+32474317098"
    MediaUrl0   "https://api.twilio.com/2010-04-01/Accounts/ACef27744806d8f8e68f25211b2ba8af60/Messages/MMea4e6bcb3a9654a03d8d2a607c6d4cdd/Media/ME27fbc66d47d8de49f1ae00e433884097"
    ApiVersion  "2010-04-01"
    Message TextShow Raw
    sourceComponent "14100"
    httpResponse    "502"
    url "https://xxxxxxxxx"
    ErrorCode   "11200"
    LogLevel    "ERROR"
    Msg "Bad Gateway"
    EmailNotification   "false"

1 个答案:

答案 0 :(得分:0)

我认为您不需要此用例的扩展名,您可能需要结果文本的语言代码,可能是转录服务的音频编码和样本评级。

以下是我的 whatson / google coud 语音到文本和 DialogFlow 代码中的一些示例。AWS 和 Microsoft 非常相似

//for ibm watson
RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
     .model(RecognizeOptions.Model.ES_ES_NARROWBANDMODEL)
     .audio(new ByteArrayInputStream(bytes))
     .contentType(HttpMediaType.AUDIO_WAV)
     .build();

// google speech to text
RecognitionConfig config = RecognitionConfig.newBuilder()
     .setSampleRateHertz(48000)
     .setLanguageCode(langcode)
     .setEncoding(RecognitionConfig.AudioEncoding.OGG_OPUS)
     .build();

// Dialogflow (sending audio directly)
 InputAudioConfig inputAudioConfig = InputAudioConfig
     .newBuilder()
     .setLanguageCode(langcode)
     .setSampleRateHertz(sampleRateHertz)
     .build();

最后,在所有情况下,您发送给服务的不是文件而是字节数组(排序)

无论如何,即使内容类型和文件扩展名之间没有一对一的关系,请求中的参数“MediaContentType0”也为您提供了一个很好的起点:“audio/ogg”。

相关问题