Godot and getting binary files via HTTP (MaryTTS)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BevanFindlay

So, I am wanting to use Godot to get a (binary) file using HTTP and then either save it or, even better, turn it into a Resource in memory that I can use. It’ll be WAV files that I’m getting in return (trying to implement MaryTTS, which is running as a server on localhost). I had a look at the docs for HTTPRequest, but can’t seem to get a working solution.

I do $HTTPRequest.request("http://...") when a particular keypress is made, and I have the _on_HTTPRequest_request_completed() function, but this never seems to be called. I tried with the function in the same Node as the request (as per the docs’ example), and I also tried putting it as part of a script for the HTTPRequest Node. If I hit the triggering key fast enough, it gives an error (“HTTPRequest is processing a request”), but if I do it slower, it doesn’t give that error, so it appears it is finishing. It just doesn’t do anything when it finishes. HTTPRequest gives a return value of 0, which I assume means no error? (Or should this give me HTTP status codes?)

Any idea what I’m doing wrong? Can HTTPRequest handle binary files? How do I get this working? Should I be using HTTPClient instead?

(Any suggestions on a better way to implement MaryTTS are also welcome).


Edit: have made some progress using HTTPClient. My code now looks like the below, where I can get a response (and even manage it in its own thread, so there’s no freezing of the main game), but the audio player doesn’t play anything.

Code is here: Dropbox - httpTest.gd - Simplify your life

:bust_in_silhouette: Reply From: BevanFindlay

Eventually got this working, once I learned how the data for the audio player needed to be structured. It’s still a little slower than I’d like, though I don’t know if that’s Godot’s end or just how long it takes MaryTTS to process (will be test this some more), but it works!

Full code is here: extends Node# HTTPClientvar threadvar mutexvar semaphorevar exit_t - Pastebin.com

Dude, thanks for this, saved me from wasting time fiddling around with HTTPRequest.
Can I buy you a coffe or something?

josaid | 2022-06-29 19:58