speech synthesis improvements
This commit is contained in:
parent
ce9a5f059f
commit
1b5e83f83f
|
@ -28,13 +28,6 @@ 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;
|
||||
|
@ -46,12 +39,11 @@ 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');
|
||||
api.say('Speech synthesis ready');
|
||||
},
|
||||
volume(v: number) {
|
||||
api.setVolume(v);
|
||||
if (api.set() == 'speech') say('knight c3');
|
||||
else api.move(true);
|
||||
api.move('knight c3');
|
||||
},
|
||||
redraw,
|
||||
trans,
|
||||
|
|
|
@ -678,7 +678,7 @@ export default class RoundController {
|
|||
|
||||
private delayedInit = () => {
|
||||
const d = this.data;
|
||||
if (this.isPlaying() && game.nbMoves(d, d.player.color) === 0 && !this.isSimulHost()) {
|
||||
if (this.isPlaying() && !li.sound.say('ready') && game.nbMoves(d, d.player.color) === 0 && !this.isSimulHost()) {
|
||||
li.sound.genericNotify();
|
||||
}
|
||||
li.requestIdleCallback(() => {
|
||||
|
|
|
@ -586,13 +586,26 @@
|
|||
var enabled = function() {
|
||||
return soundSet !== 'silent';
|
||||
};
|
||||
var getVolume = function() {
|
||||
return parseFloat(api.volumeStorage.get() || api.defaultVolume);
|
||||
}
|
||||
Object.keys(names).forEach(function(name) {
|
||||
api[name] = function() {
|
||||
api[name] = function(text) {
|
||||
if (!enabled()) return;
|
||||
Howler.volume(api.volumeStorage.get() || api.defaultVolume);
|
||||
collection(name).play();
|
||||
if (!text || !api.say(text)) {
|
||||
Howler.volume(getVolume());
|
||||
collection(name).play();
|
||||
}
|
||||
}
|
||||
});
|
||||
api.say = function(text) {
|
||||
if (soundSet != 'speech') return false;
|
||||
var msg = new SpeechSynthesisUtterance(text);
|
||||
msg.volume = getVolume();
|
||||
speechSynthesis.cancel();
|
||||
speechSynthesis.speak(msg);
|
||||
return true;
|
||||
};
|
||||
api.load = function(name) {
|
||||
if (enabled() && name in names) collection(name);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue