Skip to content

Commit 31d00e3

Browse files
stephenplusplusAce Nassri
authored andcommitted
fix(samples): use writable stream (#597)
1 parent 2752a3e commit 31d00e3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

speech/infiniteStreaming.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function infiniteStream(
5959
// const streamingLimit = 10000; // ms - set to low number for demo purposes
6060

6161
const chalk = require('chalk');
62-
const {Transform} = require('stream');
62+
const {Writable} = require('stream');
6363

6464
// Node-Record-lpcm16
6565
const recorder = require('node-record-lpcm16');
@@ -146,8 +146,8 @@ function infiniteStream(
146146
}
147147
};
148148

149-
const audioInputStreamTransform = new Transform({
150-
transform: (chunk, encoding, callback) => {
149+
const audioInputStreamTransform = new Writable({
150+
write(chunk, encoding, next) {
151151
if (newStream && lastAudioInput.length !== 0) {
152152
// Approximate math to calculate time of chunks
153153
const chunkTime = streamingLimit / lastAudioInput.length;
@@ -178,7 +178,13 @@ function infiniteStream(
178178
recognizeStream.write(chunk);
179179
}
180180

181-
callback();
181+
next();
182+
},
183+
184+
final() {
185+
if (recognizeStream) {
186+
recognizeStream.end();
187+
}
182188
},
183189
});
184190

0 commit comments

Comments
 (0)