Skip to content

Instantly share code, notes, and snippets.

@seatedro
Created September 16, 2022 17:08
Show Gist options
  • Save seatedro/86acddf28e4eade13f206490993f35a9 to your computer and use it in GitHub Desktop.
Save seatedro/86acddf28e4eade13f206490993f35a9 to your computer and use it in GitHub Desktop.
restartStream() {
if (this.recognizeStream) {
this.recognizeStream.end();
this.recognizeStream.removeAllListeners();
this.recognizeStream = null;
}
if (this.resultEndTime > 0) {
this.finalRequestEndTime = this.isFinalEndTime;
}
this.resultEndTime = 0;
this.lastAudioInput = [];
this.lastAudioInput = this.audioInput;
this.restartCounter++;
if (!this.lastTranscriptWasFinal) {
process.stdout.write("\n");
}
process.stdout.write(
chalk.yellow(
`${this.streamingLimit * this.restartCounter}: RESTARTING REQUEST\n`
)
);
this.newStream = true;
this.startRecognitionStream();
}
/**
* Closes the recognize stream and wipes it
*/
stopRecognitionStream() {
if (this.recognizeStream) {
this.recognizeStream.end();
this.recognizeStream.removeAllListeners();
}
if (this.restartTimeout) {
clearTimeout(this.restartTimeout);
}
this.recognizeStream = null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment