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

Function main

speech/quickstart.js:17–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15'use strict';
16
17function main() {
18 // [START speech_quickstart]
19 // Imports the Google Cloud client library
20 const speech = require('@google-cloud/speech');
21
22 // Creates a client
23 const client = new speech.SpeechClient();
24
25 async function quickstart() {
26 // The path to the remote LINEAR16 file
27 const gcsUri = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw';
28
29 // The audio file's encoding, sample rate in hertz, and BCP-47 language code
30 const audio = {
31 uri: gcsUri,
32 };
33 const config = {
34 encoding: 'LINEAR16',
35 sampleRateHertz: 16000,
36 languageCode: 'en-US',
37 };
38 const request = {
39 audio: audio,
40 config: config,
41 };
42
43 // Detects speech in the audio file
44 const [response] = await client.recognize(request);
45 const transcription = response.results
46 .map(result => result.alternatives[0].transcript)
47 .join('\n');
48 console.log(`Transcription: ${transcription}`);
49 }
50 quickstart();
51 // [END speech_quickstart]
52}
53
54process.on('unhandledRejection', err => {
55 console.error(err.message);

Callers 1

quickstart.jsFile · 0.70

Calls 1

quickstartFunction · 0.70

Tested by

no test coverage detected