Back to Content

SpeechSynthesisUtterance: volume property

files/en-us/web/api/speechsynthesisutterance/volume/index.md

latest1.3 KB
Original Source

{{APIRef("Web Speech API")}}

The volume property of the {{domxref("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

js
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

{{Specifications}}

Browser compatibility

{{Compat}}

See also