Baseline Widely available
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.
ValueA 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.
Examplesconst 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 (let i = 0; i < voices.length; i++) {
if (voices[i].name === selectedOption) {
utterThis.voice = voices[i];
}
}
utterThis.volume = 0.5;
synth.speak(utterThis);
inputTxt.blur();
};
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3