| 201 | } |
| 202 | |
| 203 | async function speechTranscribeMultilang(fileName) { |
| 204 | // [START speech_transcribe_multilanguage_beta] |
| 205 | const fs = require('fs'); |
| 206 | |
| 207 | // Imports the Google Cloud client library |
| 208 | const speech = require('@google-cloud/speech').v1p1beta1; |
| 209 | |
| 210 | // Creates a client |
| 211 | const client = new speech.SpeechClient(); |
| 212 | |
| 213 | /** |
| 214 | * TODO(developer): Uncomment the following lines before running the sample. |
| 215 | */ |
| 216 | // const fileName = 'Local path to audio file, e.g. /path/to/audio.raw'; |
| 217 | |
| 218 | const config = { |
| 219 | encoding: 'LINEAR16', |
| 220 | sampleRateHertz: 44100, |
| 221 | languageCode: 'en-US', |
| 222 | alternativeLanguageCodes: ['es-ES', 'en-US'], |
| 223 | }; |
| 224 | |
| 225 | const audio = { |
| 226 | content: fs.readFileSync(fileName).toString('base64'), |
| 227 | }; |
| 228 | |
| 229 | const request = { |
| 230 | config: config, |
| 231 | audio: audio, |
| 232 | }; |
| 233 | |
| 234 | const [response] = await client.recognize(request); |
| 235 | const transcription = response.results |
| 236 | .map(result => result.alternatives[0].transcript) |
| 237 | .join('\n'); |
| 238 | console.log(`Transcription: ${transcription}`); |
| 239 | // [END speech_transcribe_multilanguage_beta] |
| 240 | } |
| 241 | |
| 242 | async function speechTranscribeMultilangGCS(gcsUri) { |
| 243 | // [START speech_transcribe_multilanguage_gcs_beta] |