Using Google's text to speech API with Hyperstack - ruby-on-rails

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.

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 :-)

Related

On Heroku, can I use Rails to serve a generated audio file back to my React Native front-end?

I'm generating temporary audio files using Rails and storing them in the tmp directory in Heroku. I think want to send the audio back to Expo/React Native to be played. How can I use Rails to serve that data as a POST response?
In my Rails API backend, I connect to a Text-to-Speech API (Google), and generate an mp3 from text. I can verify that these files are being correctly created and stored in tmp as per my POST request. I am missing the conceptual piece of how to return them back.
It's ideal for me that these files are temporary, as I only need them during a single session. I can see a couple of options.
I can save the files as .mp3s in tmp, as I'm currently doing, and find a way to attach them to my POST response.
I get the audio back from the API as binary, so I can skip saving the files as .mp3s, and respond to the POST with the binary as JSON, or something.
???
Play sound in Expo/ React Native
I'm trying to avoid setting up an AWS bucket for this if possible, but if that's the best way to do it, I'm happy to hear that as well.
Thanks!

How to create an upload (large, ie ~400MB) bytestream service in Vaadin?

In an earlier post from a few minutes ago, I asked a "general" question regarding creating general webservices in vaadin: How can one create webservices in Vaadin 12?
However, one specific unique case that I mainly need to support is the uploading via https of large (eg ~400MB) bytestream objects that would presumably be sent to Vaadin via an https "post" command (with the paylod being provided I presume in raw binary format as a bytestream.) I saw that Vaadin has built-in support for uploading files (which is essentially a post command of a bytestream, I presume?) and then I saw a reference to StreamReceiver here: https://vaadin.com/docs/v12/flow/advanced/tutorial-stream-resources.html
which seems to sound like a custom file importer, but I couldn't find any (simple & more-or-less complete) examples on how to use it. Ideally, a quick few lines of Java to show the "receiving" of the bytestream and a few quick lines (ideally in Java) which "posts" to the receivestream's url would be all that's needed to show how this manual upload of bytes can be accomplished in Vaadin. (In DropWizard & Jersey, I can find such examples reasonably easily, but I'm not sure how to gain that level of control in Vaadin.)
(Very very minor bonus: is there a size limit to the post command? eg, can a bytestream of over say ~4GB be sent and received?)
In Vaadin the Upload API is optimised for streaming into File (unlike handling the stream as in Servlet and JAX-RS API). One way is to first stream to a temp file and then when the file is fully on the server side, handle the data from temp file.
Alternatively you can use Flow Viritin add-on and a helper class UploadFileHandler, which give you and API where you read the contents from InputStream, in same way as with Servlet API. See a usage example is in this test.
This isn't a first time this is asked and I actually have a more verbose blog draft about this subject. I'll add a link to that once I get that published.

How can send ajax request from activex control/NPAPI and process its response?

Currently i have a wepage where I am sending a ajax request from javascript and in respose for that server is sending a video file which will be by default saved browser download location. I want the user to select download path each and every time for the file download(which can be achieved by changing browser settings which is not suited for me). So i want to include a activex object which can send ajax request and get its response. First I want to know whether is it possible, if yes is there any prototype/examples, or please let me know how it can be achieved.
It is possible; FireBreath has a mechanism called BrowserStreams that would probably work for what you're describing, but honestly I'd suggest against it. See if you can do what you need using an extension; Chrome is dropping support for NPAPI next year and even if they weren't I think it's a really bad idea to use a plugin for something like this.
Up to you, of course. There are examples for making HTTP GET and POST requests in the FBTestPlugin example in FireBreath.

How to I access a SoundCloud public stream?

