Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Text To Speech Converter</title>
    <!-- Font Awesome CDN -->
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
    />
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="container">
      <div class="controls">
        <button class="btn" id="resume">
          <i class="fa-solid fa-play"></i>
        </button>
        <button class="btn" id="pause">
          <i class="fa-solid fa-pause"></i>
        </button>
      </div>
      <textarea
        placeholder="Enter some text here.."
        id="txt"
        rows="6"
      ></textarea>
      <button id="submit" type="submit">Submit</button>
    </div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

              
            
!

CSS

              
                * {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}
body {
  height: 100vh;
  background: #304988;
}
.container {
  background-color: #ebf2ff;
  width: 90%;
  max-width: 37.5em;
  position: absolute;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
  border-radius: 0.5em;
  padding: 2em;
  box-shadow: 0 1.87em 3.75em rgba(2, 14, 44, 0.2);
}
textarea {
  font-size: 1em;
  width: 100%;
  border-radius: 0.5em;
  padding: 1em;
  resize: none;
  border: 0.12em solid #040454;
}
#submit {
  font-size: 1.2em;
  display: block;
  width: 50%;
  position: relative;
  margin: auto;
  padding: 1em;
  border: none;
  background: #304988;
  color: #ebf2ff;
  border-radius: 0.3em;
  cursor: pointer;
  margin-top: 2em;
}
.controls {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1em;
}
.controls button {
  display: block;
  width: 3em;
  height: 3em;
  font-size: 1em;
  border-radius: 0.3em;
  cursor: pointer;
  color: #4c7df8;
  border: 0.12em solid #4c7df8;
  background-color: transparent;
}

              
            
!

JS

              
                let text = document.getElementById("txt");

let submitBtn = document.getElementById("submit");
let resumeBtn = document.getElementById("resume");
let pauseBtn = document.getElementById("pause");
let audioMessage;

submitBtn.addEventListener("click", () => {
  //set the text
  audioMessage.text = text.value;
  //speak the text
  window.speechSynthesis.speak(audioMessage);
});

resumeBtn.addEventListener("click", () => {
  pauseBtn.style.display = "block";
  resumeBtn.style.display = "none";
  //resume the audio if it is paused
  if (speechSynthesis.pause) {
    speechSynthesis.resume();
  }
});

pause.addEventListener("click", () => {
  pauseBtn.style.display = "none";
  resumeBtn.style.display = "block";
  //pause if speaking
  speechSynthesis.speaking ? speechSynthesis.pause() : "";
});

window.onload = () => {
  resumeBtn.style.display = "none";
  if ("speechSynthesis" in window) {
    audioMessage = new SpeechSynthesisUtterance();
  } else {
    alert("Speech Synthese is not supported");
  }
};

              
            
!
999px

Console