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:
@@ -12,7 +12,7 @@ export class NotebookView {
|
||||
/**
|
||||
* @param {import('../i18n/i18n.js').I18n} i18n
|
||||
* @param {object} [options]
|
||||
* @param {(text: string) => Promise<boolean>} [options.onSpeak] Lecture vocale ; absent = pas de bouton.
|
||||
* @param {(text: string, step: object) => Promise<boolean>} [options.onSpeak] Lecture vocale ; absent = pas de bouton.
|
||||
* @param {() => boolean} [options.canSpeak] Évalué à chaque étape : la voix est-elle activée ?
|
||||
*/
|
||||
constructor(i18n, { onSpeak = null, canSpeak = () => true } = {}) {
|
||||
@@ -48,13 +48,14 @@ export class NotebookView {
|
||||
}
|
||||
|
||||
/** Étape d'explication : texte, et bouton de lecture si la voix est demandée par le niveau. */
|
||||
addExplain({ text, voice, image }) {
|
||||
addExplain(step) {
|
||||
const { text, voice, image } = step;
|
||||
const children = [el('p', {}, renderInline(text))];
|
||||
if (image) {
|
||||
children.push(el('img', { src: image, alt: '' }));
|
||||
}
|
||||
if (voice && this.#onSpeak && this.#canSpeak()) {
|
||||
children.push(el('button', { type: 'button', class: 'btn', text: this.#i18n.t('voice.listen'), onclick: () => this.#onSpeak(text) }));
|
||||
children.push(el('button', { type: 'button', class: 'btn', text: this.#i18n.t('voice.listen'), onclick: () => this.#onSpeak(text, step) }));
|
||||
}
|
||||
return this.add(el('section', { class: 'explain', tabindex: '-1' }, ...children));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Panneau de réglages : accessible au clavier, chaque champ a un label visible.
|
||||
// Émet 'change' (detail: { key, value }) ; l'application persiste et applique.
|
||||
// Émet 'change' (detail: { key, value }) et 'test' (detail: { kind: 'sound' | 'voice' }) ;
|
||||
// l'application persiste, applique, et joue les échantillons.
|
||||
|
||||
import { el, uniqueId } from './dom.js';
|
||||
|
||||
@@ -35,12 +36,24 @@ export class SettingsPanel extends EventTarget {
|
||||
key: 'theme',
|
||||
}),
|
||||
this.#field('settings.sound', 'checkbox', { value: settings.soundEnabled, key: 'soundEnabled' }),
|
||||
this.#testButton('settings.testSound', 'sound'),
|
||||
this.#field('settings.volume', 'range', { value: settings.volume, min: 0, max: 1, step: 0.1, key: 'volume', number: true }),
|
||||
this.#field('settings.voice', 'checkbox', { value: settings.voiceEnabled, key: 'voiceEnabled' }),
|
||||
this.#testButton('settings.testVoice', 'voice'),
|
||||
this.#field('settings.voiceRate', 'range', { value: settings.voiceRate, min: 0.5, max: 2, step: 0.1, key: 'voiceRate', number: true }),
|
||||
);
|
||||
}
|
||||
|
||||
#testButton(labelKey, kind) {
|
||||
const button = el('button', {
|
||||
type: 'button',
|
||||
class: 'btn',
|
||||
text: this.#i18n.t(labelKey),
|
||||
onclick: () => this.dispatchEvent(new CustomEvent('test', { detail: { kind } })),
|
||||
});
|
||||
return el('div', { class: 'setting' }, button);
|
||||
}
|
||||
|
||||
#field(labelKey, kind, { value, options = [], key, number = false, ...range }) {
|
||||
const id = uniqueId('setting');
|
||||
const emit = (newValue) => this.dispatchEvent(new CustomEvent('change', { detail: { key, value: newValue } }));
|
||||
|
||||
Reference in New Issue
Block a user