SpeechSynthesisUtterance:pitch 属性
pitch
属性是 SpeechSynthesisUtterance
接口的一部分,用于获取和设置语音朗读时的音调。
如果未设置,则将使用默认值 1。
值
示例
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 (let i = 0; i < voices.length; i++) {
if (voices[i].name === selectedOption) {
utterThis.voice = voices[i];
}
}
utterThis.pitch = 1.5;
synth.speak(utterThis);
inputTxt.blur();
};
规范
规范 |
---|
Web 语音 API # dom-speechsynthesisutterance-pitch |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。