2019-11-09 00:52:54 +11:00
|
|
|
$voise = null
|
|
|
|
isBouyomi = localStorage.getItem('voice_bouyomi')
|
|
|
|
$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')
|
2019-05-19 17:39:30 +10:00
|
|
|
speechSynthesis.cancel()
|
2019-11-09 00:52:54 +11:00
|
|
|
if (!localStorage.getItem('voice_vol')) {
|
|
|
|
localStorage.setItem('voice_vol', 1)
|
2019-05-19 17:39:30 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
voiceRate = localStorage.getItem('voice_speed')
|
2019-09-26 01:04:50 +10:00
|
|
|
$synthes.rate = voiceRate
|
2019-11-09 00:52:54 +11:00
|
|
|
voicePitch = localStorage.getItem('voice_pitch')
|
2019-09-26 01:04:50 +10:00
|
|
|
$synthes.pitch = voicePitch
|
2019-11-09 00:52:54 +11:00
|
|
|
voiceVol = localStorage.getItem('voice_vol')
|
2019-09-26 01:04:50 +10:00
|
|
|
$synthes.volume = voiceVol
|
2019-05-19 17:39:30 +10:00
|
|
|
function say(msgr) {
|
2019-11-09 00:52:54 +11:00
|
|
|
msg = voiceParse(msgr)
|
|
|
|
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)
|
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$repeat = setInterval(function() {
|
|
|
|
if (!speechSynthesis.speaking) {
|
|
|
|
var voice = localStorage.getItem('voicebank')
|
|
|
|
if (voice) {
|
|
|
|
var obj = JSON.parse(voice)
|
|
|
|
if (obj[0]) {
|
|
|
|
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)
|
|
|
|
}
|
2019-09-26 01:04:50 +10:00
|
|
|
|
2019-11-09 00:52:54 +11: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) {
|
2019-11-09 00:52:54 +11:00
|
|
|
msg = $.strip_tags(msg)
|
|
|
|
msg = msg.replace(/#/g, '')
|
|
|
|
msg = msg.replace(/'/g, '')
|
|
|
|
msg = msg.replace(/"/g, '')
|
|
|
|
msg = msg.replace(/https?:\/\/[a-zA-Z0-9./-@_=?%&-]+/g, '')
|
|
|
|
return msg
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
|
|
|
function voiceToggle(tlid) {
|
2019-11-09 00:52:54 +11:00
|
|
|
var voiceck = localStorage.getItem('voice_' + 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)
|
|
|
|
} else {
|
|
|
|
localStorage.setItem('voice_' + tlid, 'true')
|
|
|
|
$('#sta-voice-' + tlid).text('On')
|
|
|
|
$('#sta-voice-' + tlid).css('color', '#009688')
|
|
|
|
parseColumn(tlid)
|
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
|
|
|
function voiceCheck(tlid) {
|
2019-11-09 00:52:54 +11:00
|
|
|
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')
|
|
|
|
}
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
function voicePlay() {
|
2019-11-09 00:52:54 +11:00
|
|
|
if (speechSynthesis.speaking) {
|
|
|
|
speechSynthesis.cancel()
|
|
|
|
} else {
|
|
|
|
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を指定すると本体設定
|
2019-09-26 01:04:50 +10:00
|
|
|
var pitch = 100; // ピッチ50-200。-1を指定すると本体設定
|
|
|
|
var volume = 100; // ボリューム0-100。-1を指定すると本体設定*/
|
2019-11-09 00:52:54 +11:00
|
|
|
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-11-09 00:52:54 +11: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')
|
|
|
|
}
|
|
|
|
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 })
|
2018-07-22 23:03:46 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
function voiceSettingLoad() {
|
2019-11-09 00:52:54 +11:00
|
|
|
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')
|
|
|
|
if (speed) {
|
|
|
|
$('#voicespeed').val(speed * 10)
|
|
|
|
$('#voicespeedVal').text(speed * 10)
|
|
|
|
}
|
|
|
|
if (pitch) {
|
|
|
|
$('#voicepitch').val(pitch * 50)
|
|
|
|
$('#voicepitchVal').text(pitch * 50)
|
|
|
|
}
|
|
|
|
if (vol) {
|
|
|
|
$('#voicevol').val(vol * 100)
|
|
|
|
$('#voicevolVal').text(vol * 100)
|
|
|
|
}
|
2019-09-26 01:04:50 +10:00
|
|
|
}
|
|
|
|
function bouyomiConnect(sends) {
|
2019-11-09 00:52:54 +11:00
|
|
|
var socket = new WebSocket('ws://localhost:50002/')
|
|
|
|
socket.onopen = function() {
|
|
|
|
socket.send(sends)
|
|
|
|
}
|
|
|
|
}
|