I have a working nodejs program in GCP that using GCP Speech to Text API
async function main() {
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');
const fs = require('fs');
// Creates a client
const client = new speech.SpeechClient();
const fileName = './resource/amazing30s_mono.flac'; // mono clip
// Reads a local audio file and converts it to base64
const file = fs.readFileSync(fileName);
const audioBytes = file.toString('base64');
// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const audio = {
content: audioBytes,
};
const config = {
languageCode: 'en-US', // Malay try 'ms-MY' (https://cloud.google.com/speech-to-text/docs/languages)
enableAutomaticPunctuation: true, // https://cloud.google.com/speech-to-text/docs/automatic-punctuation
};
const request = {
audio: audio,
config: config,
};
// Detects speech in the audio file
const [response] = await client.recognize(request);
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
console.log(`Transcription: ${transcription}`);
}
main().catch(console.error);
And I have a working TypeScript Firebase Cloud Func
import * as functions from 'firebase-functions';
export const reqWithParam = functions.https.onRequest((request, response) => {
let name = request.query.name
response.send("Request with name= " + name);
});
But how could I integrate both programs up? Or how could I bring the nodejs code into my Firebase Cloud function to make my Firebase cloud function trigger Google API to convert speech to text?
Both programs above are under the same GCP project, same server (Google cloud shell)
I have read through the doc, but there are still missing gaps
- How to 'Import' a node program
- How to get the GS path of the audio file
- How to validate token (same GCP project)
- Any YouTube tutorial showing detail steps in 'calling GCP API via Firebase'