미디어위키:Gadget-TTS.js: 두 판 사이의 차이

리버티게임(개발), 모두가 만들어가는 자유로운 게임
둘러보기로 이동 검색으로 이동
imported>Senouis
편집 요약 없음
>BANIP
편집 요약 없음
 
4번째 줄: 4번째 줄:
**/
**/
window.voiceSettings = {};
window.voiceSettings = {};
voiceSettings.default = {
voice: null,
pitch: 1,
rate: 1,
volume: 1
};
function speakSpeech() {
function speakSpeech() {
    if('notts' in geturlSearch() && window.disableTTS) return
var ssu, setting;
var ssu, setting;
    var defaultVoiceSettings = {
        voice: null,
        pitch: 1,
        rate: 1,
        volume: 1
    };
if(!('notts' in geturlSearch() || window.disableTTS)) Array.from(document.getElementsByClassName('speech')).forEach(function(elem) {
Array.from(document.getElementsByClassName('speech')).forEach(function(elem) {
ssu = new SpeechSynthesisUtterance(elem.innerText);
ssu = new SpeechSynthesisUtterance(elem.innerText);
ssu.lang = elem.lang;
ssu.lang = elem.lang;
setting = Object.assign({}, voiceSettings.default, voiceSettings[ssu.lang]);
setting = Object.assign({}, defaultVoiceSettings, voiceSettings[ssu.lang]);
if(setting.voice) ssu.voice = setting.voice;
if(setting.voice) ssu.voice = setting.voice;
if(!isNaN(elem.dataset.pitch)) ssu.pitch = setting.pitch * elem.dataset.pitch;
if(!isNaN(elem.dataset.pitch)) ssu.pitch = setting.pitch * elem.dataset.pitch;

2023년 7월 21일 (금) 10:01 기준 최신판

/** TTS 지원
 * class="speech" (lang="") (data-pitch="") (data-rate="") (data-volume="")
 * 제작자: [[사용자:hsl0]]
**/
window.voiceSettings = {};
function speakSpeech() {
    if('notts' in geturlSearch() && window.disableTTS) return
	var ssu, setting;
    var defaultVoiceSettings = {
        voice: null,
        pitch: 1,
        rate: 1,
        volume: 1
    };
	
	 Array.from(document.getElementsByClassName('speech')).forEach(function(elem) {
		ssu = new SpeechSynthesisUtterance(elem.innerText);
		
		ssu.lang = elem.lang;
		setting = Object.assign({}, defaultVoiceSettings, voiceSettings[ssu.lang]);
		if(setting.voice) ssu.voice = setting.voice;
		if(!isNaN(elem.dataset.pitch)) ssu.pitch = setting.pitch * elem.dataset.pitch;
		if(!isNaN(elem.dataset.rate)) ssu.rate = setting.rate * elem.dataset.rate;
		if(!isNaN(elem.dataset.volume)) ssu.volume = setting.volume * elem.dataset.volume;
		
		speechSynthesis.speak(ssu);
	});
}
$(speakSpeech);
/* TTS 끝 */