MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / streamingRecognize

Function streamingRecognize

speech/recognize.js:338–383  ·  view source on GitHub ↗
(
  filename,
  encoding,
  sampleRateHertz,
  languageCode
)

Source from the content-addressed store, hash-verified

336}
337
338async function streamingRecognize(
339 filename,
340 encoding,
341 sampleRateHertz,
342 languageCode
343) {
344 // [START speech_transcribe_streaming]
345 const fs = require('fs');
346
347 // Imports the Google Cloud client library
348 const speech = require('@google-cloud/speech');
349
350 // Creates a client
351 const client = new speech.SpeechClient();
352
353 /**
354 * TODO(developer): Uncomment the following lines before running the sample.
355 */
356 // const filename = 'Local path to audio file, e.g. /path/to/audio.raw';
357 // const encoding = 'Encoding of the audio file, e.g. LINEAR16';
358 // const sampleRateHertz = 16000;
359 // const languageCode = 'BCP-47 language code, e.g. en-US';
360
361 const request = {
362 config: {
363 encoding: encoding,
364 sampleRateHertz: sampleRateHertz,
365 languageCode: languageCode,
366 },
367 interimResults: false, // If you want interim results, set this to true
368 };
369
370 // Stream the audio to the Google Cloud Speech API
371 const recognizeStream = client
372 .streamingRecognize(request)
373 .on('error', console.error)
374 .on('data', data => {
375 console.log(
376 `Transcription: ${data.results[0].alternatives[0].transcript}`
377 );
378 });
379
380 // Stream an audio file from disk to the Speech API, e.g. "./resources/audio.raw"
381 fs.createReadStream(filename).pipe(recognizeStream);
382 // [END speech_transcribe_streaming]
383}
384
385function streamingMicRecognize(encoding, sampleRateHertz, languageCode) {
386 // [START speech_transcribe_streaming_mic]

Callers 1

recognize.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected