cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container">
  <h1>robot says:</h1>
  <div class="body-content">
    <!-- dropdownのやつ -->
    <select name="voice" id="voices">
      <option value="">Select A Voice</option>
    </select>
    <!-- rateのやつ -->
    <label for="rate">Rate:</label>
    <input name="rate" type="range" min="0" max="3" value="1" step="0.1">
    <!-- pitchのやつ -->
    <label for="pitch">Pitch:</label>
    <input name="pitch" type="range" min="0" max="2" step="0.1">
    <!-- textareaのやつ -->
    <textarea name="text">Hello, I'm lucky man</textarea>
    <div id="speak">Speak</div>
  </div>
</div>
            
          
!
            
              * {
  margin: 0;
  padding: 0;
}

html {
  background: #f7f7f7;
}

.container {
  width: 500px;
  margin: 30px auto;
  background: white;
}

.container > h1 {
  background: #3B5998;
  color: #fff;
  text-align: center;
  padding: 20px 0;
}

.body-content {
  padding: 30px;
}

.body-content > select,
.body-content > label,
.body-content > input,
.body-content > textarea {
  display: inline-block;
  width: 440px;
}

.body-content > select,
.body-content > textarea {
  background: #f7f7f7;
  outline: 0;
  border: 0;
}

.body-content > select {
  font-size: 16px;
}

.body-content > textarea {
  height: 100px;
  font-size: 18px;
}

#speak {
  cursor: pointer;
  font-size: 25px;
  color: #fff;
  background: #3B5998;
  text-align: center;
}

            
          
!
            
              var msg = new SpeechSynthesisUtterance();
var voices = [];
var voicesDropdown = document.querySelector('[name="voice"]');
var options = document.querySelectorAll('[type="range"], [name="text"]');
var speakBtn = document.querySelector('#speak');
msg.text = document.querySelector('[name="text"]').value;

function populateVoices() {
  voices = this.getVoices();
  voicesDropdown.innerHTML = voices
  .map(voice => `<option value="${voice.name}">${voice.name}`)
  .join();
}

function setVoice() {
  msg.voice = voices.find(voice => voice.name === this.value);
  // 声音を選択したら即時実行する
  toggle();
}

function toggle() {
  speechSynthesis.cancel();
  speechSynthesis.speak(msg);

}

function setOption() {
  msg[this.name] = this.value;
  // 変更があったら即時実行する
  toggle();
}

speechSynthesis.addEventListener('voiceschanged', populateVoices);
voicesDropdown.addEventListener('change', setVoice);
options.forEach(option => option.addEventListener('change', setOption));
speakBtn.addEventListener('click', toggle);

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console