【问题标题】:How to encode audio for Alexa Voice?如何为 Alexa Voice 编码音频?
【发布时间】:2015-12-16 21:36:38
【问题描述】:

我想使用亚马逊的 Alexa 语音服务 (AVS),但是当我使用 Recognize Speech Request 时,我得到的只是“{message: null}”。身份验证有效,请求似乎正确,因为当身份验证失败或请求格式错误时,我从 API 收到错误消息。

我有一个 wav 音频文件,16000 Hz,1 声道,并使用 PHP 的 base64_encode() 对 wav 文件的内容进行编码。

对于音频文件,AVS 文档只写了Type: Binary Data. Represents the data for the audio.

这是我要发送的请求:

标题

POST /v1/avs/speechrecognizer/recognize HTTP/1.1
Host: access-alexa-na.amazon.com
Content-Type: multipart/form-data; boundary=86371ffc080fbb6fc614e8e36d0b8a4d
Authorization: Bearer Atza|IQEBL... (valid token)
Transfer-Encoding: chunked
Cache-Control: no-cache

身体

--86371ffc080fbb6fc614e8e36d0b8a4d
Content-Disposition: form-data; name="request"
Content-Type: application/json; charset=UTF-8

{
    "messageHeader": {
        "deviceContext": [
            {
                "name":"playbackState",
                "namespace":"AudioPlayer",
                "payload": {
                    "streamId": "xxxxxxxxxxxx",
                    "offsetInMilliseconds": "xxxxxxxxxxxx",
                    "playerActivity": "xxxxxxxxxxxx"
                }
            }
        ]
    },
    "messageBody": {
        "profile": "alexa-close-talk",
        "locale": "en-us",
        "format": "audio/L16; rate=16000; channels=1"
    }
}

--86371ffc080fbb6fc614e8e36d0b8a4d
Content-Disposition: form-data; name="audio"
Content-Type: audio/L16; rate=16000; channels=1

SUQzAgAAAAAQS1RUMgAAFwBhb...(truncated result of base64_encode(file.wav))
--86371ffc080fbb6fc614e8e36d0b8a4d--

知道有什么问题/遗漏了吗?

【问题讨论】:

    标签: audio amazon encode amazon-echo alexa-voice-service


    【解决方案1】:

    音频文件的编码应该是线性 PCM 而不是 base 64。希望这会有所帮助

    【讨论】:

    • 请原谅这个相当愚蠢的问题,但我是否只需将二进制文件内容复制到帖子正文中(如5249 4646 b80a 0200 5741 5645 666d 7420...)?
    【解决方案2】:

    POST 正文应包含原始音频二进制数据。您可以使用 sox 之类的工具将音频转换为 AVS 期望的格式,即单声道、16k Hz 采样率、带符号的 16 位 PCM。

    【讨论】:

      猜你喜欢
      • 2018-02-15
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 1970-01-01
      相关资源
      最近更新 更多