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:
@@ -0,0 +1,20 @@
|
||||
// Clé de narration : relie un texte de niveau à son fichier audio pré-généré.
|
||||
// Doit rester strictement identique à scripts/voice_key.py (vecteurs de test communs).
|
||||
|
||||
const FNV_OFFSET = 0xcbf29ce484222325n;
|
||||
const FNV_PRIME = 0x100000001b3n;
|
||||
const MASK = 0xffffffffffffffffn;
|
||||
|
||||
/** Texte réellement lu : sans backticks Markdown, espaces normalisés. */
|
||||
export function speechText(text) {
|
||||
return text.replace(/`/g, '').replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
/** Empreinte FNV-1a 64 bits (16 caractères hexadécimaux) de la langue et du texte lu. */
|
||||
export function speechKey(lang, text) {
|
||||
let value = FNV_OFFSET;
|
||||
for (const byte of new TextEncoder().encode(`${lang}\n${speechText(text)}`)) {
|
||||
value = ((value ^ BigInt(byte)) * FNV_PRIME) & MASK;
|
||||
}
|
||||
return value.toString(16).padStart(16, '0');
|
||||
}
|
||||
Reference in New Issue
Block a user