MDN self-hosted library · e01.org

SpeechSynthesisUtterance: volume property

Web Speech API

Open notebook · 1 cells web-api-instance-property upstream source

Web Speech API

The volume property of the SpeechSynthesisUtterance interface gets and sets the volume that the utterance will be spoken at.

If not set, the default value 1 will be used.

Value

A float that represents the volume value, between 0 (lowest) and 1 (highest.)

If SSML is used, this value will be overridden by prosody tags in the markup.

Examples

const synth = window.speechSynthesis;

const inputForm = document.querySelector("form");
const inputTxt = document.querySelector("input");
const voiceSelect = document.querySelector("select");

const voices = synth.getVoices();

// …

inputForm.onsubmit = (event) => {
  event.preventDefault();

  const utterThis = new SpeechSynthesisUtterance(inputTxt.value);
  const selectedOption =
    voiceSelect.selectedOptions[0].getAttribute("data-name");
  for (const voice of voices) {
    if (voice.name === selectedOption) {
      utterThis.voice = voice;
    }
  }
  utterThis.volume = 0.5;
  synth.speak(utterThis);
  inputTxt.blur();
};

Specifications

Browser compatibility

See also