speech synthesis tweaks

This commit is contained in:
Thibault Duplessis 2019-04-29 10:58:23 +07:00
parent 2722867dbc
commit d6ae3aa54e
2 changed files with 20 additions and 5 deletions

View file

@ -17,6 +17,7 @@ export interface SoundCtrl {
api: any;
set(k: Key): void;
volume(v: number): void;
redraw: Redraw;
trans: Trans;
close: Close;
}
@ -27,6 +28,13 @@ export function ctrl(raw: string[], trans: Trans, redraw: Redraw, close: Close):
const api = window.lichess.sound;
function say(text: string) {
const msg = new SpeechSynthesisUtterance(text);
msg.volume = parseFloat(window.lichess.storage.get('sound-volume'));
window.speechSynthesis.cancel();
window.speechSynthesis.speak(msg);
}
return {
makeList() {
const canSpeech = window.speechSynthesis && window.speechSynthesis.getVoices().length;
@ -38,11 +46,14 @@ export function ctrl(raw: string[], trans: Trans, redraw: Redraw, close: Close):
api.genericNotify();
$.post('/pref/soundSet', { set: k });
redraw();
if (k == 'speech') say('Speech synthesis ready');
},
volume(v: number) {
api.setVolume(v);
api.move(true);
if (api.set() == 'speech') say('knight c3');
else api.move(true);
},
redraw,
trans,
close
};
@ -50,7 +61,13 @@ export function ctrl(raw: string[], trans: Trans, redraw: Redraw, close: Close):
export function view(ctrl: SoundCtrl): VNode {
return h('div.sub.sound.' + ctrl.api.set(), [
return h('div.sub.sound.' + ctrl.api.set(), {
hook: {
insert() {
window.speechSynthesis.onvoiceschanged = ctrl.redraw;
}
}
}, [
header(ctrl.trans('sound'), ctrl.close),
h('div.content', [
h('div.slider', { hook: { insert: vn => makeSlider(ctrl, vn) } }),

View file

@ -14,7 +14,7 @@ export function renderSan(san: San) {
if (c == '@') return 'at';
const code = c.charCodeAt(0);
if (code > 48 && code < 58) return c; // 1-8
if (code > 96 && code < 105) return c;
if (code > 96 && code < 105) return c + ' ';
return roles[c] || c;
}).join(' ');
if (san.includes('+')) move += ' check';
@ -36,8 +36,6 @@ window.lichess.RoundSpeech = function() {
synth.speak(msg);
}
say('ready');
return {
jump(s: Step) {
say(s.san ? renderSan(s.san) : 'Game starts');