Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <div class="slick-slider">

  <div class="full-card">

    <div class="font-card roboto-card">
      <h3 class="font--roboto">Text to Speech</h3>
      <p class="font--roboto">
      <div class="container mt-4 text-center">
        <label for="voiceList">Select Voice:</label> <br>
        <select id='voiceList'></select> <br><br>
        <label for="txtInput">Type here</label><br>
        <input id='txtInput' /> <br><br>
        <button id='btnSpeak' class="explore-button btn btn-primary animation-on-hover">Speak!</button>
    </div></p>
    </div>

    <div class="font-description">
      <h2 class="font--robotoslab">Text<span class="font--roboto"> to Speech</span></h2>
      <p class="font--roboto">This project allows you to convert text to speech in a single click. Just type what you want and it is converted to speech. Feel free to use it in other projects. This is just a demonstration of how this can be achieved via Vanilla JS.</p>
    </div>

  </div>



</div>
              
            
!

CSS

              
                ///////////DECLARE FONTS///////////
.font--robotoslab {
  font-family: 'Roboto Slab', Georgia, serif;
  font-weight: 700;
}

.font--roboto {
  font-family: 'Roboto', Arial, sans-serif;
  font-weight: 400;
}

.font--lobster {
  font-family: 'Lobster', cursive;
  font-weight: 400;
}

.font--cabin {
  font-family: 'Cabin', Arial, sans-serif;
  font-weight: 400;
}

.font--eczar {
  font-family: 'Eczar', Georgia, serif;
  font-weight: 700;
}

.font--gentium {
  font-family: 'Gentium Basic', Georgia, serif;
  font-weight: 400;
}

///////////END DECLARE FONTS///////////


* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: 'Roboto', Georgia, sans-serif;
  font-weight: 400;
  overflow: hidden;
}

