diff --git a/docs/video/.gitignore b/docs/video/.gitignore new file mode 100644 index 0000000..76c13f0 --- /dev/null +++ b/docs/video/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +vo/ +music.wav +*.mp4 diff --git a/docs/video/README.md b/docs/video/README.md new file mode 100644 index 0000000..d58a781 --- /dev/null +++ b/docs/video/README.md @@ -0,0 +1,37 @@ +# Vidéo publicitaire MonEspacePro + +Pub de 30 s au format vertical 1080 × 1920 (TikTok, Instagram Reels), avec musique originale et voix off. +Les vidéos finales sont dans `docs/` (`MonEspacePro-pub-voix-120fps.mp4`). + +| Fichier | Rôle | +|---|---| +| `video-pub.html` | L'animation (HTML/CSS/JS). Ouvrir dans Chrome ; `?t=12.5` fige l'image à 12,5 s, Espace relance. | +| `music.js` | Compose la musique (120 BPM, calée sur les temps forts) → `music.wav` | +| `voice.js` | Génère la voix off phrase par phrase (voix Microsoft « Denise ») → `vo/` | +| `mix.js` | Mixe voix et musique, la musique baisse sous la voix → `mix.wav` | +| `render.js` | Rend l'animation image par image dans Chrome et assemble le MP4 avec `mix.wav` | +| `mix.wav` | Bande son finale (versionnée : le rendu fonctionne sans régénérer la voix) | + +## Refaire la vidéo + +Prérequis : Node.js et Google Chrome installé à l'emplacement standard. + +```bash +npm install +npm run rendu:60 # → docs/MonEspacePro-pub-voix-60fps.mp4 (≈ 2 min) +npm run rendu:120 # → docs/MonEspacePro-pub-voix-120fps.mp4 (≈ 4 min) +``` + +Après une modification du texte de la voix off ou de la musique : `npm run musique`, `npm run voix`, +`npm run mixage`, puis le rendu. + +## À savoir + +- Les temps forts sont repérés par `♪` dans la timeline de `video-pub.html` ; la voix off est calée + dans le tableau `LINES` de `voice.js` (début, fin maximale, texte, débit). +- Les cartes affichées reproduisent les vraies cartes Apple Wallet générées par l'API + (`backend/src/wallet`) : même champs, même texte de prochaine récompense. +- La voix vient du service de lecture à voix haute de Microsoft Edge, prévu pour un usage personnel. + Pour une campagne payante, régénérer la voix avec une offre sous licence commerciale (Azure Speech, + même voix « Denise », ou ElevenLabs), puis relancer `npm run mixage` et le rendu. +- TikTok et Instagram diffusent au plus en 60 images/s : publier la version 60 i/s. diff --git a/docs/video/mix.js b/docs/video/mix.js new file mode 100644 index 0000000..27ef555 --- /dev/null +++ b/docs/video/mix.js @@ -0,0 +1,39 @@ +// Mixage voix off + musique, avec baisse automatique de la musique sous la voix +process.chdir(__dirname); +const fs = require('fs'); +const SR = 48000; +const wav = fs.readFileSync('music.wav'); +const N = (wav.length - 44) / 4; +const L = new Float32Array(N), R = new Float32Array(N), V = new Float32Array(N); +for (let k = 0; k < N; k++) { L[k] = wav.readInt16LE(44 + k * 4) / 32768; R[k] = wav.readInt16LE(46 + k * 4) / 32768; } + +// voix : chaque réplique normalisée puis posée à son instant +for (const { t, wav: f } of JSON.parse(fs.readFileSync('vo/plan.json'))) { + const b = fs.readFileSync(f), n = (b.length - 44) / 2; + let pk = 0; const s = new Float32Array(n); + for (let i = 0; i < n; i++) { s[i] = b.readInt16LE(44 + i * 2) / 32768; pk = Math.max(pk, Math.abs(s[i])); } + const g = .9 / pk, s0 = Math.round(t * SR); + for (let i = 0; i < n; i++) if (s0 + i < N) V[s0 + i] += s[i] * g; +} +// compression légère de la voix (plus présente sur un téléphone) +{ let env = 0; for (let k = 0; k < N; k++) { const a = Math.abs(V[k]); env = a > env ? env + (a - env) * .01 : env + (a - env) * .0003; const over = Math.max(0, env - .35); V[k] *= (env > .35 ? (.35 + over * .4) / env : 1) * 1.5; } } + +// enveloppe de présence de la voix → baisse de la musique à -10 dB (attaque 40 ms, relâche 300 ms) +const duck = new Float32Array(N); +{ let e = 0; const att = 1 - Math.exp(-1 / (.04 * SR)), rel = 1 - Math.exp(-1 / (.3 * SR)); + // anticipation de 60 ms pour que la musique baisse juste avant le premier mot + const look = Math.round(.06 * SR); + for (let k = 0; k < N; k++) { const a = Math.abs(V[Math.min(N - 1, k + look)]) > .02 ? 1 : 0; e += (a - e) * (a > e ? att : rel); duck[k] = 1 - .68 * e; } } + +let pk = 0; +for (let k = 0; k < N; k++) { + L[k] = Math.tanh(L[k] * duck[k] * .9 + V[k]); R[k] = Math.tanh(R[k] * duck[k] * .9 + V[k]); + pk = Math.max(pk, Math.abs(L[k]), Math.abs(R[k])); +} +const g = .89 / pk, out = Buffer.alloc(44 + N * 4); +out.write('RIFF', 0); out.writeUInt32LE(36 + N * 4, 4); out.write('WAVE', 8); out.write('fmt ', 12); +out.writeUInt32LE(16, 16); out.writeUInt16LE(1, 20); out.writeUInt16LE(2, 22); out.writeUInt32LE(SR, 24); +out.writeUInt32LE(SR * 4, 28); out.writeUInt16LE(4, 32); out.writeUInt16LE(16, 34); out.write('data', 36); out.writeUInt32LE(N * 4, 40); +for (let k = 0; k < N; k++) { out.writeInt16LE(Math.round(L[k] * g * 32767), 44 + k * 4); out.writeInt16LE(Math.round(R[k] * g * 32767), 46 + k * 4); } +fs.writeFileSync('mix.wav', out); +console.log('mix.wav ok'); diff --git a/docs/video/mix.wav b/docs/video/mix.wav new file mode 100644 index 0000000..5efb6e1 Binary files /dev/null and b/docs/video/mix.wav differ diff --git a/docs/video/music.js b/docs/video/music.js new file mode 100644 index 0000000..02d9806 --- /dev/null +++ b/docs/video/music.js @@ -0,0 +1,145 @@ +// Musique originale 120 BPM, 30 s, calée sur les temps forts de video-pub.html +process.chdir(__dirname); +const fs = require('fs'); +const SR = 48000, DUR = 30, N = SR * DUR; +const L = new Float32Array(N), R = new Float32Array(N); +const BEAT = 0.5; +let seed = 12345; const rnd = () => (seed = (seed * 1664525 + 1013904223) >>> 0) / 4294967296; +const mtof = m => 440 * Math.pow(2, (m - 69) / 12); +function add(t, dur, fn, pan = 0, buf = null) { + const s0 = Math.floor(t * SR), n = Math.floor(dur * SR); + const gl = Math.cos((pan + 1) * Math.PI / 4), gr = Math.sin((pan + 1) * Math.PI / 4); + for (let i = 0; i < n; i++) { + const k = s0 + i; if (k < 0 || k >= N) continue; + const v = fn(i / SR, i); + if (buf) { buf[k] += v; continue; } + L[k] += v * gl * 1.41; R[k] += v * gr * 1.41; + } +} +const inRange = (t, rs) => rs.some(([a, b]) => t >= a - 1e-6 && t < b - 1e-6); + +/* ---------- Sections ---------- */ +const DRUMS = [[0, 6], [8, 29.5]]; +const DROP = [[8, 12], [15, 18], [22, 29.5]]; // arpège lead +const PADS = [[0, 30]]; +const CHORDS = [[57, 60, 64], [53, 57, 60], [52, 55, 60], [55, 59, 62]]; // Am F C G +const ROOTS = [45, 41, 48, 43]; +const chordAt = t => Math.floor(t / 2) % 4; + +/* ---------- Sidechain ---------- */ +const kicks = []; +for (let t = 0; t < DUR; t += BEAT) if (inRange(t, DRUMS)) kicks.push(t); +const duck = new Float32Array(N).fill(1); +for (const tk of kicks) for (let i = 0; i < SR * .4; i++) { const k = Math.floor(tk * SR) + i; if (k < N) duck[k] = Math.min(duck[k], 1 - .65 * Math.exp(-i / SR / .11)); } + +/* ---------- Batterie ---------- */ +function kick(t, g = 1) { + let ph = 0; + add(t, .45, (x) => { const f = 45 + 110 * Math.exp(-x / .04); ph += 2 * Math.PI * f / SR; return g * .95 * Math.sin(ph) * Math.exp(-x / .16) + g * .3 * (rnd() * 2 - 1) * Math.exp(-x / .004); }); +} +function clap(t, g = 1) { + let lp = 0, prev = 0; + add(t, .3, (x) => { const n = rnd() * 2 - 1; const hp = n - prev; prev = n; lp += (hp - lp) * .5; const env = (x < .03 ? (Math.exp(-(x % .01) / .003)) : 1) * Math.exp(-x / .09); return g * .5 * lp * env + g * .18 * Math.sin(2 * Math.PI * 190 * x) * Math.exp(-x / .05); }, (rnd() - .5) * .3); +} +function hat(t, g = 1, open = false) { + let prev = 0; + add(t, open ? .25 : .06, (x) => { const n = rnd() * 2 - 1; const hp = n - prev; prev = n; return g * .22 * hp * Math.exp(-x / (open ? .08 : .018)); }, .35); +} +for (let t = 0; t < DUR; t += .125) { + if (!inRange(t, DRUMS)) continue; + const b = Math.round(t / .125) % 8; + if (b % 4 === 0) kick(t); + if (b === 4) clap(t); + if (b === 2 || b === 6) hat(t, 1, inRange(t, DROP)); + else hat(t, .45); +} +// roulement de caisse claire avant les ruptures (5,0→6,0 et 7,0→8,0, 14,0→15,0) +for (const [a, b] of [[5, 6], [7, 8], [14, 15], [25, 26]]) { + for (let t = a; t < b - 1e-6;) { const p = (t - a) / (b - a); clap(t, .35 + .6 * p); t += p < .5 ? .125 : .0625; } +} + +/* ---------- Basse ---------- */ +for (let t = 0; t < 29.5; t += .25) { + if (!inRange(t, DRUMS)) continue; + const b = Math.round(t / .25) % 2; if (b === 0 && !inRange(t, DROP)) continue; + const f = mtof(ROOTS[chordAt(t)] - 12 + (b ? 12 : 0) * 0), d = .22; + let ph = 0, lp = 0; + add(t, d, (x) => { ph = (ph + f / SR) % 1; const saw = 2 * ph - 1; const cut = .02 + .25 * Math.exp(-x / .05); lp += (saw - lp) * cut; return .55 * lp * Math.min(1, x / .004) * Math.exp(-x / .25) * (x > d - .01 ? (d - x) / .01 : 1); }); +} + +/* ---------- Pad supersaw (pompé par le kick) ---------- */ +const pad = new Float32Array(N), padR = new Float32Array(N); +for (let bar = 0; bar < 15; bar++) { + const t = bar * 2; if (!inRange(t, PADS)) continue; + const notes = CHORDS[bar % 4]; + for (const m of notes) for (const det of [-.12, 0, .11]) { + const f = mtof(m + det); let ph = rnd(), lp = 0; + const brk = inRange(t, [[6, 8]]); + add(t, 2.05, (x) => { ph = (ph + f / SR) % 1; lp += ((2 * ph - 1) - lp) * (brk ? .03 + .05 * (x / 2) : .09); return .055 * lp * Math.min(1, x / .02) * (x > 1.98 ? Math.max(0, (2.05 - x) / .07) : 1); }, 0, det < 0 ? pad : padR); + } +} +for (let k = 0; k < N; k++) { const g = (inRange(k / SR, [[6, 8]]) ? 1.6 : 1) * duck[k]; L[k] += (pad[k] * .8 + padR[k] * .2) * g; R[k] += (padR[k] * .8 + pad[k] * .2) * g; } + +/* ---------- Arpège lead (sections drop) + délai ---------- */ +const lead = new Float32Array(N); +for (let t = 0; t < DUR; t += .125) { + if (!inRange(t, DROP)) continue; + const c = CHORDS[chordAt(t)], i = Math.round(t / .125) % 8; + const m = c[[0, 1, 2, 1, 0, 2, 1, 2][i]] + 12 + (i === 7 ? 12 : 0), f = mtof(m); + let ph = 0, lp = 0; + add(t, .2, (x) => { ph = (ph + f / SR) % 1; const sq = ph < .5 ? 1 : -1; lp += (sq - lp) * (.05 + .3 * Math.exp(-x / .03)); return .08 * lp * Math.exp(-x / .07); }, 0, lead); +} +{ const d = Math.floor(.375 * SR); for (let k = 0; k < N; k++) { const dl = k >= d ? lead[k - d] : 0; const dr = k >= 2 * d ? lead[k - 2 * d] : 0; L[k] += (lead[k] + .45 * dl) * duck[k]; R[k] += (lead[k] + .35 * dr) * duck[k]; } } + +/* ---------- Effets synchronisés à l'image ---------- */ +function boom(t, g = 1) { let ph = 0; add(t, 1.6, (x) => { const f = 38 + 80 * Math.exp(-x / .06); ph += 2 * Math.PI * f / SR; return g * (.8 * Math.sin(ph) * Math.exp(-x / .5) + .25 * (rnd() * 2 - 1) * Math.exp(-x / .08)); }); } +function whoosh(t, d = .35, g = 1) { let lp = 0; add(t - d * .7, d, (x) => { const p = x / d; lp += ((rnd() * 2 - 1) - lp) * (.02 + .5 * p * p); return g * .5 * lp * Math.sin(Math.PI * p); }, 0); } +function riser(a, b, g = 1) { let lp = 0, ph = 0; add(a, b - a, (x) => { const p = x / (b - a); lp += ((rnd() * 2 - 1) - lp) * (.01 + .4 * p * p); ph = (ph + (200 + 1400 * p * p) / SR) % 1; return g * (.35 * lp + .05 * (2 * ph - 1)) * p * p; }); } +function bell(t, m, g = 1, d = .6) { const f = mtof(m); add(t, d, (x) => g * .22 * (Math.sin(2 * Math.PI * f * x) + .35 * Math.sin(2 * Math.PI * f * 2.01 * x) * Math.exp(-x / .08)) * Math.exp(-x / (d / 4)), (rnd() - .5) * .4); } +function beep(t, f, d = .07) { add(t, d, (x) => .16 * Math.sin(2 * Math.PI * f * x) * (x < .005 ? x / .005 : 1) * (x > d - .01 ? (d - x) / .01 : 1)); } +function boing(t) { let ph = 0; add(t, .35, (x) => { const f = 300 + 500 * Math.exp(-x / .06) * (1 + .2 * Math.sin(2 * Math.PI * 18 * x)); ph += 2 * Math.PI * f / SR; return .2 * Math.sin(ph) * Math.exp(-x / .12); }); } + +boom(0, .9); // 0,0 accroche +kick(.5, 1.2); boom(.5, .6); // 0,5 impact du tampon +whoosh(1.9, .25); // 1,9 whip pan +boom(2.5, .6); // 2,5 CARTON +boom(3, .4); whoosh(4, .15, .6); whoosh(5.07, .25); // slam / coupe / whip vertical +for (const t of [3.5, 4.5, 5.5]) clap(t, 1.1); // traits rouges +riser(4.5, 6, .9); boom(6, 1.1); // rupture verte +bell(6.25, 81, .7, 1.2); bell(7.5, 88, .7, 1.2); // « Et si… » / « téléphone ? » +riser(7, 8, .7); boom(8, .9); // drop comptoir +boing(8.5); kick(9, .8); // téléphone qui arrive / se pose +beep(9.5, 1975); beep(9.6, 2637, .1); // bip du scan +whoosh(10.42, .2, .6); +riser(11, 12, .6); whoosh(12.1, .35, 1); // zoom à travers l'écran +bell(13, 76, .8); bell(13.5, 81, .6); bell(14, 84, .6); // carte dans le Wallet + pastilles +whoosh(15.05, .3, .8); // volet diagonal +[15.5, 16.25, 16.75, 17.25, 17.5, 17.75].forEach((t, i) => { bell(t, [69, 72, 74, 76, 79, 81][i], .9, .5); kick(t, .5); }); +boom(18, 1.2); bell(18, 84, 1, 1.4); bell(18, 88, .8, 1.4); bell(18.06, 93, .6, 1.4); // 10/10 confettis +for (let i = 0; i < 26; i++) hat(18 + i * .03 + rnd() * .02, .7, true); +bell(18.5, 88, .6); +whoosh(20.07, .25); // whip pan +bell(20.75, 88, .8, .5); bell(20.87, 93, .8, .7); // notification +boom(22, .8); // flash +bell(22.35, 81, .5); bell(23.3, 84, .5); bell(24.55, 88, .5); // coches +for (let i = 0; i < 12; i++) beep(24.65 + i * .05, 1200 + i * 90, .03); // compteur 0 → 19 € +bell(25.25, 93, .9, .9); bell(25.25, 88, .6, .9); +boom(26, .7); whoosh(26.1, .3, .6); // signature +boing(26.5); boom(26.5, .5); // point jaune +bell(27.25, 81, .5); bell(27.75, 88, .5); +riser(28.5, 29.5, .7); +boom(29.5, .5); kick(29.75, 1); boom(29.75, .7); // la carte retombe (raccord boucle) + +/* ---------- Master ---------- */ +let peak = 0; +for (let k = 0; k < N; k++) { L[k] = Math.tanh(L[k] * 1.3); R[k] = Math.tanh(R[k] * 1.3); peak = Math.max(peak, Math.abs(L[k]), Math.abs(R[k])); } +const norm = .89 / peak; +// micro fondu de 5 ms aux extrémités +for (let k = 0; k < 240; k++) { const g = k / 240; L[k] *= g; R[k] *= g; L[N - 1 - k] *= g; R[N - 1 - k] *= g; } +const out = Buffer.alloc(44 + N * 4); +out.write('RIFF', 0); out.writeUInt32LE(36 + N * 4, 4); out.write('WAVE', 8); out.write('fmt ', 12); +out.writeUInt32LE(16, 16); out.writeUInt16LE(1, 20); out.writeUInt16LE(2, 22); out.writeUInt32LE(SR, 24); +out.writeUInt32LE(SR * 4, 28); out.writeUInt16LE(4, 32); out.writeUInt16LE(16, 34); out.write('data', 36); out.writeUInt32LE(N * 4, 40); +for (let k = 0; k < N; k++) { out.writeInt16LE(Math.round(Math.max(-1, Math.min(1, L[k] * norm)) * 32767), 44 + k * 4); out.writeInt16LE(Math.round(Math.max(-1, Math.min(1, R[k] * norm)) * 32767), 46 + k * 4); } +fs.writeFileSync('music.wav', out); +console.log('music.wav ok, peak avant normalisation', peak.toFixed(2)); diff --git a/docs/video/package.json b/docs/video/package.json new file mode 100644 index 0000000..8dcffff --- /dev/null +++ b/docs/video/package.json @@ -0,0 +1,17 @@ +{ + "name": "monespacepro-video", + "private": true, + "description": "Vidéo publicitaire MonEspacePro : animation, musique, voix off et rendu MP4", + "scripts": { + "musique": "node music.js", + "voix": "node voice.js", + "mixage": "node mix.js", + "rendu:60": "node render.js 60 ../MonEspacePro-pub-voix-60fps.mp4", + "rendu:120": "node render.js 120 ../MonEspacePro-pub-voix-120fps.mp4" + }, + "dependencies": { + "ffmpeg-static": "^5.3.0", + "msedge-tts": "^2.0.9", + "playwright-core": "^1.63.0" + } +} diff --git a/docs/video/render.js b/docs/video/render.js new file mode 100644 index 0000000..4fbbdf9 --- /dev/null +++ b/docs/video/render.js @@ -0,0 +1,35 @@ +// Rendu image par image de video-pub.html → MP4 (voix off + musique). +// Usage : node render.js [audio.wav, par défaut mix.wav] +process.chdir(__dirname); +const { chromium } = require('playwright-core'); +const ffmpeg = require('ffmpeg-static'); +const { spawn } = require('child_process'); +const FPS = +process.argv[2] || 120; +const OUT = require('path').resolve(process.argv[3] || `MonEspacePro-pub-${FPS}fps.mp4`); +const SRC = require('url').pathToFileURL(__dirname + '/video-pub.html').href + '?t=0'; + +(async () => { + const browser = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe', headless: true }); + const page = await browser.newPage({ viewport: { width: 1080, height: 1920 }, deviceScaleFactor: 1 }); + await page.goto(SRC); + await page.waitForFunction(() => typeof seek === 'function' && typeof A !== 'undefined' && A.length > 100 && document.fonts.check('800 100px Figtree')); + await page.addStyleTag({ content: '#replay{display:none!important}' }); + const ff = spawn(ffmpeg, ['-y', '-hide_banner', '-loglevel', 'error', + '-f', 'image2pipe', '-framerate', String(FPS), '-c:v', 'mjpeg', '-i', '-', + '-i', process.argv[4] || 'mix.wav', + '-c:v', 'libx264', '-preset', 'slow', '-crf', '17', '-pix_fmt', 'yuv420p', '-profile:v', 'high', + '-r', String(FPS), '-c:a', 'aac', '-b:a', '192k', '-ar', '48000', '-shortest', '-movflags', '+faststart', OUT], + { stdio: ['pipe', 'inherit', 'inherit'] }); + const total = FPS * 30; + const t0 = Date.now(); + for (let i = 0; i < total; i++) { + await page.evaluate(t => { seek(t); return new Promise(r => requestAnimationFrame(() => r())); }, i / FPS); + const buf = await page.screenshot({ type: 'jpeg', quality: 95, clip: { x: 0, y: 0, width: 1080, height: 1920 } }); + if (!ff.stdin.write(buf)) await new Promise(r => ff.stdin.once('drain', r)); + if (i % (FPS * 2) === 0) console.log(`${(i / FPS).toFixed(0)} s / 30 — ${((Date.now() - t0) / 1000).toFixed(0)} s écoulées`); + } + ff.stdin.end(); + await new Promise(r => ff.on('close', r)); + await browser.close(); + console.log('Terminé :', OUT); +})(); diff --git a/docs/video/video-pub.html b/docs/video/video-pub.html new file mode 100644 index 0000000..5541cd7 --- /dev/null +++ b/docs/video/video-pub.html @@ -0,0 +1,710 @@ + + + + + + +MonEspacePro — pub 30 s + + + + + + +
+
+ + +
+
+
Oubliée
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
Perdue
+
+
+
+
+
+
+
+
+
+ + +
+
+
Jamais
+
pleine
+
+
+
+
+ + +
+
+
Et si…
+
…elle était
+
dans son
+
téléphone ?
+
+
+ + +
+
+
Au comptoir
+
1 scan.
+
0 appli.
+ +
+
Scannez-moi
+
+
Boulangerie Kerlann
+
Carte de fidélité
+
+
+ +
+
+
+
+
+
+
Visez le QR code
+
+ +
+
+
+
Ajouter à Wallet
+
+
+
+
+
+ + +
+
+
+
+
+
Wallet
+
+
+
Banque
+
Transport
+
+
+
+
Apple Wallet
+
Google Wallet
+
+
+ + +
+
+
+
+
+
+
Offerte !
+
+
+ + +
+
+
+
+
+
08:47
+
mardi 7 octobre
+
+
BK
+
+
Boulangerie Kerlannmaintenant
+
Votre viennoiserie offerte vous attend !
+
+
+
+
+
Ils
+
reviennent.
+
+
+ + +
+
+
+ +
Prête en
+
5 minutes
+
+
+ +
+
+
+
+
+ +
À vos
+
couleurs
+
+
+
+ +
Dès
+
+
+
 €
