From 09d2839a0059e2e1977c8e38914518b4388ba13d Mon Sep 17 00:00:00 2001 From: Cutls Date: Thu, 26 Sep 2019 00:04:50 +0900 Subject: [PATCH] Add: BouyomiChan connection --- app/js/tl/speech.js | 79 ++++++++++++++++++++++---- app/js/ui/layout.js | 6 +- app/view/make/language/bg/setting.json | 2 + app/view/make/language/cs/setting.json | 2 + app/view/make/language/de/setting.json | 2 + app/view/make/language/en/setting.json | 2 + app/view/make/language/ja/setting.json | 2 + app/view/make/setting.sample.html | 48 +++++++++++----- 8 files changed, 115 insertions(+), 28 deletions(-) diff --git a/app/js/tl/speech.js b/app/js/tl/speech.js index f89ffc00..610cef55 100644 --- a/app/js/tl/speech.js +++ b/app/js/tl/speech.js @@ -1,4 +1,5 @@ $voise = null; +isBouyomi = localStorage.getItem("voice_bouyomi"); $voiseName = lang.lang_speech; $voices = speechSynthesis.getVoices(); $synthes = new SpeechSynthesisUtterance(); @@ -9,9 +10,12 @@ speechSynthesis.cancel() if (!localStorage.getItem("voice_vol")) { localStorage.setItem("voice_vol", 1) } -$synthes.rate = localStorage.getItem("voice_speed"); -$synthes.pitch = localStorage.getItem("voice_pitch"); -$synthes.volume = localStorage.getItem("voice_vol"); +voiceRate = localStorage.getItem("voice_speed"); +$synthes.rate = voiceRate +voicePitch = localStorage.getItem("voice_pitch"); +$synthes.pitch = voicePitch +voiceVol = localStorage.getItem("voice_vol"); +$synthes.volume = voiceVol function say(msgr) { msg = voiceParse(msgr); var voice = localStorage.getItem("voicebank"); @@ -32,8 +36,21 @@ $repeat = setInterval(function () { if (voice) { var obj = JSON.parse(voice); if (obj[0]) { - $synthes.text = obj[0]; - speechSynthesis.speak($synthes); + if (localStorage.getItem("voice_bouyomi")) { + var delim = ""; + 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); + } + obj.splice(0, 1); var json = JSON.stringify(obj); localStorage.setItem("voicebank", json); @@ -54,6 +71,11 @@ function voiceToggle(tlid) { if (voiceck) { localStorage.removeItem("voice_" + tlid); speechSynthesis.cancel() + if (localStorage.getItem("voice_bouyomi")) { + var command = 0x0010; + var sends = "" + command; + bouyomiConnect(sends) + } $("#sta-voice-" + tlid).text("Off"); $("#sta-voice-" + tlid).css("color", 'red'); parseColumn(tlid); @@ -78,21 +100,51 @@ 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); + var text = $("#voicetxt").val(); + var rate = $("#voicespeed").val(); + var pitch = $("#voicepitch").val() + var vol = $("#voicevol").val() + if (localStorage.getItem("voice_bouyomi")) { + var delim = ""; + 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); + } } } function voiceSettings() { + 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"); + } localStorage.setItem("voice_speed", $("#voicespeed").val() / 10); localStorage.setItem("voice_pitch", $("#voicepitch").val() / 50); localStorage.setItem("voice_vol", $("#voicevol").val() / 100); M.toast({ html: lang.lang_speech_refresh, displayLength: 3000 }) } function voiceSettingLoad() { + var flag = localStorage.getItem("voice_bouyomi"); + if (flag) { + $("#bym_yes").prop("checked", true); + } else { + $("#bym_no").prop("checked", true); + } var speed = localStorage.getItem("voice_speed"); var pitch = localStorage.getItem("voice_pitch"); var vol = localStorage.getItem("voice_vol"); @@ -108,4 +160,11 @@ function voiceSettingLoad() { $("#voicevol").val(vol * 100); $("#voicevolVal").text(vol * 100); } +} +function bouyomiConnect(sends) { + var socket = new WebSocket('ws://localhost:50002/'); + socket.onopen = function () { + socket.send(sends); + } + } \ No newline at end of file diff --git a/app/js/ui/layout.js b/app/js/ui/layout.js index aac0ed33..d92efa1b 100644 --- a/app/js/ui/layout.js +++ b/app/js/ui/layout.js @@ -269,9 +269,9 @@ function parseColumn(target, dontclose) { ')" class="setting nex">perm_mediaOn' + lang.lang_layout_mediafil + '
linkOn' + lang.lang_layout_linkana + '
hearingOn' + lang.lang_layout_tts + 'TL
On' + lang.lang_layout_linkana + '
hearing' + + '">On' + lang.lang_layout_tts + 'TL
refresh' + lang.lang_layout_reconnect + '
' + lang.lang_layout_headercolor + '
' + lang.lang_layout_nodata + '
' if (numtarget) { diff --git a/app/view/make/language/bg/setting.json b/app/view/make/language/bg/setting.json index 70fb62da..8474ca7a 100644 --- a/app/view/make/language/bg/setting.json +++ b/app/view/make/language/bg/setting.json @@ -152,6 +152,8 @@ "templete3": "", "postartwork": "Attach an Artwork of Spotify", "tts": "TTS(text to speech) Preferences", + "bouyomi": "BouyomiChan connect", + "bouyomiWarn": "Require: BouyomiChan WebSocket Plugin", "speed": "Speed", "speedwarn": "1-100(default:10)", "pitch": "Pitch", diff --git a/app/view/make/language/cs/setting.json b/app/view/make/language/cs/setting.json index a8e55f20..68e38a0b 100644 --- a/app/view/make/language/cs/setting.json +++ b/app/view/make/language/cs/setting.json @@ -152,6 +152,8 @@ "templete3": "", "postartwork": "Attach an Artwork of Spotify", "tts": "TTS(text to speech) Preferences", + "bouyomi": "BouyomiChan connect", + "bouyomiWarn": "Require: BouyomiChan WebSocket Plugin", "speed": "Speed", "speedwarn": "1-100(default:10)", "pitch": "Pitch", diff --git a/app/view/make/language/de/setting.json b/app/view/make/language/de/setting.json index af6a0ae7..d3d0b96a 100644 --- a/app/view/make/language/de/setting.json +++ b/app/view/make/language/de/setting.json @@ -152,6 +152,8 @@ "templete3": "", "postartwork": "Das Artwork von Spotify anhängen", "tts": "Einstellungen Vorlesefunktion", + "bouyomi": "BouyomiChan connect", + "bouyomiWarn": "Require: BouyomiChan WebSocket Plugin", "speed": "Geschwindigkeit", "speedwarn": "1-100(Standard:10)", "pitch": "Stimmlage", diff --git a/app/view/make/language/en/setting.json b/app/view/make/language/en/setting.json index 1ac79d13..07ce404e 100644 --- a/app/view/make/language/en/setting.json +++ b/app/view/make/language/en/setting.json @@ -152,6 +152,8 @@ "templete3": "", "postartwork": "Attach an Artwork of Spotify", "tts": "TTS(text to speech) Preferences", + "bouyomi": "BouyomiChan connect", + "bouyomiWarn": "Require: BouyomiChan WebSocket Plugin", "speed": "Speed", "speedwarn": "1-100(default:10)", "pitch": "Pitch", diff --git a/app/view/make/language/ja/setting.json b/app/view/make/language/ja/setting.json index 5bcf61d2..fb08d7a3 100644 --- a/app/view/make/language/ja/setting.json +++ b/app/view/make/language/ja/setting.json @@ -152,6 +152,8 @@ "template3": "", "postartwork": "アルバムアートワークを添付する(Spotify)", "tts": "読み上げの設定", + "bouyomi": "棒読みちゃん連携", + "bouyomiWarn": "「棒読みちゃん用のWebSocket受付プラグイン」が必要です。", "speed": "読み上げの速さ", "speedwarn": "1-100まで、デフォルトは10。", "pitch": "読み上げの高さ", diff --git a/app/view/make/setting.sample.html b/app/view/make/setting.sample.html index b8207b35..00b70084 100644 --- a/app/view/make/setting.sample.html +++ b/app/view/make/setting.sample.html @@ -247,10 +247,10 @@ id="c3-file">

-
@@vol@@
- @@volwarn80@@
-

80
- @@vol@@ + @@volwarn80@@
+

80
+

@@ -267,7 +267,8 @@