mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
Rework sound effects and add pre-generated Piper narration
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+22
-1
@@ -10,6 +10,7 @@ import { SettingsStore } from './core/SettingsStore.js';
|
||||
import { ValidationEngine } from './core/ValidationEngine.js';
|
||||
import { VoiceEngine } from './core/VoiceEngine.js';
|
||||
import { I18n } from './i18n/i18n.js';
|
||||
import { speechKey } from './core/speechKey.js';
|
||||
import { BadgeToast } from './ui/BadgeToast.js';
|
||||
import { CellManager } from './ui/CellManager.js';
|
||||
import { NotebookView } from './ui/NotebookView.js';
|
||||
@@ -56,6 +57,7 @@ class App {
|
||||
#audio;
|
||||
#voice;
|
||||
#manager;
|
||||
#toast;
|
||||
#map;
|
||||
#panel;
|
||||
#levelIds = [];
|
||||
@@ -81,10 +83,11 @@ class App {
|
||||
|
||||
const client = new PyodideWorkerClient({ indexURL: new URL('/vendor/pyodide/', location.href).href });
|
||||
const notebook = new NotebookView(this.#i18n, {
|
||||
onSpeak: (text) => this.#voice.speak(text, this.#i18n.lang),
|
||||
onSpeak: (text, step) => this.#voice.speak(text, this.#i18n.lang, { audioUrl: step.audioUrl }),
|
||||
canSpeak: () => this.#voice.supported && this.#voice.enabled,
|
||||
});
|
||||
const toast = new BadgeToast(this.#i18n);
|
||||
this.#toast = toast;
|
||||
this.#manager = new CellManager({
|
||||
i18n: this.#i18n,
|
||||
notebook,
|
||||
@@ -101,6 +104,7 @@ class App {
|
||||
this.#map.addEventListener('select', (event) => this.#openLevel(event.detail.id));
|
||||
this.#panel = new SettingsPanel(this.#i18n);
|
||||
this.#panel.addEventListener('change', (event) => this.#onSettingChange(event.detail));
|
||||
this.#panel.addEventListener('test', (event) => this.#onTest(event.detail.kind));
|
||||
|
||||
document.getElementById('progress-region').append(this.#map.element);
|
||||
document.getElementById('notebook-region').append(notebook.element);
|
||||
@@ -168,6 +172,23 @@ class App {
|
||||
}
|
||||
}
|
||||
|
||||
/** Échantillons des réglages : le clic est le geste utilisateur qui débloque le son. */
|
||||
async #onTest(kind) {
|
||||
if (kind === 'sound') {
|
||||
await this.#audio.unlock();
|
||||
this.#audio.play('success_big');
|
||||
return;
|
||||
}
|
||||
if (!this.#voice.enabled) {
|
||||
this.#toast.show(this.#i18n.t('settings.voiceOffNotice'));
|
||||
return;
|
||||
}
|
||||
const lang = this.#i18n.lang;
|
||||
const sample = this.#i18n.t('voice.sample');
|
||||
const audioUrl = new URL(`assets/voice/${lang}/${speechKey(lang, sample)}.mp3`, document.baseURI).href;
|
||||
await this.#voice.speak(sample, lang, { audioUrl });
|
||||
}
|
||||
|
||||
#registerServiceWorker() {
|
||||
// Repli : sans service worker (http hors localhost, navigateur ancien), l'app fonctionne en ligne.
|
||||
if ('serviceWorker' in navigator) {
|
||||
|
||||
Reference in New Issue
Block a user