BarrieH
BarrieH

Reputation: 373

Using Google's text to speech API with Hyperstack

I would like to use the Google text-speech API to let my user type text into a text control, and then click a button which would send the text to my Rails server, where it would use the Google TextToSpeach API to create an mp3 file of that speech.

The Google API looks very simple to use: https://cloud.google.com/text-to-speech/docs/create-audio

In a traditional Rails application, I would write an API to pass the text to be transcribed and would expect that API call to return the path to the MP3 file created for the user to download.

It seems that a Hyperstack Isomorphic Operations would be the right approach for this, but how do I ensure the operation only runs on the server and not on the client though and how do I get the output value of the Operation (ie the file created) so I can display it in the browser for the user to download?

I should stress that I only need the Google API to Create the Audio file on the server (not play it). The user will then download the created file so their own use.

Upvotes: 1

Views: 169

Answers (1)

Mitch VanDuyn
Mitch VanDuyn

Reputation: 2878

An operation is not going to help you here. Why?

Because unless you know a trick I don't, the only way to play an audio file without a lot of extra work, is to point an HTML audio tag's source at a url on the server.

This is then very easily done by a standard rails controller method that decodes the string from the URL params and returns the mp3 file in the response body.

For example /utils/text2speech.mp3?text=Hello%020There would just return the MP3 file.

Just to fully answer your question however, the Hyperstack::ServerOp class is a subclass of Operation that only runs on the server, but can be called from the client.

Too bad its no help here :-)

Upvotes: 0

Related Questions