I use google speech-to-text service via @google-cloud/speech library on my node.js firebase functions, however I want to use it as streaming data and as far as I understand there is no possibility to achieve that on firebase functions.
So I have decided to do that on the client side which is angular for my case. Nevertheless I cannot find any useful documentation.
I want to know if there is any possibility to use google speech-to-text service on angular in a secure way.
Here is my functions on node.js;
import {SpeechClient} from "@google-cloud/speech";
export const transcriptAudio = onCall(async (data) => {
let userId = data.auth?.token?.uid;
if(!userId)
throw new HttpsError('unauthenticated', 'The user is not authenticated.');
let audioByte = data.data.audioByte as string;
// Detects speech in the audio file
const client = new SpeechClient();
const response = await client.recognize(
{
audio: {content: audioByte},
config: {
encoding: "LINEAR16",
audioChannelCount: 2,
languageCode: "en-US"}});
const transcription = response[0].results?.map(result => result.alternatives![0].transcript).join('\n');
return transcription;
});
UPDATE 1: I have asked it to chatgpt and it suggested me to use Firebase Functions to authenticate the user and get the accessToken and on angular side, use that accessToken to authenticate the api requests. It sounds reasonable to me.
UPDATE 2: It turned out that I need to use grpc to use speech-to-text as a streaming data. So I need to setup and use a ngx-grpc like library to achieve that, is that right? It seems like a lot of work. I don't want to miss a much easier solution.