| 23 | const client = new speech.SpeechClient(); |
| 24 | |
| 25 | async function quickstart() { |
| 26 | // The path to the remote LINEAR16 file |
| 27 | const gcsUri = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw'; |
| 28 | |
| 29 | // The audio file's encoding, sample rate in hertz, and BCP-47 language code |
| 30 | const audio = { |
| 31 | uri: gcsUri, |
| 32 | }; |
| 33 | const config = { |
| 34 | encoding: 'LINEAR16', |
| 35 | sampleRateHertz: 16000, |
| 36 | languageCode: 'en-US', |
| 37 | }; |
| 38 | const request = { |
| 39 | audio: audio, |
| 40 | config: config, |
| 41 | }; |
| 42 | |
| 43 | // Detects speech in the audio file |
| 44 | const [response] = await client.recognize(request); |
| 45 | const transcription = response.results |
| 46 | .map(result => result.alternatives[0].transcript) |
| 47 | .join('\n'); |
| 48 | console.log(`Transcription: ${transcription}`); |
| 49 | } |
| 50 | quickstart(); |
| 51 | // [END speech_quickstart] |
| 52 | } |