audio - 如何为 Alexa Voice 编码音频?

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

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

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

对于音频文件,AVS 文档只说 Type: Binary Data. Represents the data for the audio.
这是我发送的请求:

header

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

body
--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--

知道有什么问题/缺少吗?

最佳答案

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

关于audio - 如何为 Alexa Voice 编码音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32673998/

相关文章:

matlab - 在Matlab中读取和播放PCM音频

ios - Amazon S3 iOS SDK 照片上传有时会出错 - SignatureDoesNotMatch

amazon-web-services - 如果位置!= 美国,则使用 Amazon MechanicalTurk?

python - 在 Python 3 中,如何从字符串中删除所有非 UTF8 字符?

python - 如何在 python 3 中检查字符串是否为 100% ascii

java - 将字节数组编码解码为字符串而不丢失数据

javascript - 音频文件未在 tampermonkey 上使用用户脚本播放

javascript - 带有录音的视频与Internet Explorer兼容

c# - 从数组中的音频字节获取诸如音高或振幅之类的信息

amazon-web-services - 来自亚马逊产品 API 的多项优惠