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

Function main

speech/transcribeFile.v2.js:21–56  ·  view source on GitHub ↗
(recognizerName, audioFilePath = 'resources/brooklyn.flac')

Source from the content-addressed store, hash-verified

19// description: Transcribe a local file using Speech-to-Text v2
20
21async function main(recognizerName, audioFilePath = 'resources/brooklyn.flac') {
22 // [START speech_transcribe_file_v2]
23
24 /**
25 * TODO(developer): Uncomment these variables before running the sample.
26 */
27 // const recognizerName= "projects/[PROJECT_ID]/locations/[LOCATION]/recognizers/[RECOGNIZER_ID]";
28 // const audioFilePath = "path/to/audio/file";
29
30 // Import the Cloud Speech-to-Text library
31 const speech = require('@google-cloud/speech').v2;
32 const fs = require('fs');
33
34 async function transcribeFile() {
35 // Instantiate the client
36 const client = new speech.SpeechClient();
37
38 const content = fs.readFileSync(audioFilePath).toString('base64');
39 const transcriptionRequest = {
40 recognizer: recognizerName,
41 config: {
42 // Automatically detects audio encoding
43 autoDecodingConfig: {},
44 },
45 content: content,
46 };
47
48 const response = await client.recognize(transcriptionRequest);
49 for (const result of response[0].results) {
50 console.log(`Transcript: ${result.alternatives[0].transcript}`);
51 }
52 }
53
54 await transcribeFile();
55 // [END speech_transcribe_file_v2]
56}
57
58exports.transcribeFileV2 = main;

Callers

nothing calls this directly

Calls 1

transcribeFileFunction · 0.85

Tested by

no test coverage detected