How do I play a track from a SoundCloud URL, which, for example, I got from the xml response from a query
<stream-url>https://api.soundcloud.com/tracks/31164607/stream</stream-url>
I should have thought that it would have been as easy as:
https://api.soundcloud.com/tracks/31164607/stream&client_id=my_client_id
yet I get
<error>401 - Unauthorized</error>
All I want to do is consume it in a Silverlight MediaElement, so all I need is set some url to the MediaElement's Source property.
I've checked an application that I wrote about 2 years ago, and THEN, accessing the stream url was as easy as this for a public track:
http://api.soundcloud.com/tracks/18163056/stream&consumer_key=MY_CONSUMER_KEY
however this no longer seems to work.
For example, all I had to do then in C# was:
MediaElement me = new MediaElement();
me.Source= new Url("http://api.soundcloud.com/tracks/18163056/stream&consumer_key=MY_CONSUMER_KEY");
me.Play();
Any hints would be appreciated.
I had a reply on a Microsoft forum that seems to imply that SoundCloud might not be possible to stream to Windows 8 Metro devices without consuming the whole stream before playback starts - which is quite worrying and would seem to imply that to make authentication possible, it would have to be done entirely in the url querystring insterad of using the header:
(The following reply is the answer to the following question: 'I am able to access an audio stream by http using the MediaElement, however I need to access it via https in which I need to add the oAuth info to the header of the initial request.
How is this done when using a MediaElement, and if it cannot be done, what is the workaround for consuming an audio feed in Metro 8 that requires header authentication to stream?')
"Direct access to the underlying network stream is not currently permitted by the MediaElement. Because of this there is currently no way to modify the header of the HTTP request to include any additional authentication information. That said, you do have control over the URL. You could theoretically setup an HTTP proxy service that translated the HTTP GET request parameters into the necessary oAuth credentials. Keep in mind that this is just a theoretical workaround. You may find different behavior in practice. Another theoretical workaround would be to handle the oAuth yourself via a raw stream socket and pass the retuned media data to the MediaElement via "Set Source" and a "Random Access Stream". Please keep in mind that this method has major limitations. in order to use a "Random Access Stream" with the ME you need to make sure all of the data is available before passing it to the ME."
The proxy service is not scalable for an application that is merely distributed for free as every stream would need to come via the proxy. And the raw stream socket, although getting around this, would mean that playback could not start until the whole file had downloaded - and this goes against all current UX (User Experience) guidelines.
So once again, if anyone has any tips, or info about how the whole authentication thing can be achieved in a querystring instead of using headers, I'd appreciate it!
I'm a little confused about whether you're referring to a public or a private track? If it's a public track, then you shouldn't need to send any authentication information, just your client id.
When I request https://api.soundcloud.com/tracks/31164607/stream?client_id=YOUR_CLIENT_ID then I get a 302 redirect to the proper mp3 stream.
Remember, adding parameters to a URL must start with a ? not &. This could (more than likely) be the reason why you are getting a 401 (SC is not picking up the client_id).
After authentication the link like this
http://api.soundcloud.com/tracks/103229681/stream?consumer_key=d61f17a08f86bfb1dea28539908bc9bf
is working fine. I am using Action Script.
I'm following up on Tom's reply because he calls attention to url character specificity. My HTTP requests randomly started failing today, and I was prefacing my client_Id with a ?. As soon as I changed that single ? to &, it started working. So in my case, SC wasn't picking up my client_Id because I used the wrong character. I think depending on where in the request we're talking about specifically, it's worth noting that differences between ? and & do make a difference.

EBAY - Sending a file via http post?

I've a file I want to send to the ebay system to support the LMS.
All the samples I've found include the use of the API, but the environment I'm working in doesn't have the ability to use it (the api).
So I'm forced to send the file with an HTTP post. But the doc's seem lacking.
Has anyone constructed/found an example of a HTTP post that will send a given file.
EDIT:
Oh.. what I see in the samples I have found is an area that seems it's supposed to have the data, but in the sample, there's nothing I'd consider real data.
Are you talking about the file transfer service or the bulk upload service? Don't you just generate an xml document and post the url like in this example:
http://developer.ebay.com/DevZone/file-transfer/CallRef/uploadFile.html#Samples

Resources