Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Create a Testimonial box switcher using HTML CSS & JavaScript
Next article icon

Build a Text to Speech Converter using HTML, CSS & Javascript

Last Updated : 21 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A text-to-speech converter is an application that is used to convert the text content entered by the user into speech with a click of a button. A text-to-speech converter should have a text area at the top so that, the user can enter a long text to be converted into speech followed by a button that converts the entered text into speech and plays the sound on click to it.

Here, we will build a fully responsive text-to-speech converter using HTML, CSS, and JavaScript.

Project Preview:

Text-to-Speech converter preview

Approach

  • Create a folder with the project name and create the required HTML, CSS, and JavaScript files as shown in the project structure.
  • Now, use the HTML tags like textarea, button, div, head, body etc. to define the structure of the website.
  • Add the styles to the HTML tags used to define the structure by selecting them with the help of given IDs and Classes.
  • Utilise the speechSynthesis API of the global window object and the SpeechSynthesisUtterance to create a utteraance of the entered text.
  • Next, use the speak() method of the speechSynthesis API to speak or play the created utterance as a speech.
  • Handle the errors efficiently if user have not provided any text to convert.

Example: The below example will help you to understand the process of creating an text-to-speech converter using HTML, CSS, and JavaScript:

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content=         "width=device-width, initial-scale=1.0">     <title>Text to Speech Converter</title>     <link rel="stylesheet" href="style.css"> </head>  <body>     <div class="container">         <div class="app-container">             <div class="headings-container">                 <h1>Text to Speech Converter</h1>                 <h3>Enter Text and Convert into Speech</h3>             </div>              <div class="interaction-container">                 <textarea id="textToConvert"                      placeholder="Enter text to convert into speech..."                      id="" cols="35" rows="10"                      class="text-control"></textarea>                  <p class="error-para"></p>                  <button class="btn" id="convertBtn">                     Play Converted Sound                 </button>             </div>         </div>     </div>      <script src="script.js"></script> </body>  </html> 
CSS
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');  body {     padding: 0;     margin: 0;     box-sizing: border-box;     font-family: "Poppins", sans-serif; }  .container {     height: 100vh;     width: 100%;     display: flex;     align-items: center;     justify-content: center;     background-image: linear-gradient(90deg, #161578, #b81055); }  .app-container {     display: flex;     align-items: center;     justify-content: center;     flex-direction: column;     text-align: center;     color: #fff; }  .headings-container {     padding: 0 1rem; }  .interaction-container {     display: flex;     align-items: normal;     justify-content: center;     flex-direction: column;     text-align: center;     padding: 0 1rem; }  .text-control {     padding: 0.5rem;     margin: 2rem 0;     background-color: #3f464a52;     color: #fff;     border: 1px solid #fff;     border-radius: 10px; }  .text-control:focus-visible {     outline: none; }  .error-para {     color: red; }  .btn {     padding: 0.8rem;     background-image: linear-gradient(90deg, #F4244C, #F57D4E);     border: 1px solid transparent;     border-radius: 10px;     color: #fff;     cursor: pointer;     transition: all 0.25s; }  .btn:hover {     padding: 1rem; } 
JavaScript
const text = document.getElementById("textToConvert"); const convertBtn = document.getElementById("convertBtn");  convertBtn.addEventListener('click', function () {     const speechSynth = window.speechSynthesis;     const enteredText = text.value;     const error = document.querySelector('.error-para');      if (!speechSynth.speaking &&         !enteredText.trim().length) {         error.textContent = `Nothing to Convert!          Enter text in the text area.`     }          if (!speechSynth.speaking && enteredText.trim().length) {         error.textContent = "";         const newUtter =             new SpeechSynthesisUtterance(enteredText);         speechSynth.speak(newUtter);         convertBtn.textContent = "Sound is Playing..."     }          setTimeout(() => {         convertBtn.textContent = "Play Converted Sound"     }, 5000); }); 

Output:

TexttoSpeechConverterFinal
Final Output
Note: You will not able to hear the voice as it is an gif so kindly run this project locally on any Online IDE(Replit, etc.)



Next Article
Create a Testimonial box switcher using HTML CSS & JavaScript

A

abhish8rzd
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Projects

Similar Reads

  • Create a Testimonial box switcher using HTML CSS & JavaScript
    In this article, we will develop an interactive Testimonial box switcher application using HTML CSS & JavaScript Language. In this application, we have a Card component that has the message given by the testimonial, also there is information about the person and his/her designation. The card com
    4 min read
  • How To Build Notes App Using Html CSS JavaScript ?
    In this article, we are going learn how to make a Notes App using HTML, CSS, and JavaScript. This project will help you to improve your practical knowledge in HTML, CSS, and JavaScript. In this notes app, we can save the notes as titles and descriptions in the local storage so the notes will stay th
    4 min read
  • Create a Length Converter using HTML CSS and JavaScript
    In this article, we will learn how to create a length converter using HTML, CSS, and JavaScript. The Length Converter is an intuitive web-based application that eliminates the complexities associated with manual conversions. Its user-friendly interface allows users to input a numerical value and sel
    6 min read
  • HTML Code to JSON Converter App Using HTML, CSS, and JavaScript
    HTML tables are a common way to represent structured data on web pages, but transforming this data into a JSON format can be troublesome. JSON is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. We will be creating the HTML Code
    3 min read
  • Design a Unit Converter using HTML CSS and JavaScript
    In this article, we will be developing an interactive and styled unit converter using HTML, CSS, and JavaScript.In this application, we have a select category option box in which different types of units are specified, like temperature, area, weight, length, and time. As per the user selection, the
    7 min read
  • How to Create Stopwatch using HTML CSS and JavaScript ?
    In this article, we will learn How to create a Stopwatch using HTML CSS, and JavaScript. The StopWatch will have the Start, Stop, and Reset functionality. Prerequisites:HTML CSS JavaScriptApproach:Create one container in which all the elements are present.Inside this container add 2 divs that contai
    3 min read
  • How to create Sentence Translator using HTML, CSS, and JavaScript ?
    In this article, we are going to make a sentence translator app with the help of API using JavaScript. Basic setup: Open VS Code and open a folder from your drive where you want to create this project and give the name Translate-Sentence(folderName). After opening create the following files: index.h
    3 min read
  • Build a Piano using Html, CSS and JavaScript
    In this article, we will build a piano using HTML, CSS, and JavaScript. A piano is a musical instrument consisting of different keys that produce different sounds to create a sweet musical sound when used in a particular sequence. Similarly, a piano app also contains keys that produce different soun
    4 min read
  • Create a User Polls Project using HTML CSS & JavaScript
    Creating a user polls project has various valuable purposes, including gathering feedback, engaging users, personalizing content, fostering community, conducting research, A/B testing, and improving the user experience. Clear objectives are crucial, and in this example, we focus on collecting data o
    3 min read
  • How to create Popup Box using HTML CSS and JavaScript?
    Creating a popup box with HTML, CSS, and JavaScript improves user interaction on a website. A responsive popup appears when a button is clicked, featuring an HTML structure, CSS for styling, and JavaScript functions to manage visibility. ApproachCreate the Popup structure using HTML tags, Some tags
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences