SpeechSynthesisUtterance: pitch 屬性
pitch 屬性是 SpeechSynthesisUtterance 介面的一部分,用於獲取和設定發音時的音高。
如果未設定,將使用預設值 1。
值
一個表示音高值的浮點數。它的範圍可以是從 0(最低)到 2(最高),其中 1 是當前平臺或語音的預設音高。某些語音合成引擎或語音可能會進一步限制最小和最大速率。如果使用 SSML,此值將被標記中的 prosody 標籤覆蓋。
示例
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.pitch = 1.5;
synth.speak(utterThis);
inputTxt.blur();
};
規範
| 規範 |
|---|
| Web Speech API # dom-speechsynthesisutterance-pitch |
瀏覽器相容性
載入中…