
Repo Coming Soon!
--- type: transcript date: 2023-11-07 youtube_id: eIznC00hI-Y --- # Transcript: Get Started in 6 Minutes with the Brand New Text-To-Speech API from OpenAI in Bun/Node.js right in this video I'm going to be showing you how to set up the new text to speech functionality from open eyes API in nodejs so the first thing that you're going to do is just create a new project so I use bun so if you just go ahead and bun in it you can go through and select whether you want to use a Javascript file or typescript file um run through those commands once that's all set up you're going to have the package Json set up the index.js all set up now the first thing that we're going to install and only thing for that matter is we're going to go ahead and then just bun install the opening I so once that is all set up you can go ahead and create a EnV so if you just touch touch. EnV you'll have thatv file here now in your EnV you'll have to get a API key from platform. open.com account AI Keys once you have that key go ahead and put it in a variable just like this so open aore aior key and paste it in there so once you've done that you can go ahead uh save out your EnV and we'll just start running through the code here so the first thing we're going to import is the file system module as well as the path so this is going to be so we can actually save out the file once the response has been returned so next we're going to import the open AI SDK and then we're going to initialize the open a client so if you're using the most recent version and you will need it in this case the V4 version of the node SDK you don't actually need to explicitly pass in the uh process. EnV and all of that for the open uh AI API key so that's sort of the nice combination with running bun or the most recent version of a believe node also has that where you don't need to explicitly import something like EnV to read your environment variables so you can just initialize your uh open AI client just like that then this is going to be where we save out our file here so so I'm just using the date in this example feel free to use whatever you'd like though so first we're just going to wrap our whole application in an synchronous function here and then first what we're going to do is we're going to establish how we're going to interact with the open AI API So within their SDK the way that we do this is we're going to be awaiting the audio speech and we're going to be passing in a couple different options here so there's a couple model options that you have here there's the tts1 and then there's also the TTS 1-hd so HD as you might imagine that's a higher quality version it's also twice as expensive as the tts1 version so in terms of the voices I have them all in line here the different voices that you can choose from there's not as many as something like 11 Labs has where there's just like hundreds or seemingly thousands of voices a lot anyway in comparison but there is enough and these generally sound pretty good in my opinion so next we're going to put in our input so I just put in a simple this is an example of open ai's new text to speeech API to demonstrate on developers digest YouTube channel I also ran this through um a character counter just to show you how much this would cost so this is going to be 210 of a penny to run this uh input here with their uh tts-1 model so to uh if you wanted to use the uh tts-1 DHT model it would just be double the price so next we're going to log out and then we're going to be converting the response to a buffer that we're going to be writing to which will save just to the root of our directory here then we're going to write out our file and then simply run it so a couple things uh I just wanted to include in the file here so like I mentioned in terms of the cost of the API so it is relatively cheap like a line like this you know two10 of a penny for this if you're going to be doing a lot of text obviously cost a lot more but pretty self-explanatory in that regards now the one thing I did want to point out is the usage notice so within the API docs it's very explicit that if you're using this you have to disclose that this is an AI generated voice and not a human voice so I'd like to think that most people would probably hear these models and even though they're pretty good still be able to distinguish that it is AI generated but you will have to include that within your application so next I just wanted to include a handful of references here um for the API Keys pricing and docs if you need them so now if I just go ahead and save this out and run our application here I'll just show you what it sounds like so you see it's very quick to get the response back and if I just go ahead and run this I'll also turn up my speakers here this is an example of open ai's new text to speech API to demonstrate on Developers digest's YouTube channel so I'll also swap out a couple different options here so I'll show you their HD version so if I just run this again we can compare that this is an example of open ai's new text to speeech API to demonstrate on developers d YouTube channnel so in my opinion I don't think that that is worth twice the cost for that difference I don't notice that much of a difference for the HD model to be honest at least not yet and then if I just swap out uh some of one of the voices here let's just try a different one here this is an example of open ai's new text to speech API to demon r on developers digest YouTube channel so that's it for this one if you found this video useful please like comment share and subscribe over the week uh following this video I'll be releasing a lot of content around opening eyes recent announcements so if you're looking for more content within node JavaScript nextjs feel free to subscribe to the Channel all of a lots coming over the coming days here
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.
Weekly deep dives on AI agents, coding tools, and building with LLMs - delivered to your inbox.
Free forever. No spam.
Subscribe FreeNew tutorials, open-source projects, and deep dives on coding agents - delivered weekly.