+
/mois
+
+
sans engagement
+
+
+
+ + +
+
+
+ + + + + +
MonEspacePro
+
Créez votre carte
+
monespacepro.eu
+
+
+
+ + +
+
+
STOP
+
+
+
+
+
+
+
+
+
+
+
Fini la carte
+
en
+
CARTON.
+
+
+ +
+
+
+
+
+ + + + + diff --git a/docs/video/voice.js b/docs/video/voice.js new file mode 100644 index 0000000..5cb2f42 --- /dev/null +++ b/docs/video/voice.js @@ -0,0 +1,60 @@ +// Voix off : chaque réplique est générée séparément puis calée sur la timeline de la vidéo +process.chdir(__dirname); +const { MsEdgeTTS, OUTPUT_FORMAT } = require('msedge-tts'); +const ffmpeg = require('ffmpeg-static'); +const { execFileSync } = require('child_process'); +const fs = require('fs'); + +const VOICE = 'fr-FR-DeniseNeural'; +// [début (s), fin max (s), texte, débit] +const LINES = [ + [0.1, 1.4, 'Stop !', '+0%'], + [1.45, 3.0, 'Fini la carte en carton.', '+12%'], + [3.05, 4.0, 'Oubliée…', '+5%'], + [4.05, 5.0, 'Perdue…', '+5%'], + [5.1, 6.0, 'Jamais pleine.', '+8%'], + [6.25, 8.0, 'Et si elle était dans son téléphone ?', '+10%'], + [8.15, 10.4, 'Votre client scanne le QR code.', '+10%'], + [10.5, 12.0, 'Zéro appli à télécharger.', '+12%'], + [12.4, 15.0, 'Sa carte arrive dans Apple Wallet ou Google Wallet.', '+14%'], + [15.35, 17.95, 'À chaque passage, un tampon, en un scan.', '+12%'], + [18.25, 19.95, 'Au dixième, c’est offert !', '+12%'], + [20.55, 22.0, 'Une notif… et ils reviennent.', '+12%'], + [22.15, 23.25, 'Prête en cinq minutes.', '+12%'], + [23.35, 24.5, 'À vos couleurs.', '+8%'], + [24.55, 26.4, 'Dès dix-neuf euros par mois, sans engagement.', '+28%'], + [26.5, 27.3, 'Mon Espace Pro.', '+15%'], + [27.35, 29.45, 'Créez votre carte sur mon espace pro point e u.', '+22%'], +]; + +async function synth(text, rate, file) { + const tts = new MsEdgeTTS(); + await tts.setMetadata(VOICE, OUTPUT_FORMAT.AUDIO_24KHZ_96KBITRATE_MONO_MP3); + const { audioStream } = tts.toStream(text, { rate }); + const chunks = []; + await new Promise((res, rej) => { audioStream.on('data', c => chunks.push(c)); audioStream.on('end', res); audioStream.on('error', rej); }); + tts.close(); + fs.writeFileSync(file, Buffer.concat(chunks)); +} +function toWav(src, dst) { + // 48 kHz mono, silences de début et de fin retirés + execFileSync(ffmpeg, ['-y', '-loglevel', 'error', '-i', src, '-af', + 'silenceremove=start_periods=1:start_threshold=-45dB,areverse,silenceremove=start_periods=1:start_threshold=-45dB,areverse', + '-ar', '48000', '-ac', '1', '-c:a', 'pcm_s16le', dst]); + return (fs.statSync(dst).size - 44) / 2 / 48000; +} + +(async () => { + fs.mkdirSync('vo', { recursive: true }); + const plan = []; + for (let i = 0; i < LINES.length; i++) { + const [t, end, text, rate] = LINES[i]; + const mp3 = `vo/${String(i).padStart(2, '0')}.mp3`, wav = mp3.replace('.mp3', '.wav'); + await synth(text, rate, mp3); + const d = toWav(mp3, wav); + const ok = t + d <= end + .05; + console.log(`${ok ? 'OK ' : 'LONG'} ${t.toFixed(2)}→${(t + d).toFixed(2)} (max ${end}) ${text}`); + plan.push({ t, wav, d }); + } + fs.writeFileSync('vo/plan.json', JSON.stringify(plan, null, 1)); +})();