Skip to content

Commit

Permalink
fix(samples): use writable stream (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored May 15, 2020
1 parent a7fa3f3 commit cc12415
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions speech/infiniteStreaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function infiniteStream(
// const streamingLimit = 10000; // ms - set to low number for demo purposes

const chalk = require('chalk');
const {Transform} = require('stream');
const {Writable} = require('stream');

// Node-Record-lpcm16
const recorder = require('node-record-lpcm16');
Expand Down Expand Up @@ -146,8 +146,8 @@ function infiniteStream(
}
};

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

callback();
next();
},

final() {
if (recognizeStream) {
recognizeStream.end();
}
},
});

Expand Down

0 comments on commit cc12415

Please sign in to comment.