| 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] |