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

Function syncRecognize

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

Source from the content-addressed store, hash-verified

23'use strict';
24
25async function syncRecognize(
26 filename,
27 encoding,
28 sampleRateHertz,
29 languageCode
30) {
31 // [START speech_transcribe_sync]
32 // Imports the Google Cloud client library
33 const fs = require('fs');
34 const speech = require('@google-cloud/speech');
35
36 // Creates a client
37 const client = new speech.SpeechClient();
38
39 /**
40 * TODO(developer): Uncomment the following lines before running the sample.
41 */
42 // const filename = 'Local path to audio file, e.g. /path/to/audio.raw';
43 // const encoding = 'Encoding of the audio file, e.g. LINEAR16';
44 // const sampleRateHertz = 16000;
45 // const languageCode = 'BCP-47 language code, e.g. en-US';
46
47 const config = {
48 encoding: encoding,
49 sampleRateHertz: sampleRateHertz,
50 languageCode: languageCode,
51 };
52 const audio = {
53 content: fs.readFileSync(filename).toString('base64'),
54 };
55
56 const request = {
57 config: config,
58 audio: audio,
59 };
60
61 // Detects speech in the audio file
62 const [response] = await client.recognize(request);
63 const transcription = response.results
64 .map(result => result.alternatives[0].transcript)
65 .join('\n');
66 console.log('Transcription: ', transcription);
67 // [END speech_transcribe_sync]
68}
69
70async function syncRecognizeGCS(
71 gcsUri,

Callers 1

recognize.jsFile · 0.85

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected