Baseline Widely available
Experimental: ããã¯å®é¨çãªæ©è½ã§ãã
æ¬çªã§ä½¿ç¨ããåã«ãã©ã¦ã¶ã¼äºææ§ä¸è¦§è¡¨ããã§ãã¯ãã¦ãã ããã
Window ãªãã¸ã§ã¯ãã® speechSynthesis
èªã¿åãå°ç¨ããããã£ã¯ãSpeechSynthesis
ãªãã¸ã§ã¯ããè¿ãã¾ããããã¯ãWeb Speech API ã®é³å£°åææ©è½ã使ç¨ããããã®ã¨ã³ããªã¼ãã¤ã³ãã§ãã
var synth = window.speechSynthesis;
å¤
SpeechSynthesis
ãªãã¸ã§ã¯ãã
ç§ãã¡ã®åºæ¬ç㪠é³å£°åæã®ã㢠ã§ã¯ãæåã« window.speechSynthesis
ã使ç¨ã㦠SpeechSynthesis ã³ã³ããã¼ã©ã¼ã¸ã®åç
§ãåå¾ãã¾ããããã¤ãã®å¿
è¦ãªå¤æ°ãå®ç¾©ããå¾ãSpeechSynthesis.getVoices()
ã使ç¨ãã¦å©ç¨å¯è½ãªé³å£°ã®ãªã¹ããåå¾ãããããã®é¸æã¡ãã¥ã¼ãæ§æãã¾ããã¦ã¼ã¶ã¼ã¯ããããã使ç¨ãããé³å£°ãé¸ã¹ã¾ãã
inputForm.onsubmit
ãã³ãã©ã¼å
é¨ã§ã¯ãpreventDefault() ã§ãã©ã¼ã éä¿¡ã忢ããããã¹ã <input>
ã«å
¥åãããããã¹ããå«ãæ°ãã SpeechSynthesisUtterance
ã¤ã³ã¹ã¿ã³ã¹ã使ãã¾ãããã®çºå£° (utterance) ã«ã¦ã¼ã¶ã¼ã <select>
è¦ç´ ã§é¸æããé³å£°ãè¨å®ããSpeechSynthesis.speak()
ã¡ã½ãããéãã¦çºå£°ã®çºè©±ãéå§ãã¾ãã
var synth = window.speechSynthesis;
var inputForm = document.querySelector("form");
var inputTxt = document.querySelector("input");
var voiceSelect = document.querySelector("select");
function populateVoiceList() {
voices = synth.getVoices();
for (i = 0; i < voices.length; i++) {
var option = document.createElement("option");
option.textContent = voices[i].name + " (" + voices[i].lang + ")";
if (voices[i].default) {
option.textContent += " -- DEFAULT";
}
option.setAttribute("data-lang", voices[i].lang);
option.setAttribute("data-name", voices[i].name);
voiceSelect.appendChild(option);
}
}
populateVoiceList();
if (speechSynthesis.onvoiceschanged !== undefined) {
speechSynthesis.onvoiceschanged = populateVoiceList;
}
inputForm.onsubmit = function (event) {
event.preventDefault();
var utterThis = new SpeechSynthesisUtterance(inputTxt.value);
var selectedOption = voiceSelect.selectedOptions[0].getAttribute("data-name");
for (i = 0; i < voices.length; i++) {
if (voices[i].name === selectedOption) {
utterThis.voice = voices[i];
}
}
synth.speak(utterThis);
inputTxt.blur();
};
仿§æ¸ ãã©ã¦ã¶ã¼ã®å®è£
ç¶æ³ é¢é£é
ç®
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.4