Search code examples
javascriptgoogle-app-enginegoogle-cloud-functionsgoogle-speech-api

Moving Google STT from Cloud Functions to dedicated GAE


I'm using Cloud Functions to convert audio/mp4 from getUserMedia() placed in Storage bucket
To audio/x-flac format using ffmpeg for being able to transcribe it using Google STT

bucket
  .file(file.name)
  .download({ destination })
  .then(() =>
     ffmpeg(destination)
       .setFfmpegPath(ffmpeg_static.path)
       .audioChannels(1)
       .audioFrequency(16000)
       .format('flac')
       .on('error', console.log)
       .on('end', () =>
          bucket
            .upload(targetTempFilePath, { destination: targetStorageFilePath })
            .then(() => {
               fs.unlinkSync(destination);
               fs.unlinkSync(targetTempFilePath);
            });
        )
        .save(targetTempFilePath);
      )
  );

Workflow: client-side MP4 => Storage bucket trigger => STT => Firestore
It works great and I get clean FLAC files and STT works flawlessly in this combination!

But only IF

Input files are not larger than 1-2 Mb each (usually I have a series of 5-10 files coming in at once).
I'm aware of 10 Mb limit and now I want to let Cloud Functions handle image processing only and move all audio stuff to some dedicated GAE or GCE instance.

What's better to use: in this case GAE or GCP, dockerized or native, Python or Node, etc.
How exactly could the workflow be triggered on GCP instance after placing files on Storage?
Any thoughts or ideas would be greatly welcomed!


Solution

  • I would recommend you to use the Cloud Function as a Cloud Storage trigger. In this way, you will be able to get the name of the file uploaded in your specific bucket. You can check this documentation about Google Cloud Storage Triggers, in order to see some examples.

    If you use Python, you can see the file name by using:

    print('File: {}'.format(data['name']))

    Once you got the name of the file, you can do the request to GAE in order to convert the audio.

    I also found this post that explains how to call an URL hosted in Google App Engine, and I think it might be useful for you.

    Hope this helps!