body {
  background: linear-gradient( to bottom, #EDF1F2, #D5E2F2);
  justify-content: center;
  align-items: center;
  font-size: 14px;
  display: flex;
}

h1 {
  font-size: 3.5em;
  margin: 0;
  font-weight: normal;
}

h2 {
  font-size: 3em;
  margin: 0;
  font-weight: normal;
}

h3 {
  font-size: 2.5em;
  margin: 0;
  font-weight: normal;
}

h4 {
  font-size: 2.125em;
  margin: 0;
  font-weight: normal;
}

h5 {
  font-size: 1.75em;
  margin: 0;
  font-weight: normal;
}

h6 {
  font-size: 1.25em;
  margin: 0;
  font-weight: normal;
}

.author {
  position: absolute;
  bottom: 5px;
  right: 15px;
  color: #999;
  a {
    color: #A1BEE6;
    text-decoration: none;
    &:hover {
      color: #327CCB;
    }
  }
}


.bx-viewport {
  overflow: visible !important;
}

.bx-pager {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}

.bx-wrapper .bx-pager.bx-default-pager a {
  background: #666;
  text-indent: -9999px;
  display: block;
  width: 15px;
  height: 15px;
  margin: 0 10px;
  outline: 0;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.bx-wrapper .bx-pager.bx-default-pager a:hover,
.bx-wrapper .bx-pager.bx-default-pager a.active {
  background: rgba(0, 0, 0, 0.7);
}

.full-card {
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 60px;
  height: 80vh;
  max-height: 600px;
  background: white;
  width: 90%;
  max-width: 1300px;
  box-shadow: 0 15px 20px -15px rgba(0, 0, 0, 0.3), 0 55px 50px -35px rgba(0, 0, 0, 0.3), 0 85px 60px -25px rgba(0, 0, 0, 0.1);
}

.font-card {
  position: relative;
  width: 28%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: linear-gradient(45deg, rgba(159, 190, 230, 1) 0%, rgba(223, 234, 238, 1) 100%);
  ;
  padding: 20px 20px;
  color: white;
  margin: 0 15px;
  text-align: center;
  box-shadow: 0 15px 20px -15px rgba(0, 0, 0, 0.3), 0 55px 50px -35px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.3s, transform 0.3s;
  transition-delay: 0.15s;
  &.hovered-card {
    box-shadow: 0 5px 3px -5px rgba(0, 0, 0, 0.3), 0 2px 8px -5px rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
  }
  p {
    line-height: 1.4;
  }
}

.font-description {
  padding: 0 30px;
  margin: 15px;
  width: 44%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  h2 {
    color: rgb(86, 87, 94);
    span {
      color: rgb(210, 210, 210);
    }
  }
  p {
    padding-left: 15px;
    color: #777;
    line-height: 1.8;
    &:before {
      content: "\2014";
      margin-left: -15px;
      margin-right: 4px;
    }
  }
}

.explore-button {
  font-size: 0.9em;
  background: white;
  width: 80%;
  color: #a7a7a7;
  display: inline-block;
  padding: 1em;
  margin-top: 2em;
  border-radius: 5em;
  text-transform: uppercase;
  text-decoration: none;
  letter-spacing: 0.15em;
  box-shadow: 0 15px 20px -10px rgba(0, 0, 0, 0.3);
  transition: color 0.6s, box-shadow 0.3s, transform 0.3s;
  &:hover {
    box-shadow: 0 3px 5px -5px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
    color: #6f6f6f;
  }
}

@media screen and (max-width: 991px) {
  .full-card {
    height: auto;
    flex-wrap: wrap;
    padding: 30px 60px;
  }
  .font-card {
    width: calc(100% - 30px);
  }
  .font-description {
    width: 100%;
  }
}

////////////////BACKGROUNDS////////////////

.robotoslab-card {
  background: url(https://res.cloudinary.com/dqj168cdc/image/upload/v1480286526/Roboto-slab-image_mtwren.jpg) no-repeat center center;
}

.roboto-card {
  background: #171717;
  background-size: cover;
}

.lobster-card {
  background: url(https://res.cloudinary.com/dqj168cdc/image/upload/v1480349796/lobster-image_pznrao.jpg) no-repeat center center;
  background-size: cover;
}

.cabin-card {
  background: url(https://res.cloudinary.com/dqj168cdc/image/upload/v1480350297/cabin-image_dqxlwi.jpg) no-repeat center center;
  background-size: cover;
}

.eczar-card {
  background: url(https://res.cloudinary.com/dqj168cdc/image/upload/v1480522564/turtle-image_nblim1.jpg) no-repeat center center;
  background-size: cover;
}

.gentium-card {
  background: url(https://res.cloudinary.com/dqj168cdc/image/upload/v1480522983/penguin-image_dufrwg.jpg) no-repeat center center;
  background-size: cover;
}

////////////////END BACKGROUNDS///////////////
              
            
!

JS

              
                var voiceList = document.getElementById('voiceList');
var txtInput = document.getElementById('txtInput');
var btnSpeak = document.getElementById('btnSpeak');


var tts = window.speechSynthesis;
var voices = [];

getVoices();

if(speechSynthesis !== undefined){
  speechSynthesis.onvoiceschanged = getVoices;
}

btnSpeak.addEventListener('click', () => {
    var toSpeak = new SpeechSynthesisUtterance(txtInput.value);
    var selectedVoiceName = voiceList.selectedOptions[0].getAttribute('data-name');
    voices.forEach((voice) => {
        if (voice.name === selectedVoiceName) {
            toSpeak.voice = voice;
        }
    });
    tts.speak(toSpeak);
});

function getVoices(){
  voices = tts.getVoices();
  voiceList.innerHTML = '';
  voices.forEach((voice) => {
    var item = document.createElement('option');
    item.textContent = voice.name;
    item.setAttribute('data-lang', voice.lang);
     item.setAttribute('data-name', voice.name);
    voiceList.appendChild(item);
    
  });
  voiceList.selectedIndex = 0;
}
              
            
!
999px

Console