()
| 35 | const speech = require('@google-cloud/speech'); |
| 36 | const fs = require('fs'); |
| 37 | async function quickstartV2() { |
| 38 | // Instantiates a client |
| 39 | const client = new speech.v2.SpeechClient(); |
| 40 | |
| 41 | const recognizerRequest = { |
| 42 | parent: `projects/${projectId}/locations/global`, |
| 43 | recognizerId: recognizerId, |
| 44 | recognizer: { |
| 45 | languageCodes: ['en-US'], |
| 46 | model: 'latest_long', |
| 47 | }, |
| 48 | }; |
| 49 | |
| 50 | const operation = await client.createRecognizer(recognizerRequest); |
| 51 | const recognizer = operation[0].result; |
| 52 | |
| 53 | const content = fs.readFileSync(audioFilePath).toString('base64'); |
| 54 | |
| 55 | const transcriptionRequest = { |
| 56 | recognizer: recognizer.name, |
| 57 | config: { |
| 58 | // Automatically detects audio encoding |
| 59 | autoDecodingConfig: {}, |
| 60 | }, |
| 61 | content: content, |
| 62 | }; |
| 63 | |
| 64 | const response = await client.recognize(transcriptionRequest); |
| 65 | for (const result of response[0].results) { |
| 66 | console.log(`Transcript: ${result.alternatives[0].transcript}`); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | await quickstartV2(); |
| 71 | // [END speech_quickstart_v2] |
no test coverage detected