Created
February 3, 2020 17:28
-
-
Save dalequark/f15eec20fbdce9aed34f26c2b9b33d77 to your computer and use it in GitHub Desktop.
DF Stream Promise
This file contains 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
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