Find The Latest Tech Insights, News and Updates to Read

How to Build a Voice Chatbot with PlayHT in Node.js

Written by Karan Kumar | Oct 12, 2023 4:43:11 PM

Get Started with PlayHT

Play.ht is a cutting-edge platform that empowers developers, content creators, and businesses to convert text into natural, human-like speech effortlessly. In this article, we'll explore how to leverage Play.ht's capabilities, where you can access its services and the range of offerings it provides.

Play.ht is revolutionizing the way we interact with digital content by enabling the generation of lifelike voices for various applications, from chatbots to audiobooks and beyond. With its simple yet powerful API, integrating voice generation into your projects has never been easier.

Key Takeaways
  • PlayHT in Node.js empowers developers to build voice chatbots that enhance user interactions through natural language processing and voice recognition.
  • By harnessing PlayHT, you can design personalized and interactive voice-driven experiences, improving user engagement and satisfaction.
  • Voice chatbots offer exciting possibilities for various applications, from customer support to virtual assistants, opening doors to innovative solutions in the tech world.

Where Can You Use Play.ht

Play.ht's versatility makes it a valuable tool across a wide array of applications:

  • Voice Assistants: Enhance your voice assistant's capabilities by integrating natural-sounding voices, improving user interactions.
  • Chatbots: Create engaging and informative chatbots that can converse with users more effectively.
  • Audiobooks: Turn your written content into audiobooks with professional narration.
  • Accessibility: Improve the accessibility of your digital content by offering audio versions for users with visual impairments.
  • E-Learning: Make online courses and educational content more engaging with voiceovers.
  • Entertainment: Add narration to podcasts, video games, and more to captivate your audience.

Services Provided by Play.ht

Play.ht offers a range of services to cater to your specific needs:

  • Text to Speech (TTS): The core feature of Play.ht, which converts written text into spoken words.
  • Voice Customization: Tailor voices to match your brand's personality or create unique character voices for gaming and storytelling.
  • Multiple Languages: Access a multitude of languages and accents, ensuring your content reaches a global audience.
  • Realistic Intonation: Play.ht's technology provides natural intonation, making the generated speech sound remarkably human.
  • API Integration: Seamlessly integrate Play.ht's capabilities into your applications and platforms via their API.

Play.ht currently has two APIs

Before you can start using our API, you need to generate an API Secret Key and obtain your User ID. These are essential to authenticate your requests and access the API's features.

After setting up your key, proceed to our step-by-step guide to get your first audio generated.

Supported Plans

To get more info about the supported plans and available words, please visit https://play.ht/pricing/.

If you need further support, please refer to https://help.play.ht/.

Hire talented Node.js developers to build a cutting-edge Voice Chatbot with PlayHT. Elevate your customer engagement and transform user experiences with the power of vocal AI.

How to use PlayHT Api’s in Node js

In this article, we delve into the fascinating world of voice cloning and ultra-realistic voices through Node.js. We'll guide you through a project where users can not only clone their own voices but also utilize these ultra-realistic voices to convert text into speech.

Imagine the power of hearing your own words spoken back to you in your very own voice, or experimenting with different ultra-realistic voices for various applications. Join us on this journey to explore the innovative possibilities that voice cloning and ultra-realistic voices bring to the realm of text-to-speech technology.

Let's start :-   

Before diving into the exciting world of voice cloning and ultra-realistic voices with Node.js, let's make sure you have everything set up correctly.

1. Install Node.js:

If you haven't already, you'll need to install Node.js on your system. Node.js is a crucial runtime environment for running JavaScript on your machine.

You can download Node.js from the official website nodejs.org. Be sure to choose the version that best suits your operating system.

2. Check Node.js Version:

Once you've installed Node.js, open your terminal or command prompt and type the following command to check if Node.js and npm (Node Package Manager) have been successfully installed:


Node version something like that: 18.0.01 

Setting Up Your Node.js Project:

