| 68 | } |
| 69 | |
| 70 | async function syncRecognizeGCS( |
| 71 | gcsUri, |
| 72 | encoding, |
| 73 | sampleRateHertz, |
| 74 | languageCode |
| 75 | ) { |
| 76 | // [START speech_transcribe_sync_gcs] |
| 77 | // Imports the Google Cloud client library |
| 78 | const speech = require('@google-cloud/speech'); |
| 79 | |
| 80 | // Creates a client |
| 81 | const client = new speech.SpeechClient(); |
| 82 | |
| 83 | /** |
| 84 | * TODO(developer): Uncomment the following lines before running the sample. |
| 85 | */ |
| 86 | // const gcsUri = 'gs://my-bucket/audio.raw'; |
| 87 | // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; |
| 88 | // const sampleRateHertz = 16000; |
| 89 | // const languageCode = 'BCP-47 language code, e.g. en-US'; |
| 90 | |
| 91 | const config = { |
| 92 | encoding: encoding, |
| 93 | sampleRateHertz: sampleRateHertz, |
| 94 | languageCode: languageCode, |
| 95 | }; |
| 96 | const audio = { |
| 97 | uri: gcsUri, |
| 98 | }; |
| 99 | |
| 100 | const request = { |
| 101 | config: config, |
| 102 | audio: audio, |
| 103 | }; |
| 104 | |
| 105 | // Detects speech in the audio file |
| 106 | const [response] = await client.recognize(request); |
| 107 | const transcription = response.results |
| 108 | .map(result => result.alternatives[0].transcript) |
| 109 | .join('\n'); |
| 110 | console.log('Transcription: ', transcription); |
| 111 | // [END speech_transcribe_sync_gcs] |
| 112 | } |
| 113 | |
| 114 | async function syncRecognizeWords( |
| 115 | filename, |