|
18 | 18 | const util = require('util');
|
19 | 19 | const fs = require('fs');
|
20 | 20 | const {struct} = require('pb-util');
|
21 |
| -const pump = require('pump'); |
22 |
| -const through2 = require('through2'); |
| 21 | +const {Transform, pipeline} = require('stream'); |
| 22 | + |
| 23 | +const pump = util.promisify(pipeline); |
23 | 24 |
|
24 | 25 | function detectTextIntent(projectId, sessionId, queries, languageCode) {
|
25 | 26 | // [START dialogflow_detect_intent_text]
|
@@ -164,7 +165,7 @@ async function detectAudioIntent(
|
164 | 165 | // [END dialogflow_detect_intent_audio]
|
165 | 166 | }
|
166 | 167 |
|
167 |
| -function streamingDetectIntent( |
| 168 | +async function streamingDetectIntent( |
168 | 169 | projectId,
|
169 | 170 | sessionId,
|
170 | 171 | filename,
|
@@ -227,11 +228,14 @@ function streamingDetectIntent(
|
227 | 228 |
|
228 | 229 | // Stream an audio file from disk to the Conversation API, e.g.
|
229 | 230 | // "./resources/audio.raw"
|
230 |
| - pump( |
| 231 | + await pump( |
231 | 232 | fs.createReadStream(filename),
|
232 | 233 | // Format the audio stream into the request format.
|
233 |
| - through2.obj((obj, _, next) => { |
234 |
| - next(null, {inputAudio: obj}); |
| 234 | + new Transform({ |
| 235 | + objectMode: true, |
| 236 | + transform: (obj, _, next) => { |
| 237 | + next(null, {inputAudio: obj}); |
| 238 | + }, |
235 | 239 | }),
|
236 | 240 | detectStream
|
237 | 241 | );
|
|
0 commit comments