| 440 | } |
| 441 | |
| 442 | async function syncRecognizeModelSelection( |
| 443 | filename, |
| 444 | model, |
| 445 | encoding, |
| 446 | sampleRateHertz, |
| 447 | languageCode |
| 448 | ) { |
| 449 | // [START speech_transcribe_model_selection] |
| 450 | // Imports the Google Cloud client library for Beta API |
| 451 | /** |
| 452 | * TODO(developer): Update client library import to use new |
| 453 | * version of API when desired features become available |
| 454 | */ |
| 455 | const speech = require('@google-cloud/speech').v1p1beta1; |
| 456 | const fs = require('fs'); |
| 457 | |
| 458 | // Creates a client |
| 459 | const client = new speech.SpeechClient(); |
| 460 | |
| 461 | /** |
| 462 | * TODO(developer): Uncomment the following lines before running the sample. |
| 463 | */ |
| 464 | // const filename = 'Local path to audio file, e.g. /path/to/audio.raw'; |
| 465 | // const model = 'Model to use, e.g. phone_call, video, default'; |
| 466 | // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; |
| 467 | // const sampleRateHertz = 16000; |
| 468 | // const languageCode = 'BCP-47 language code, e.g. en-US'; |
| 469 | |
| 470 | const config = { |
| 471 | encoding: encoding, |
| 472 | sampleRateHertz: sampleRateHertz, |
| 473 | languageCode: languageCode, |
| 474 | model: model, |
| 475 | }; |
| 476 | const audio = { |
| 477 | content: fs.readFileSync(filename).toString('base64'), |
| 478 | }; |
| 479 | |
| 480 | const request = { |
| 481 | config: config, |
| 482 | audio: audio, |
| 483 | }; |
| 484 | |
| 485 | // Detects speech in the audio file |
| 486 | const [response] = await client.recognize(request); |
| 487 | const transcription = response.results |
| 488 | .map(result => result.alternatives[0].transcript) |
| 489 | .join('\n'); |
| 490 | console.log('Transcription: ', transcription); |
| 491 | // [END speech_transcribe_model_selection] |
| 492 | } |
| 493 | |
| 494 | async function syncRecognizeModelSelectionGCS( |
| 495 | gcsUri, |