Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
audio lext test
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: "__id__",
secretAccessKey: "__secret__",
});
var lexruntime = new AWS.LexRuntime({region: 'us-east-1'});
// // TEXT REQUEST -> TEXT RESPONSE
// var params = {
// botAlias: 'StephenChatEngineExample', // required */
// botName: 'StephenChatEngineExample', // required */
// userId: 'irdfvbdefb', // required */
// inputText: 'yo',
// };
// lexruntime.postText(params, function (err, data) {
// if (err) console.log(err, err.stack); // an error occurred
// else console.log(data); // successful response
// });
// var audioBuffer;
// TEXT REQUEST -> AUDIO AND TEXT RESPONSE
var params = {
botAlias: 'StephenChatEngineExample', /* required */
botName: 'StephenChatEngineExample', /* required */
contentType: 'text/plain; charset=utf-8', /* required */
inputStream: 'hi stephen', /* required */
userId: 'rthrthrthr', /* required */
accept: 'audio/pcm',
};
lexruntime.postContent(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
audioBuffer = data.audioStream;
// audioBuffer = Buffer.from(audioBuffer).toString('base64');
// audioBuffer = Buffer.from(audioBuffer, 'base64').toString('ascii');
// AUDIO REQUEST -> AUDIO AND TEXT RESPONSE
var params = {
botAlias: 'StephenChatEngineExample', /* required */
botName: 'StephenChatEngineExample', /* required */
// accept: 'audio/*',
contentType: 'audio/l16; rate=16000; channels=1',
inputStream: audioBuffer, /* required */
userId: 'rthrthrthrth546h5', /* required */
};
lexruntime.postContent(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.