Last active
January 9, 2023 16:25
-
-
Save rashaabdulrazzak/982d4f8e960e704b6f57ed70fd228855 to your computer and use it in GitHub Desktop.
transcribe file located in cloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imports the Google Cloud client library | |
const speech = require('@google-cloud/speech'); | |
// Creates a client | |
const client = new speech.SpeechClient(); | |
// const gcsUri = 'gs://my-bucket/audio.raw'; | |
// const encoding = 'Encoding of the audio file, e.g. LINEAR16'; | |
// const sampleRateHertz = 16000; | |
// const languageCode = 'BCP-47 language code, e.g. en-US'; | |
const config = { | |
encoding: encoding, | |
sampleRateHertz: sampleRateHertz, | |
languageCode: languageCode, | |
}; | |
const audio = { | |
uri: gcsUri, | |
}; | |
const request = { | |
config: config, | |
audio: audio, | |
}; | |
// Detects speech in the audio file. This creates a recognition job that you | |
// can wait for now, or get its result later. | |
const [operation] = await client.longRunningRecognize(request); | |
// Get a Promise representation of the final result of the job | |
const [response] = await operation.promise(); | |
const transcription = response.results | |
.map(result => result.alternatives[0].transcript) | |
.join('\n'); | |
console.log(`Transcription: ${transcription}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment