But for shorter files, you can add your media to a google cloud storage and run google cloud STT inside a cloud function and save the result to firestore.
// Goolge App Engine calls STT SDK
// this function returns null.
exports.createTranscript = functions.firestore
.document("transcripts/{transcriptId}")
.onCreate(async (change, context) => {
// Get an object representing the document
const newValue = change.data();
// for now only run STT for uploaded files
// eg if running from STT then don't run this
if (newValue.transcriptionType === "upload") {
// access a particular field as you would any JS property
const storageRef = newValue.storageRef;
console.log("storageRef", storageRef);
// https://firebase.google.com/docs/storage/admin/start
const storage = admin.storage();
// https://github.com/firebase/firebase-tools/issues/1573#issuecomment-517000981
const bucket = storage.appInternal.options.storageBucket;
// // const gcsUri = 'gs://my-bucket/audio.raw';
const gcsUri = `gs://${bucket}/${storageRef}`;
console.log("gcsUri", gcsUri);
//////// STT ////////
// Creates a client for STT
const client = new speech.SpeechClient();
const encoding = "mp3"; //'Encoding of the audio file, e.g. LINEAR16';
const sampleRateHertz = "48000"; //16000;
// const languageCode = newValue.language.value;
const languageCode = "en-US"; //'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();
// TODO: Convert to DPE
// TODO: Save DPE json format to firebase as collection
// get text - tmp
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join("\n");
console.log(`Transcription: ${transcription}`);
// Then return a promise of a set operation to update the document
return change.ref.set(
{
// TODO: change transcription to transcript
transcription: transcription
},
{ merge: true }
);
} else {
return null;
}
});