To get started with your Node.js project, begin by creating a folder with a name of your choice; let's call it <YOUR_FOLDER_NAME>. Inside this folder, you'll want to add your main server file, often named index.js or something similar. This is where your application's core logic will reside.

Next, you'll need to initialize your Node.js project to manage dependencies. You can do this by running the npm init -y command within your project folder. This command will generate a package.json file, which holds metadata about your project.

To incorporate useful packages like Express.js for building web applications, you can use the npm install command, followed by the package name. For example, to add Express, you'd run npm install express. This action will not only install the package but also generate a package-lock.json file, ensuring consistent dependency versions.

With your folder structure, main server file, package.json, and package-lock.json in place, you're ready to start building your Node.js application with the necessary dependencies.

 

Then our folder looks like this 

your project folder will take on the structured appearance described above.

1. Voice Cloning Api

In the next, we'll explore the intriguing process of cloning your own voice into a customized 'cloned voice.' We'll dive into the details of how to achieve this unique transformation. Following that, we'll delve into the world of API integration in Node.js, demonstrating how to harness the power of APIs to make your projects more dynamic and engaging.

Replace <YOUR_SECRET_KEY_HERE> and <YOUR_USER_ID_HERE> with your actual API Secret Key and User ID.
Notice that the Bearer prefix is absent in the request above (because it goes to a /v1/** 

endpoint). For /v2/** endpoints, you will need it:

The provided statement refers to the information obtained from an API response. It suggests that the content or data displayed subsequently in the article is a result of the response received from certain API endpoints or services.

2. Generate Audio From text Api

After successfully creating a clone of your voice, the next step involves harnessing the power of ultra-realistic APIs. These APIs are specifically designed to transform text into speech with an astonishing level of realism and authenticity. The combination of your cloned voice and these advanced APIs opens up a world of possibilities, enabling you to create text-to-speech applications that sound remarkably human. Dive into the future of voice technology with this groundbreaking fusion of voice cloning and ultra-realistic speech synthesis

This api creates text to speech :

 

In this API, you can retrieve text-to-speech job data by providing the unique ID obtained from the "create text-to-speech" API. By using this ID, you can access the output URL, which likely contains the generated audio file. This functionality allows you to efficiently manage and retrieve the results of your text-to-speech conversion jobs, enabling seamless integration of generated audio into your applications or services.

3. Get text-to-speech job data


This API offers a versatile way to retrieve information about a text-to-speech job. Depending on the 'Accept' header specified in the request, the API responds with various types of data.

When 'Accept' is set to 'application/json' or '/', it provides detailed information regarding the requested job. This includes the job's status, progress, and other relevant details. The response carries a 'Status 200 - OK' message.

For those interested in real-time updates on the job's progress, specifying 'Accept' as 'text/event-stream' (or using the query parameter '?format=event-stream') yields a text event-stream. This stream continually updates with valuable insights into the job's ongoing status, and the response is marked with 'Status 200 - OK'.

Lastly, if the aim is to obtain the actual audio output in MP3 format, setting 'Accept' to 'audio/mpeg' (or using '?format=audio-mpeg' in the query) results in a byte stream of the generated audio file. This is perfect for acquiring the synthesized speech in a listenable format. It also includes a 'Status 200 - OK' message. However, in the event that the file couldn't be generated as an MP3, it will gracefully return 'HTTP 406'. This flexibility in response types caters to a wide range of use cases and preferences when interacting with the text-to-speech job retrieval API.

Using this API i can get output data. Here the URL is our result URL is our link of mp3 file.

Conclusion

In conclusion, Play.ht is a game-changing platform that simplifies the process of generating human-like speech from text. With its user-friendly interface, diverse voice options, and wide range of applications, Play.ht opens up a world of possibilities for developers and content creators alike. Whether you're looking to enhance user experiences, create engaging content, or improve accessibility, Play.ht has the tools and technology to help you achieve your goals.