How to connect to an API using Unreal Engine Blueprints | Use case - Replica Studios | UE 4.27

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey what's going on welcome back uh today i thought i'd dive into um apis i thought it might be interesting for some folks to figure out how to integrate uh an api with unreal engine blueprints uh so i'm gonna use a i think a more common use case there is a tool called replica studios that uh can be used to basically generate a.i character voices so i'll just show how this thing works really quickly um you can pick an actor voice they've got a whole bunch of um actors in their portfolio uh you can pick one of them i'm gonna try and pick one that's not a beta we'll select this guy atlas you can type in some dialogue hey you youtubers how are you okay uh there's a whole bunch of different uh styles that you can um work with uh but we're just gonna save the take and then we're going to uh download uh or actually we're gonna play it hey youtubers how are you right so it's uh it's computer generated uh audio text-to-speech and like i said that's the general use case for the cool thing is that they uh have also included an api where you can integrate into this and pull out the audio that you want and store it to flat files on your system and so i thought that would be a neat use case to demonstrate integrating with in unreal engine i assume for the most part if you're watching this video you probably already know what an api is but if we do have uh people that aren't sure it's a programmable interface so basically all that means is that for example replica has their own set of code on their own servers and they execute that code to generate the speech that i just showed you in their application what an api does is it'll expose certain pieces of their programming out to what are called endpoints and then from a separate application you can reach out to those endpoints and access whatever they're making available in this case they're going to make i think five or six endpoints available where you can ask them to generate a um an ai voice and then um they'll provide you with a file that you can pull down in that ai voice rather than using their application directly okay so uh i just brought up a clip from a previous tutorial that i made where i was demoing the functionality of the api i'll put a link in the description below for this but what i've got on the screen now is i just got some basic ui widgets where it's taking in uh the different information from the user it's then passing it out to the replica api and you're seeing the the results what a great day to be alive what a great day to be alive so we'll close out of there um we'll go to their main website here and under products replica api uh maybe it was just under resources api docs you can come here and they basically explain how the api is working all of their examples use um what the heck is the name of the application uh use this postman application to sort of prove out how to set up and use the api um so i would encourage you to set postman up and follow their documentation here i've already set it up once you have it working you can have your off the authentication set up your uh get of the voice you get of the speech and then there's a couple of different other options there but that's essentially what they're talking about when uh they're talking about postman really um for our use case i mean you don't need it other other than to sort of prove that you can get it to work from your system using the postman app and their directions i'm going to show you how to set it up in unreal engine and we may refer back to um some of the code that's in postman to show you how i figured some of this stuff out um the other thing that they've got in their documentation is along the top they've got uh what is this five different um script types um so if you were to click on a specific script type for example http and then scroll down to the different endpoints that are on the api it's got the code samples that you're going to need based on the type of api that you're using so this is all the http http uh scripting for each one of the endpoint calls that you can make to their api well let's get started in an unreal uh application i'm going to be using 427 so i would recommend you do the same but this should work in all the other versions as well okay so let's just pick a new game that's fine we can do a blank template that is also fine and then we won't need ray tracing or any of this other stuff um this is all fine and what we can do is we can call this my replica api and then this one my replica api okay okay so for this to work we're gonna need a couple of things we're gonna need some plugins and so i'm just going to launch the marketplace here and we'll look for the plugins that we need i'll actually show you in my library here so in the installed plugins actually i'll show you on uh 426 is where i used this last um you can click on install plugins so if you go to library the version i've got all these versions installed but the version that you're using if you click on install plugins it shows you all the different plugins that you have installed what we need is we need this va rest plugin and we need this runtime files downloader so va rest and runtime files downloader i'm just going to confirm that i have those in uh 427 which i do runtime files uh downloader and uh va rest so perfect and i'll just show you on the marketplace where you can grab those what is going on here there we go va rest it's free just go and grab that one run on files download there you go this guy also free so grab both of those um and you should be good to go i'm gonna go with those downloaded i'm gonna go into my plugins and i'm going to look for both of them so runtime files downloader i'm going to enable that it's going to ask me to restart but since we're restarting we may as well get all of our plugins there we go and restart now so now both of those plugins are going to be enabled in our project and because we're not going to do a whole lot with this project i'm actually just going to go up to here settings um sorry up the blueprints and um open the level blueprint level blueprint and that way we don't have to uh create a separate sort of blueprint class and whatnot it's already created for us and this type of functionality is generic so we're going to be running it from the generic blueprint anyways i think that makes sense um so we'll do it from there we're going to uh let's just use the one key we'll just right click and we'll put in one and we just need something to drive uh this right so a keyboard event is fine so the first thing that we want to do is we want to set up the username and password right so i guess what we want to do is we probably want to create a widget to enter the password but i'm just thinking maybe we'll hold off on that for now and we'll just default set a couple of text variables for this for now and then we'll add a widget later um so let's just say user name password and then we'll just change this to a string and this one will change to a string as well okay so off of this will be a rest and then there should be like a va rest sub system or something get va res subsystem so this um uh this element will allow us to drive all of the blueprint nodes that we need so uh when i was trying to type in the construct uh json request it's gotta come from uh this guy here so then uh on pressing one using the va rest subsystem you can construct a json request and the first one that we want to do is we want to do a post and i just want to make sure we want to request a body and then what i'm going to do is i'm actually going to promote this to a variable and i call this guy json post request so that we can manage that and then i'm going to bind event to on request complete that's just saying you know when this request has been completed we can create a custom event to trigger once the uh request has been completed so i'm just gonna do custom event uh and then we'll just call this authentication [Music] rest callback okay so basically this custom event will execute when this request is completed and then we can run uh additional code off of there um we also want to have a separately bind event to on request fail so we want to know when the request fails and we'll just drive that in line and then uh we're also gonna have another custom event here no you know what i'm gonna i'm gonna tie them together for now you could have your separate events but i think there's an opportunity to share the code so we'll just drive it into the same event and then we'll just manage that later uh that's fine okay um what else do we want to do here right so we want to also here we want to get request object boom run that down here and then on this one we want to set the string field okay so this is where we're going to put in our username and then the field name this is going to be the client id and again referring back to uh postman you can see that it needs in this um uh json object right with the post command it needs a client id and a secret id right so this one's going to be the client id and then we're going to do the same thing here we're going to again set string field and then we're going to call this one secret and then the string value is going to be your password so on these uh because i don't want to share my username and password with you all that you need to do is hit compile and save oops or sorry compile and then you can now edit the default name value of the username and the password so just go in there and enter in your actual username for replica studios and your password for replica studios and then those will be passed along that request object sorry my bad i'm referring to my uh other code here and i'll try and explain it as i go along but i haven't looked at this for a while so i'm literally just kind of following along here okay so we got our json object and we need the post request here so we need this post request again and we need to drive that in there your target is your poster request and your json object is the json object there right so that's the two and then we need to process the url off of that boom keep that the same q and align those up and then this is the url that we need so the url is going to be the replica replica studios api url so in here i have it here and we would be able to see the same thing in our replica studios documentation uh right here you can see the post of the url that's all that we're jamming into this uh post url there we go cool that's right um and then that would be all the code to sort of create the um the json request and to post um the request to uh replica studios and then essentially um this is looking to monitor does this entire request does it complete or does it fail right and so uh basically we would end up here and we would want to get the response object okay and this we can get the field names and we'd also want to get the string field tool and this is going to be the access token okay um and let me just see if i can tie that whoops i keep hitting save well you know what i should save it save um we'll call this uh api integration cool um yeah so if i went back to the endpoints here um here this is what we're getting right we're getting this access token this is essentially going to be our token that keeps the session alive while we're communicating with the api so to make sure that um the api doesn't mix up requests like if i connect to the api at the same time that you connect to replica how does it know uh how does it keep straight who's accessing what and how do i know if you've authenticated with a username and password how do i make sure that you know the information that i'm that you're requesting is being sent to you that's this access token or these bare tokens that are going to persist through your integration in the api and make sure that you have a unique id so that while you're talking to the api it knows um it knows who you are and that you're authenticated uh so we are going to you just made oh yeah we're going to get a copy i always forget between reference and copy i think those words are way too similar anyways we're going to get a copy because changes then don't go back to the array we're not making changes to the original array we're just getting copies okay so we want to get the two elements out of the array let's just do this get array field all right and we'll do that twice that array field and then essentially from these we can go here we can go here so those field names right are uh the fields that we have there that's kind of clean okay we could uh if we want print string you know what we might as well put these print strings in because we're probably going to mess something up so this will be able to tell us what we're doing um here this is again right the field name and uh we'll do another one there we go um we have those field names printing out okay and these arrays are different because they're inputs into them the field names are different and then um we want to do this as string same thing as string and then we're going to do some more printing print string we want to put the string in let's just change the color at this point so we know it's something a little bit different okay so the return value if this fails is um bad credentials and i don't think that's is it in the documentation here no i don't think it's in the documentation i think this was just um me playing around uh and putting in like trying this making it fail and then seeing what the output was from the api so what i found was that if you get this array field and it returns the exact value bad credentials then that's when you can determine if the credentials are are bad and then what i did is i just promoted this to a variable and i put authentication passed um and then i just set that in there and then uh i also did a print string and then i put this guy in there [Music] i'll show you everything that's going on here and then we also need this string field over here so this guy okay and then i also want to set this um promote this to a variable as an access token access token yeah cool and yeah i want to set that guy in there down we'll change this guy's color to pink too cool okay no other way around there we go okay uh then we're setting the access token then what we're going to do is we're going to run a branch off of here branch branch and this is where we're going to get the authentication passed and make sure that it's true right that just happened over here right so if if it doesn't equal bad credentials um then uh right so if it's true we're gonna say uh another print string and then here we're just gonna say often authentication fails and we'll turn that uh red instead of pulling in text for now we'll just create another um string and we'll call this uh text to speech block um and this one we can this is where we'll hard code whatever we want to pull back from replica studios so this is a test out to replica and so that's what uh the the voice file that we'll get back it'll say that um we could create a gui and have the person enter it but for now just for testing purposes we'll just do this for now okay so then um the next thing we want to do is that's going to do our authentication i like to break these up so i'm going to put in another keyboard event and we'll just keep it simple with two and then what we're going to do is from this va uh rest subsystem we're gonna do our json get request so we're gonna do construction uh construct construct json uh request right and that's going to be here so when we press 2 it'll do this it'll be a get request and um form url that's fine okay so then this one we're going to promote to a variable again we're going to call this json get request and then we're going to go through similar type exercise to on event to on request complete and then we'll do the on fail and i'll just stop quickly and show you so this is the authentication it's passed the next one is we need to um get the voice and we need to uh get the speech that we're going to use so essentially we got to say hey what voice actor do we want to use and then what um what speech do we want to call and what's the sample rate and all that sort of stuff so here's all the different stuff and then i don't use the long polling here so those are the ones that we're going to use okay so we are constructing this get object so we can pull this off get request object there we go combine that in there we can find event then to on request fail and then same thing i'm just going to use one one custom event and we'll call this rest json get request response uh response object there we go okay let's just keep going with this so uh response object we need to tie this event in there when it's completed we'll clean this up a little uh there looks good okay um we need to set the header uh of this request the target is going to remain the same the header name is going to be authorization and you got to be careful make sure that you're putting in the right values there so again applying back to the documentation here you go uh authorization header right so that's why we're putting that in or conversely if you did go through the process of playing around with uh playing around with postman you can see here uh header is authorization okay okay cool uh header names authorization the value is going to be our access token that we created previously right so we got um the response back and where'd we store that we stored that here right so on our response object in the access token field we pulled out uh the access token and that's now going to be our authorization token right so this is confirming that because we're sending a separate request here right we send an initial request these requests are going to happen at different times we now sent this request and this is authorizing us or saying that hey we already have this token uh from you so you know who we are um so there is another step that has to happen here though right so um we need an append and because this isn't on its own what we need to do is we need to append this bearer with a space i believe in front yeah uh we need to append bearer with a space and then our access token and that'll actually be our complete uh header value and i believe uh that's this right authorization bearer and then the token so see there's a space there so that's why it's going to need that bearer space and then the ax and then the actual access token okay next we're finally using uh this guy to set request object um we'll do that and we'll bring him up here and then so the requesting object is again going to be our json get request we established over there put them in boom okay and then um what else do we got going on here we have i'm just looking because we did a few things a little bit differently okay i'll just stay along the top for now so um this is going to uh have a print string which will um funnel in a sec and then we're going to have the process url uh but it needs a target jason get request process url there we go okay so yeah we need to i believe get this text-to-speech block and then we need to uh reformat it so uh we need to replace and anything with a blank we need to convert from a blank and we actually need to insert that blank in here so you need to hit space and then here we need to put percent um 20. okay and the reason that we're doing that is if we go back to our documentation again this is why so in the get we actually it this is how it's formulated it says speech question mark text equals and then everywhere there's supposed to be a a space the formatting is percent 20. so basically what we need to do is we either need to originally put this in as percent twenties um or we need to replace every spat space so conceivably um especially if you're going to expose this to the user in a in a blueprint widget you're not going to ask them to put percent 20 instead of spaces so we would do that for them right so this you can put whatever your text is in normal format and then we can reformat it based on what the actual api needs if that all makes sense okay um cool what else this can actually slide down um and then this can go up this way okay i don't like the way that looks so let's just like this okay so format make sure again make sure that you actually did put in the space there so you can see if i put the arrow keys the space is there and then no space is just percent 20 and so that's going to convert that string into the format that we need and then what we can do is we can append um and we are going to need uh this url that i was showing you in the documentation uh we're going to need all this and all the way up to equals i'm just going to copy that out and essentially we've got to put that in here and then we put our newly formatted string uh at the end and then um the next piece we do is we go and speaker and speaker id equals and then um what we can do is we can add another pin here and we can promote this to variable and we would call this uh not that we would call this something different we would call this replica speaker id cool and then let's just cue these up cool actually let's do that again bring that down like that okay um okay so let me just explain this last part um but if you look it's got our text and then at the end it has and speaker id equals and then a value there right um okay cool um so that's all working except we don't have anything in this speaker id so what i'm going to do is i'm just going to copy this value over here um but essentially each one of these uh where's my replica oh did i close it i'll show you each one of these speakers has an id and if you really wanted to kind of expand the uh the api you could go and you could get all the speakers and you could then select have your user select them all that sort of stuff but this is what it's talking about when you select a voice right you have all these different speakers and so each one of them is going to have a speaker id okay so let's do this we're talking about all the different voice actors that are available why don't we actually um dive into it i haven't done this before in another project but why don't we actually go and get all the different voice variable types and pull in the uu ids and let the user select what uuid uh they want to use so how do we do that um i spent about 30 minutes or so figuring out how this all works and so i added a third event but what i'll do is i'll remove this and we'll basically copy it over and i'll walk you through how we did that but before we do that i'm going to back up here to the first event that we created on number one and i think i did a decent job of walking you guys through what's happening when we're calling the authentication request but maybe i didn't explain in greater detail what's happening um when we get a response back right so we're basically we're posting a json request we're um uh sending them some values over to the api in a specific format we're uh creating a request object and then we're posting it to the url that is available for the api okay and then basically these two events are handling on request complete or on request fail handle the response back right so in the apa api call we're going out to that website uh we're going out to that url we're sending information in that url and then after that's complete we're getting a response back so this is the response section how do we understand the response a little bit better well there's this little function if i pull this off of here and i say get response content as string i think this will do a good job of explaining a little bit in more detail what's happening let's do this actually let's print a string here print string uh let's cut this one off and let's just pump in the string and then we'll choose a different color let's just pick like an orangey color and we will pick uh 60 seconds so it stays on our screen uh for a minute so it doesn't go away okay now if i uh compile and save and i run that i'm just gonna hit one uh you can see what's printed out to the screen uh we have a curly brace then we have access token then we have a big long alphanumeric string and then we have another uh refresh token and then another alphanumeric uh string and then uh close of the curly brace so that's the data that we're getting back from the api in a string format well how do we make sense of that so if we go back to the code that we're running we're essentially using this get response object so that's the response from the api and then we're running two different things on top of it so the first thing that i ran was get field names if we go back to our example um yeah so this here the access token this is the field name and this refresh token is the field name and then this is the value that's tied to that field name so all that i had done here previously was i was getting the field names to understand what are our options so you actually don't need a lot of this code this was really just printing it out to the screen out to the screen so that we could better understand the api so what i'm going to do is i'm while we're here i'm actually going to remove a lot of this we don't need the field names uh we don't need the field array oh actually we do need this for bad credentials never mind i'm going to leave that in but we don't need these two print strings then we can just leave that i'll just run that here we're using bad credentials off of this one um and technically we don't need this guy either so really we don't need this whole second field because we're not using the refresh token at all i'm just going to delete this there we go so that's really the only the code that we need so i'll leave that in there and you can see how this all works we'll pull this all back cool i don't mind that i'll leave that as is okay and then like this okay uh so where was i yeah so we have the string we printed that out okay so essentially what we're doing is we're getting the response object we're pulling out the field name and then based on that field name we're getting the array field which is that alphanumeric portion of the response object so we got the name and then the input that we need to get the array field is to tell it what name are we gonna get the access token or are we gonna get the refresh token yeah and then down here we're getting the string field so it's just a different way to get the value out of there and we want the one specifically that is access token um so the reason that that we have these two options is because i coupled the bind request fail and the on request complete um together right so in the request uh complete it's going to follow this path and on the request fail it's essentially we need this to see if it's called bad credentials that's all that that um that's all that's happening there okay cool so i think now that we understand that a little bit better um that might be helpful okay so i'm gonna delete this out of here we don't need to actually get the response object as a string that was really just to help us understand what was happening here okay so fast forward to what we've done here we're going to use the voice we're going to use the voice api so let me cut this off and i'll slide this code down and what we can do is we can potentially refer to it so i can rebuild it for you so essentially we want to do almost exactly the same as we did in the previous example so we want to construct json object or json request we're making a request out to the api we want to drive that from the three value we want that to be a get and request body okay so it's just matching oh actually we want it to be a url oh i put request body we want it to match this guy up here okay and then the same thing that we did up here where we set the json get request we bound all the events we set the header all this stuff we actually want to copy and put here we could combine this all into a function because we're running essentially the same thing but for this example i think we're only doing two so i'll have two separate things here but we could create variables and basically run a function and um have a little bit of cleaner code but for this we'll just walk through it and we'll make it happen okay um so this is setting the get request uh let's just see if there's anything so set the the get request into the variable we're using the same variable we want to bind on request complete quest fail we want to set the header we want to set request object and we want to process the url you'll notice that the url is slightly different on this one the oh i haven't updated this one yet but this one is going to be the voice url that we get out of here here's your url that we're um processing the header name is going to be the same auth authorization and then we're going to be inputting the bear token so that's all going to be the same that's why we copied that code over okay and then the response is where things are going to change a little bit so um what we want to do is we want to create an event so this one i called race array race rest json get request and i'll actually change that name to uh speech because that's the this one we're constructing the speech and then this one we will do a custom event and we will call it the exact same except we'll call it uh voice okay cool and then um yeah so then at this point this is where things got a little bit dicey for me so if you remember on the uh the authentication request we got a response object well i went and i followed the same uh line of thinking and i got a response object but the problem was is that response object kept coming up blank and so what i did is i then uh did this i said get response content as string and uh just like we did earlier print string and i printed this out to the screen we'll make this 60 seconds pull this down so we're not jammed in our code there okay and if i compile and save this what's it complaining about oh right okay no problem just plug that in there as well compile and save this and if i go to our project and i hit play i have to hit one through won't work on its own if i hit three on its own it's just going to fail right authenticate auth authorization header is invalid exception unauthorized um so if i uh it's going to fail because we don't have uh an auth authentication request set up and we don't have a bare token so now if i hit 1 you'll see that went through fine and now if i hit three you'll see that we get a uh supply of objects but the difference here uh is that instead of just having a curly brace and then a couple of options we actually have multiple sets of curly braces and so what we want to do is we want to get this response object in here this whole thing is a response object but really what we have is we have an array of um response objects whereas last time we just got a single object returned to us that we could manipulate so that's why i was running into problems so the way to work around that at least in unreal is um this so but we don't need this because we unders well you know i'll leave it because i may refer to it again to explain a few things but we don't need this um so what we're going to do is instead of getting a response object we're going to get a response value so let's drive this off of here response value and from the response value we're going to treat it as an array based on as an array because essentially that's what it is right we have an array of a whole bunch of objects and then um what we would have to do is now that we have that in an array we can pump out each one of these right so if i've got a copy so for our example here we're only going to get value zero but um we could here i'll just do this just so that we know we could get the length of the array as well i'll do that just to kind of show okay so we're going to get the first object and we're going to get the length of the array and then just to demonstrate what's going on here i am going to print string both of those things out so we will do an append and we will do four pins and we're going to say first first array value colon space uh this thing and then we'll put the length in there and we'll say array length space okay and i think actually i have to do more to this one i just realized um because that's just going to get the name of our object and we actually want more than that so let's pump this down this way pull this here and then um i think as object yeah as object i want to take the value of um yeah we want to take the value out of here we want to treat it as a json object and then we want to do what we did before get the field names and get the string field so or we can just get the string field so um here let's do this here get field names get string field okay um and then this one's going to be name and this is going to be yeah we might as well get all of them so for each loop here i'll just copy this so uh you know what i'll just do it so for each loop for each value in this array this down print out the element that's the body and then when it's completed execute this print string which is going to be the um first array value right so this guy is that's the array length and then this one is going to be name and we'll show why that's the case there okay let's compile and save this and see what happens so hit play hit one uh one's complete now hit three so there you go so oh i didn't uh i didn't put those for a meaningful amount of time uh let's pump all of these up to 60 and 60 and let's just change the colors keep us organized a little bit boom boom okay file save and let's play this out so one to connect three and then here's what we got so uh you can see here is our initial string and then basically what we did is we grabbed the first object and then we said print out the name fields well the name fields are uuid and name right and then there's values the uu id is this and the name is agatha angry what we did is we printed out agareth agatha angry uh and then we also printed out the array length of 127. so what it's saying is there's 127 of these objects in this array and what we did is we grabbed the first one and we took the name out of it okay so let's keep coming along here i realized uh i made a couple of mistakes here when i pumped that into uh a value and this is spelt incorrectly so my apologies for anyone that has ocd you're probably um ringing off the brain cells are ringing off the hook there sorry triggered um okay so this was a first array value and then space and then uh array length okay cool um yeah so what i'm thinking here is really to use this correctly we should be uh pulling all the values from uh the voice response that we got back identifying the unique values on the name and then providing those names to the user in the form of a drop-down list the user could pick the name and then based on that name we would then look for the unique values of emotions that are tied to that user allow the user to print to pick uh that value from a drop-down list and then ultimately with those two values selected go back to the array and select the appropriate uuid this tutorial is a little bit long so if people are really interested in that i can create that separate and show you that functionality we probably do that in in 10 or 15 minutes a short tutorial but this one we'll just leave it as is we'll pull one value out so we'll get instead of this being name we'll instead pull the eu id of the first value and we'll store that in a string variable so we'll just call uuid response change this to a string and then compile and save and yeah what we'll do is we'll return this value and we'll stick it to uuid response oops that should be a set and we can get rid of this print string garbage do uh we don't need the field names anymore that was just for demo and this is all it will do so we will uh and one thing that i should be doing with the arrays we don't need the string either and get rid of that this will actually be a really simple function um one thing that we should do when we're getting any array is we should make sure that the array isn't empty so um let's do this and we should be saying essentially branch or we can say greater than z uh greater than yeah and we want it greater than zero and essentially we'll only run this code if this is true so then we'll do a branch and we'll say if this condition is true then run that code and we'll go and we'll do that for our other arrays too right so um that's some of these errors that are coming up so if i opened up the message log it's probably going to say um access none right so we want to get rid of those errors so we're sometimes running it and the array is empty and then we're asking it to print things out of the array or whatnot so this will just make sure that the length is greater before we actually execute any code on top of that array cool okay so now that we've got gotten the um the ud uu id response we can actually use this uuid response in our second option here this was our get so really what we should have done is we should have done this one as number two and then this one is number three and maybe we should just fix that right now because that's an easy fix let's do it and it makes sense from a numerical order perspective right we're going to do the authentication we're going to get our lists of voices and then number three in the order is we are going to then um select the speech file that we want from uh replica okay cool so yeah so press one authenticate press two get the voice um stored in the uuid and then three construct the json [Music] we don't need this hello string i don't know why that's in there let's get rid of that and then let's let's fill in this url so if we went back to replica um we're using the speech one here so whoops we want this url which we should be creating right that's why it's not populated we've got this url uh we need the speaker id which now we have one right speaker id equals uuid response and we should be able to pump that in here oh yeah this right so let's get rid of this then delete that um get rid of this pin oh yeah in number two um and this should be set replica speaker id instead and then we can delete this yes that replica speaker id here we go boom okay and then we come back here leave that and here we can print out uh the replica speaker id if we need to we shouldn't need to now that we fixed it i'll save play okay let's see this one two three there cool so we got a valid response back now we can get rid of this this is just for troubleshooting boom one two three there so there's our response back okay so now what we want to do is we want to uh get the file back so it gave us a response but we don't actually have a um we don't actually have a um file captured so that's sort of the next step in this uh tutorials we'll grab the file okay okay so yeah now we want to make the code to handle this response and get the file downloader um so let's put in this piece of work so i believe i'm just going to look at my old code here process the url yes uh json get request okay yeah out of here get rid of this and what we can do is we can download file to storage okay and essentially what we want to do is we want to get some objects to do that so we can get the response object and in the response object we can get a string field and you saw when i had it all printed out before there was a field called uh url that's what we want and we also um then want to take this uh url and we want to pump it into our download file storage and then we want to can whoops sorry my apologies we want to convert to absolute path okay and the file save directory i don't think that we created one of these yet but let's do this let's just say file save directory and that's fine for a string and then this is where we're going to choose where does the um file get saved to in uh yeah get that we'll compile save that's fine for now and this you can just put your path so here i'll just put the colon for now i'll pump that into this and then we'll put that as our save path we'll put the timeout as a minute and then um we can use a couple of these uh event objects to monitor what we're doing so let's just clean this up a little bit okay and i think this is pretty straightforward right so basically on the response get the object get the string field which is the url from the response from the api create a file save path and then stick it in this download file to storage and then we have to basically uh create some events here right so download pro uh whoops i want to go custom event and then i want to go download download progress is one and then on complete custom event do that and we'll call this down download complete okay this one i'm actually going to stick over here because this is our happy path and the download progress so this one what it does is it'll return bytes received and the content length and so what we could do if we wanted to is we could print out and this is how you would use a status bar but essentially for our purposes because we're not doing any gui we can basically print out the status as the file is being downloaded so if we um took this out and how do we want to do this maybe we just do it this way we can go append and at the top we can say first percentage down load complete complete okay colon space and then what we can do is we can pump these values in so what do i want to do here i think i want to convert this to um a float and i want to convert this to a float okay now i have these both as floats which is good and then i want to divide one float by the other so let's do this uh float over float we'll drop that into here and so essentially we're saying the amount of bytes received divided by the entire content length is going to give us a percentage right that's all that we're doing here and then we can pump that in here right so we can have this stack and have this uh append and then essentially it'll say your your content is a total amount of bytes and then the bytes received at a time in place we will print that um out to the screen and i'll show you how that runs in a second and then we should um put this a little bit longer so let's just say this displays for 10 seconds and we change the color to like a dark green seems appropriate for this type of thing how do we get a nice dark green there we go right okay and then what else do we want to do okay so we want to figure out the results here right so there is this thing called switch on i don't know i'm not going to try reading that out switch on e download to storage result um and then basically these are all the different results that you can have so you can have a successful download so let's print out a string download was successful cool you can have the download fail string uh that one can be two seconds because it's quick fail oh come on work with me here all right whatever we're going to put down load failed we're going to put that in red because red is bad and then we're going to let this sit a little longer and then the print string and we're gonna say saving of file failed okay and then same thing we are going to that in red red and we'll display that for a little bit longer and uh that's about it um then we have the file on our computer so let's just test this out what happens if i compile nothing okay it's good okay so let's see if that worked okay so our fail saved because our save directory needs a name so let's call this realtek.wave i'll save and then let's run this one two three there are percentages of download completed and then uh we should have a file uh i'll have to troubleshoot that later but let's just see on our d drive yeah we now have this real tech file if we play it this is a test out to replica this is a test out to replica cool is that what we wrote in our um this is a test out to replica suite so now if we change this this is a change out to replica this is a change out to replica okay now that we have the file loaded on your machine uh what we need to do is we need to run that audio um and import that file uh into uh unreal uh i forgot earlier when i had you download the plugins uh i forgot there's a third plugin we need and it's this audio analysis tools plugin also free so just go ahead and grab that one in my project here we're going to go audio analysis we're going to enable it restart okay once we're restarted okay and then we're gonna go here and off of our new pin here we're gonna create runtime audio importer we are going to um bind event to on result it all start feeling somewhat similar now import audio from file okay on unresolved bent oh sorry create whoa create custom i don't know let me custom there we go add custom event and there we go on results import audio file we are going to switch on et trans coding transcoding and maybe i need to do it here switch to e transcoding status yep um this you want to play 2d sound we want yep okay the file path needs to be the file save directory the target is your return value here that's fine experiment format automatically play the 2d sound yeah could be good let's give that a go and then we can clean this all up after make sure it works so let's try this oh let's get new audio so we know that we have the right one um is now this is a changeout replica why is it getting the old file let's try that again one authenticated two authentication oh there's that three oh there i didn't wait for that i guess last time and then four the tutorial is now over okay so that does wrap it up i did go back and i added some error coding um to make sure that all of the error messaging and um the errors were handled so i put in um print strings to handle any of the error outputs so you can take a look at those i did decide to print out the get response content as string because that would sort of cheaply handle our error messaging on the failure accounts without having to you know create a whole second line of code i thought that was reasonable for what we were doing here and i put in some error checking on the length of an array to make sure that we weren't processing on any of our arrays if they didn't have content in them so you'll find that that has been included in each section and that's it so thanks for following along if you want access to the project files as i mentioned earlier you can get that from my patreon page on my channel up at the top right that will take you to the patreon page where i will upload all of these files you can contribute whatever amount you want just be aware that when you do put in an amount it is putting in a monthly charge um so just recognize that that's recurring and if you don't want it to be a one-time thing then make sure to cancel um with patreon right away or you know happy to have you know a couple of buck support um for the work that i'm doing so uh whatever you choose to do we're just trying to make this accessible for everybody and just cover off uh some of my minor costs here for hosting and doing that sort of stuff um that's it so uh officially let's run the project and show you how it's working with the error coding what we want to do is we want to delete the file if we have one run this hit four failure three failure two failure and then if we run it in correct order here's the final output the tutorial is now over and now the tutorial is the tutorial is now over it is
Info
Channel: Fractured Fantasy
Views: 13,450
Rating: undefined out of 5
Keywords: Replica studios, Unreal engine, Replica api, Blueprints API, API Unreal Engine, API tutorial for blueprints, How to access an API using blueprints, UE5, UE4, UE4.27, UE 4.27, Unreal Engine 4.27, Text to speech API, Text to speech unreal engine, Lip sync API unreal engine, VA Rest, VA Rest API, VA Rest Plugin, Audio Analysis tool, Runtime Files Downloader, Unreal Json request, Json Post, Json Get, Json API, HTTP API
Id: 5JJvcv7Fr-k
Channel Id: undefined
Length: 77min 47sec (4667 seconds)
Published: Wed Nov 24 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.