Skip to content

Instantly share code, notes, and snippets.

@mjurincic
Forked from chrisradek/lex-stream.js
Created October 11, 2017 11:27
Show Gist options
  • Save mjurincic/558221fd8bb6c0819638af75b6fce95a to your computer and use it in GitHub Desktop.
Save mjurincic/558221fd8bb6c0819638af75b6fce95a to your computer and use it in GitHub Desktop.
Streaming Polly Audio into Lex
var path = require('path');
var fs = require('fs');
var AWS = require('aws-sdk');
var polly = new AWS.Polly();
var lexRuntime = new AWS.LexRuntime();
async function run() {
var audioStream = polly.synthesizeSpeech({
OutputFormat: 'pcm',
Text: 'It was the best of times, it was the worst of times',
VoiceId: 'Amy',
SampleRate: '16000',
TextType: 'text'
}).createReadStream();
var lexData = await lexRuntime.postContent({
botName: 'NAME',
botAlias: 'ALIAS',
contentType: 'audio/l16; rate=16000; channels=1',
inputStream: audioStream,
userId: 'ID'
}).promise();
console.log(lexData)
console.log(lexData.inputTranscript);
// save lex response
fs.writeFileSync(path.join(__dirname, 'lex-response.mp3'), lexData.audioStream);
}
run().then(console.log).catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment