2019-05-19 17:39:30 +10:00
|
|
|
$voise = null;
|
2019-09-26 01:04:50 +10:00
|
|
|
isBouyomi = localStorage.getItem("voice_bouyomi");
|
2019-05-19 17:39:30 +10:00
|
|
|
$voiseName = lang.lang_speech;
|
|
|
|
$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()
|
|
|
|
if (!localStorage.getItem("voice_vol")) {
|
|
|
|
localStorage.setItem("voice_vol", 1)
|
|
|
|
}
|
2019-09-26 01:04:50 +10:00
|
|
|
voiceRate = localStorage.getItem("voice_speed");
|
|
|
|
$synthes.rate = voiceRate
|
|
|
|
voicePitch = localStorage.getItem("voice_pitch");
|
|
|
|
$synthes.pitch = voicePitch
|
|
|
|
voiceVol = localStorage.getItem("voice_vol");
|
|
|
|
$synthes.volume = voiceVol
|
2019-05-19 17:39:30 +10:00
|
|
|
function say(msgr) {
|
|
|
|
msg = voiceParse(msgr);
|
|
|
|
var voice = localStorage.getItem("voicebank");
|
2018-07-22 23:03:46 +10:00
|
|
|
var obj = JSON.parse(voice);
|
2019-05-19 17:39:30 +10:00
|
|
|
if (!obj) {
|
|
|
|
var json = JSON.stringify([msg]);
|
|
|
|
localStorage.setItem("voicebank", json);
|
|
|
|
} else {
|
|
|
|
obj.push([msg]);
|
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
localStorage.setItem("voicebank", json);
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
$repeat = setInterval(function () {
|
|
|
|
if (!speechSynthesis.speaking) {
|
|
|
|
var voice = localStorage.getItem("voicebank");
|
|
|
|
if (voice) {
|
2018-07-22 23:03:46 +10:00
|
|
|
var obj = JSON.parse(voice);
|
2019-05-19 17:39:30 +10:00
|
|
|
if (obj[0]) {
|
2019-09-26 01:04:50 +10:00
|
|
|
if (localStorage.getItem("voice_bouyomi")) {
|
|
|
|
var delim = "<bouyomi>";
|
|
|
|
var thisVoiceRate = voiceRate * 10 + 70
|
|
|
|
var thisVoicePitch = voicePitch * 50 + 70
|
|
|
|
var thisVoiceVol = voiceVol * 100
|
|
|
|
console.log(thisVoiceRate, thisVoicePitch, thisVoiceVol)
|
|
|
|
var command = 0x0001;
|
|
|
|
var type = 0;
|
|
|
|
var sends = "" + command + delim + thisVoiceRate + delim + thisVoicePitch + delim + thisVoiceVol + delim + type + delim + obj[0];
|
|
|
|
bouyomiConnect(sends)
|
|
|
|
} else {
|
|
|
|
$synthes.text = obj[0];
|
|
|
|
speechSynthesis.speak($synthes);
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:03:46 +10:00
|
|
|
obj.splice(0, 1);
|
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
localStorage.setItem("voicebank", json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 300);
|
2019-05-19 17:39:30 +10:00
|
|
|
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, "");
|
2019-05-19 17:39:30 +10:00
|
|
|
return msg;
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
|
|
|
function voiceToggle(tlid) {
|
2019-05-19 17:39:30 +10:00
|
|
|
var voiceck = localStorage.getItem("voice_" + tlid);
|
|
|
|
if (voiceck) {
|
2018-07-22 23:03:46 +10:00
|
|
|
localStorage.removeItem("voice_" + tlid);
|
|
|
|
speechSynthesis.cancel()
|
2019-09-26 01:04:50 +10:00
|
|
|
if (localStorage.getItem("voice_bouyomi")) {
|
|
|
|
var command = 0x0010;
|
|
|
|
var sends = "" + command;
|
|
|
|
bouyomiConnect(sends)
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
$("#sta-voice-" + tlid).text("Off");
|
|
|
|
$("#sta-voice-" + tlid).css("color", 'red');
|
2019-08-14 01:40:21 +10:00
|
|
|
parseColumn(tlid);
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
|
|
|
localStorage.setItem("voice_" + tlid, "true");
|
|
|
|
$("#sta-voice-" + tlid).text("On");
|
|
|
|
$("#sta-voice-" + tlid).css("color", '#009688');
|
2019-08-14 01:40:21 +10:00
|
|
|
parseColumn(tlid);
|
2019-05-19 17:39:30 +10:00
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
|
|
|
function voiceCheck(tlid) {
|
|
|
|
var voiceck = localStorage.getItem("voice_" + tlid);
|
2019-05-19 17:39:30 +10:00
|
|
|
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');
|
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
function voicePlay() {
|
|
|
|
if (speechSynthesis.speaking) {
|
2018-07-22 23:03:46 +10:00
|
|
|
speechSynthesis.cancel()
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-09-26 01:04:50 +10:00
|
|
|
var text = $("#voicetxt").val();
|
|
|
|
var rate = $("#voicespeed").val();
|
|
|
|
var pitch = $("#voicepitch").val()
|
|
|
|
var vol = $("#voicevol").val()
|
|
|
|
if (localStorage.getItem("voice_bouyomi")) {
|
|
|
|
var delim = "<bouyomi>";
|
|
|
|
rate = rate * 1 + 70
|
|
|
|
pitch = pitch * 1 + 70
|
|
|
|
var command = 0x0001; // コマンドです。0x0001.読み上げ/0x0010.ポーズ/0x0020.再開/0x0030.スキップ
|
|
|
|
/*var speed = 100; // 速度50-200。-1を指定すると本体設定
|
|
|
|
var pitch = 100; // ピッチ50-200。-1を指定すると本体設定
|
|
|
|
var volume = 100; // ボリューム0-100。-1を指定すると本体設定*/
|
|
|
|
var type = 0; // 声質(0.本体設定/1.女性1/2.女性2/3.男性1/4.男性2/5.中性/6.ロボット/7.機械1/8.機械2)
|
|
|
|
var sends = "" + command + delim + rate + delim + pitch + delim + vol + delim + type + delim + text;
|
|
|
|
bouyomiConnect(sends)
|
|
|
|
} else {
|
|
|
|
$synthes.text = text
|
|
|
|
$synthes.rate = rate / 10
|
|
|
|
$synthes.pitch = pitch / 50
|
|
|
|
$synthes.volume = vol / 100;
|
|
|
|
speechSynthesis.speak($synthes);
|
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-19 17:39:30 +10:00
|
|
|
function voiceSettings() {
|
2019-09-26 01:04:50 +10:00
|
|
|
var awk = $("[name=bym]:checked").val();
|
|
|
|
if (awk == "yes") {
|
|
|
|
localStorage.setItem("voice_bouyomi", "yes");
|
|
|
|
M.toast({ html: "Bouyomi Chan connection requires WebSocket Plugin", displayLength: 3000 })
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem("voice_bouyomi");
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
localStorage.setItem("voice_speed", $("#voicespeed").val() / 10);
|
|
|
|
localStorage.setItem("voice_pitch", $("#voicepitch").val() / 50);
|
|
|
|
localStorage.setItem("voice_vol", $("#voicevol").val() / 100);
|
2019-06-07 02:11:04 +10:00
|
|
|
M.toast({ html: lang.lang_speech_refresh, displayLength: 3000 })
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
function voiceSettingLoad() {
|
2019-09-26 01:04:50 +10:00
|
|
|
var flag = localStorage.getItem("voice_bouyomi");
|
|
|
|
if (flag) {
|
|
|
|
$("#bym_yes").prop("checked", true);
|
|
|
|
} else {
|
|
|
|
$("#bym_no").prop("checked", true);
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
var speed = localStorage.getItem("voice_speed");
|
|
|
|
var pitch = localStorage.getItem("voice_pitch");
|
|
|
|
var vol = localStorage.getItem("voice_vol");
|
|
|
|
if (speed) {
|
|
|
|
$("#voicespeed").val(speed * 10);
|
2019-09-17 01:59:25 +10:00
|
|
|
$("#voicespeedVal").text(speed * 10);
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (pitch) {
|
|
|
|
$("#voicepitch").val(pitch * 50);
|
2019-09-17 01:59:25 +10:00
|
|
|
$("#voicepitchVal").text(pitch * 50);
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (vol) {
|
|
|
|
$("#voicevol").val(vol * 100);
|
2019-09-17 01:59:25 +10:00
|
|
|
$("#voicevolVal").text(vol * 100);
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-09-26 01:04:50 +10:00
|
|
|
}
|
|
|
|
function bouyomiConnect(sends) {
|
|
|
|
var socket = new WebSocket('ws://localhost:50002/');
|
|
|
|
socket.onopen = function () {
|
|
|
|
socket.send(sends);
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|