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

Function asyncRecognizeGCS

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

Source from the content-addressed store, hash-verified

225}
226
227async function asyncRecognizeGCS(
228 gcsUri,
229 encoding,
230 sampleRateHertz,
231 languageCode
232) {
233 // [START speech_transcribe_async_gcs]
234 // Imports the Google Cloud client library
235 const speech = require('@google-cloud/speech');
236
237 // Creates a client
238 const client = new speech.SpeechClient();
239
240 /**
241 * TODO(developer): Uncomment the following lines before running the sample.
242 */
243 // const gcsUri = 'gs://my-bucket/audio.raw';
244 // const encoding = 'Encoding of the audio file, e.g. LINEAR16';
245 // const sampleRateHertz = 16000;
246 // const languageCode = 'BCP-47 language code, e.g. en-US';
247
248 const config = {
249 encoding: encoding,
250 sampleRateHertz: sampleRateHertz,
251 languageCode: languageCode,
252 };
253
254 const audio = {
255 uri: gcsUri,
256 };
257
258 const request = {
259 config: config,
260 audio: audio,
261 };
262
263 // Detects speech in the audio file. This creates a recognition job that you
264 // can wait for now, or get its result later.
265 const [operation] = await client.longRunningRecognize(request);
266 // Get a Promise representation of the final result of the job
267 const [response] = await operation.promise();
268 const transcription = response.results
269 .map(result => result.alternatives[0].transcript)
270 .join('\n');
271 console.log(`Transcription: ${transcription}`);
272 // [END speech_transcribe_async_gcs]
273}
274
275async function asyncRecognizeGCSWords(
276 gcsUri,

Callers 1

recognize.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected