• We just launched and are currently in beta. Join us as we build and grow the community.

JavaScript - Convert Text to Speech

bll97569

Email Campaign Revenue Specialist
B Rep
0
0
0
Rep
0
B Vouches
0
0
0
Vouches
0
Posts
116
Likes
159
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this tutorial we will create a Convert Text to Speech using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is a text-based programming language meant to run as part of a web-based application. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...

Getting started:

This is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    Javascript - Convert Text to Speech</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted;"

    /

    >
  17. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  18. <div

    class

    =

    "col-md-6"

    >
  19. <div

    class

    =

    "form-group"

    >
  20. <label

    >

    Enter a text</

    label

    >
  21. <input

    type

    =

    "text"

    id

    =

    "text"

    class

    =

    "form-control"

    /

    >
  22. <br

    /

    >
  23. <center

    ><button

    type

    =

    "button"

    class

    =

    "btn btn-default"

    onclick

    =

    "Speak()"

    >

    Play</

    button

    ></

    center

    >
  24. </

    div

    >
  25. </

    div

    >
  26. </

    div

    >
  27. </

    body

    >
  28. <script

    src

    =

    "js/responsive-voice.js"

    ></

    script

    >
  29. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  30. </

    html

    >

Creating the Script

This code contains the script of the application. This code will convert the input text into speech. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.
  1. function

    Speak(

    )

    {
  2. var

    text =

    document.getElementById

    (

    'text'

    )

    ;
  3. if

    (

    text.value

    ==

    ""

    )

    {
  4. alert(

    "Please enter some text"

    )

    ;
  5. }

    else

    {
  6. responsiveVoice.setDefaultVoice

    (

    "US English Male"

    )

    ;
  7. responsiveVoice.speak

    (

    text.value

    )

    ;
  8. text.value

    =

    ""

    ;
  9. }
  10. }

Note: To make the speech work make sure you download the plugin here https://responsivevoice.org/

⚙ Live Demo

There you have it we successfully created a Convert Text to Speech using Javascript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

336,529

336,537

Top