【发布时间】:2021-08-23 22:45:27
【问题描述】:
我正在尝试开发一个应用程序,它将获取音频文件并使用 aws-sdk 将其发送到 Amazon Lex,特别是 lexruntime 到 postContent。
目前我在网络上有音频文件,我正在本地下载这些音频文件,然后尝试将该音频文件的名称放入我的 postContent 参数中。但是,lex 正在返回一个空转录和一个引出意图,这意味着它无法正确处理我的音频文件。这是我下载/发布到 lex 的方式:
var file = fs.createWriteStream("file.wav");
var request = https.get(url, function(response) {
response.pipe(file);
});
var params = {
botAlias: 'prod', /* required */
botName: 'OrderFlowers', /* required */
//inputText: `${command}`, /* required */
contentType: 'audio/x-l16; sample-rate=16000; channel-count=1', /*required */
inputStream: './file.wav',
accept: 'text/plain; charset=utf-8',
userId: 'Test'/* required */
//requestAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */,
//sessionAttributes: any /* This value will be JSON encoded on your behalf with JSON.stringify() */
};
lexruntime.postContent(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data);
});
上面从 Lex 得到以下响应:
{ contentType: 'text/plain;charset=utf-8',
message: 'I didn\'t understand you, what would you like to do?',
messageFormat: 'PlainText',
dialogState: 'ElicitIntent',
inputTranscript: '',
audioStream: <Buffer > }
我知道音频文件已正确下载并且会映射到正确的 Lex 意图,但我认为我没有正确发送音频文件。如果最好永远不要从 URL 本地下载音频文件,我可以接受这种方法。
这里是亚马逊文档:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexRuntime.html
任何帮助将不胜感激。
【问题讨论】:
标签: node.js aws-sdk audio-streaming chatbot amazon-lex