# Example implementation

## High level overview

You'd need 2 cloud function, one (`createTranscript`)to start the recognition, and trigger a cloud task that on a time delay triggers the second one (`firestoreCheckSTT`)to check the progress of the transcription gcp operation. If the transcript is not done, it triggers another cloud task to re-trigger the second cloud task later.

![GCP STT + Cloud functions + Cloud Task](https://931037443-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lu8k-cSlWRZojfRmKmI%2F-ML7zMMx0seWCGjcTlBS%2F-ML7zXT6vQ4KzwkdA_kD%2Fdpe-firebase-stt.png?alt=media\&token=bab143e2-b6ee-4016-beff-0748ca5993f1)

## Cloud Function `createTranscript`

* [ ] Create audio that meets GCP STT Specs \
  (eg `ogg` or `wav`.`ffmpeg` bin present on GCP Cloud function by default)
* [ ] &#x20;Call Google Cloud STT long running recognition
* [ ] Get operation name in response&#x20;
* [ ] Start cloud task (eg on a 5 min delay)
  * [ ] in cloud task payload have
    * operation name
    * firestore path to the audio file
  * [ ] cloud task end point for cloud function to check STT `firestoreCheckSTT`
  * [ ] add ENV for firebase to be able to call GCP STT opration
* [ ] save to firestorm&#x20;
  * operation name
  * status 'in-progress'
* [ ] return&#x20;

## Cloud function to check if operation is done `firestoreCheckSTT`

* [ ] end point for GCP operation
* [ ] GET request to check GCP operation end point   &#x20;
  * [ ] if done&#x20;
    * [ ] save data
  * [ ] if not done
    * [ ] trigger another cloud task operation&#x20;
    * [ ] same payload
  * [ ] if errors&#x20;
    * [ ] save data to firestore

missing handling edge cases, eg If the transcript has been deleted, should try to save in the cloud task, it should drop it Eg instead of set / merge should be try catch, with a method for update only if it exists
