Skip to content

Instantly share code, notes, and snippets.

@dalequark
Created February 3, 2020 17:28
Show Gist options
  • Save dalequark/f15eec20fbdce9aed34f26c2b9b33d77 to your computer and use it in GitHub Desktop.
Save dalequark/f15eec20fbdce9aed34f26c2b9b33d77 to your computer and use it in GitHub Desktop.
DF Stream Promise
let queryResult;
return new Promise(resolve => {
let silent = true
detectStream.on('data', data => {
if (data.recognitionResult) {
silent = false
console.log(
`Intermediate transcript: ${data.recognitionResult.transcript}`
);
if (data.recognitionResult.isFinal) {
console.log("Result Is Final");
recording.stop();
}
}
if (data.queryResult) {
console.log(`Fulfillment text: ${data.queryResult.fulfillmentText}`);
queryResult = data.queryResult;
}
if (data.outputAudio && data.outputAudio.length) {
resolve({"audio" : data.outputAudio, "queryResult" : queryResult});
pumpStream.end();
}
});
detectStream.write(makeInitialStreamRequestArgs(sessionId));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment