-
-
Save mjurincic/558221fd8bb6c0819638af75b6fce95a to your computer and use it in GitHub Desktop.
Streaming Polly Audio into Lex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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