Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created May 1, 2018 00:32
Show Gist options
  • Save ajb413/2ecb9a85b379a3a9ff08e27029ef5454 to your computer and use it in GitHub Desktop.
Save ajb413/2ecb9a85b379a3a9ff08e27029ef5454 to your computer and use it in GitHub Desktop.
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