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

Function syncRecognizeGCS

speech/recognize.js:70–112  ·  view source on GitHub ↗
(
  gcsUri,
  encoding,
  sampleRateHertz,
  languageCode
)

Source from the content-addressed store, hash-verified

68}
69
70async function syncRecognizeGCS(
71 gcsUri,
72 encoding,
73 sampleRateHertz,
74 languageCode
75) {
76 // [START speech_transcribe_sync_gcs]
77 // Imports the Google Cloud client library
78 const speech = require('@google-cloud/speech');
79
80 // Creates a client
81 const client = new speech.SpeechClient();
82
83 /**
84 * TODO(developer): Uncomment the following lines before running the sample.
85 */
86 // const gcsUri = 'gs://my-bucket/audio.raw';
87 // const encoding = 'Encoding of the audio file, e.g. LINEAR16';
88 // const sampleRateHertz = 16000;
89 // const languageCode = 'BCP-47 language code, e.g. en-US';
90
91 const config = {
92 encoding: encoding,
93 sampleRateHertz: sampleRateHertz,
94 languageCode: languageCode,
95 };
96 const audio = {
97 uri: gcsUri,
98 };
99
100 const request = {
101 config: config,
102 audio: audio,
103 };
104
105 // Detects speech in the audio file
106 const [response] = await client.recognize(request);
107 const transcription = response.results
108 .map(result => result.alternatives[0].transcript)
109 .join('\n');
110 console.log('Transcription: ', transcription);
111 // [END speech_transcribe_sync_gcs]
112}
113
114async function syncRecognizeWords(
115 filename,

Callers 1

recognize.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected