2018-07-22 23:03:46 +10:00
|
|
|
$voise = null;
|
2018-07-30 03:35:29 +10:00
|
|
|
$voiseName = lang_speech[lang];
|
2018-07-22 23:03:46 +10:00
|
|
|
$voices = speechSynthesis.getVoices();
|
|
|
|
$synthes = new SpeechSynthesisUtterance();
|
|
|
|
$voise = $.grep($voices, function(n, i){return n.name == $voiseName})[0];
|
|
|
|
$synthes.voice = $voise; // 音声の設定
|
|
|
|
localStorage.removeItem("voicebank");
|
|
|
|
speechSynthesis.cancel()
|
2018-08-05 02:26:34 +10:00
|
|
|
if(!localStorage.getItem("voice_vol")){
|
|
|
|
localStorage.setItem("voice_vol",1)
|
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
$synthes.rate=localStorage.getItem("voice_speed");
|
|
|
|
$synthes.pitch=localStorage.getItem("voice_pitch");
|
|
|
|
$synthes.volume=localStorage.getItem("voice_vol");
|
2018-09-17 21:55:00 +10:00
|
|
|
function say(msgr){
|
|
|
|
msg=voiceParse(msgr);
|
2018-07-22 23:03:46 +10:00
|
|
|
var voice=localStorage.getItem("voicebank");
|
|
|
|
var obj = JSON.parse(voice);
|
|
|
|
if(!obj){
|
|
|
|
var json = JSON.stringify([msg]);
|
|
|
|
localStorage.setItem("voicebank", json);
|
|
|
|
}else{
|
|
|
|
obj.push([msg]);
|
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
localStorage.setItem("voicebank", json);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$repeat = setInterval(function() {
|
|
|
|
if(!speechSynthesis.speaking){
|
|
|
|
var voice=localStorage.getItem("voicebank");
|
|
|
|
if(voice){
|
|
|
|
var obj = JSON.parse(voice);
|
|
|
|
if(obj[0]){
|
|
|
|
$synthes.text = obj[0];
|
2018-08-05 02:26:34 +10:00
|
|
|
console.log($synthes);
|
2018-07-22 23:03:46 +10:00
|
|
|
speechSynthesis.speak($synthes);
|
|
|
|
obj.splice(0, 1);
|
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
localStorage.setItem("voicebank", json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
function voiceParse(msg){
|
2018-09-17 21:55:00 +10:00
|
|
|
msg = $.strip_tags(msg);
|
2018-07-22 23:03:46 +10:00
|
|
|
msg = msg.replace(/#/g, "");
|
|
|
|
msg = msg.replace(/'/g, "");
|
|
|
|
msg = msg.replace(/"/g, "");
|
2018-09-17 21:55:00 +10:00
|
|
|
msg = msg.replace(/https?:\/\/[a-zA-Z0-9./-@_=?%&-]+/g, "");
|
2018-07-22 23:03:46 +10:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
function voiceToggle(tlid) {
|
|
|
|
var voiceck = localStorage.getItem("voice_" + tlid);
|
|
|
|
if (voiceck) {
|
|
|
|
localStorage.removeItem("voice_" + tlid);
|
|
|
|
speechSynthesis.cancel()
|
|
|
|
$("#sta-voice-" + tlid).text("Off");
|
|
|
|
$("#sta-voice-" + tlid).css("color",'red');
|
|
|
|
parseColumn();
|
|
|
|
} else {
|
|
|
|
localStorage.setItem("voice_" + tlid, "true");
|
|
|
|
$("#sta-voice-" + tlid).text("On");
|
|
|
|
$("#sta-voice-" + tlid).css("color",'#009688');
|
|
|
|
parseColumn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function voiceCheck(tlid) {
|
|
|
|
var voiceck = localStorage.getItem("voice_" + tlid);
|
|
|
|
if (voiceck) {
|
|
|
|
$("#sta-voice-" + tlid).text("On");
|
|
|
|
$("#sta-voice-" + tlid).css("color",'#009688');
|
|
|
|
} else {
|
|
|
|
$("#sta-voice-" + tlid).text("Off");
|
|
|
|
$("#sta-voice-" + tlid).css("color",'red');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function voicePlay(){
|
|
|
|
if(speechSynthesis.speaking){
|
|
|
|
speechSynthesis.cancel()
|
|
|
|
}else{
|
|
|
|
$synthes.text = $("#voicetxt").val();
|
|
|
|
$synthes.rate = $("#voicespeed").val()/10;
|
|
|
|
$synthes.pitch = $("#voicepitch").val()/50;
|
|
|
|
$synthes.volume = $("#voicevol").val()/100;
|
|
|
|
speechSynthesis.speak($synthes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function voiceSettings(){
|
|
|
|
localStorage.setItem("voice_speed", $("#voicespeed").val()/10);
|
|
|
|
localStorage.setItem("voice_pitch", $("#voicepitch").val()/50);
|
|
|
|
localStorage.setItem("voice_vol", $("#voicevol").val()/100);
|
2018-07-29 17:37:54 +10:00
|
|
|
Materialize.toast(lang_speech_refresh[lang], 3000);
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
|
|
|
function voiceSettingLoad(){
|
|
|
|
var speed=localStorage.getItem("voice_speed");
|
|
|
|
var pitch=localStorage.getItem("voice_pitch");
|
|
|
|
var vol=localStorage.getItem("voice_vol");
|
|
|
|
if(speed){
|
|
|
|
$("#voicespeed").val(speed*10);
|
|
|
|
}
|
|
|
|
if(pitch){
|
|
|
|
$("#voicepitch").val(pitch*50);
|
|
|
|
}
|
|
|
|
if(vol){
|
|
|
|
$("#voicevol").val(vol*100);
|
|
|
|
}
|
|
|
|
}
|