MonEspacePro/docs/video/voice.js
2026-10-08 15:30:12 +02:00

60 lines
2.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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));
})();