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 Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

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
Loading ..................

Console