// Synthetic "voices" for the speaker-similarity tests (release 34 N2): additive // harmonic speech-like sound, deterministic for its parameters. Two voices // differ the way two people do to a speaker-embedding model — pitch and the // resonances of the vocal tract — and nothing in them is a recording. // // syntheticVoice({ f0, formants, seconds, rate, syllableHz, phase }) // f0 fundamental in Hz (a low voice ~100, a high one ~220) // formants [[centreHz, bandwidthHz], …] — each harmonic's gain is the // sum of these resonances (a vowel colour) // syllableHz the on/off rate of the syllable envelope (default 4) // phase shifts the syllables and the vibrato, so two takes of ONE // voice are different sound with the same colour // withSilence(samples, { before, after, rate }) pads with digital silence. // VOICE_A / VOICE_B: two voices a model should tell apart. export const VOICE_A = Object.freeze({ f0: 105, formants: [[700, 130], [1220, 160], [2600, 250]] }); export const VOICE_B = Object.freeze({ f0: 215, formants: [[380, 90], [2250, 220], [3050, 300]] }); export function syntheticVoice({ f0, formants, seconds = 2, rate = 16000, syllableHz = 4, phase = 0, level = 0.3 }) { const n = Math.round(seconds * rate); const out = new Float32Array(n); const top = Math.min(4000, rate / 2 - 200); const gains = []; for (let k = 1; k * f0 * 1.06 < top; k += 1) { const f = k * f0; let g = 0; for (const [c, b] of formants) g += 1 / (1 + ((f - c) / b) ** 2); gains.push(g / k ** 0.5); } let ph = 0; for (let i = 0; i < n; i += 1) { const t = i / rate; // A slow vibrato and a falling-rising intonation: pitch is never a constant. const pitch = f0 * (1 + 0.03 * Math.sin(2 * Math.PI * 5.5 * t + phase) + 0.06 * Math.sin(2 * Math.PI * 0.4 * t + phase * 0.7)); ph += (2 * Math.PI * pitch) / rate; let s = 0; for (let k = 0; k < gains.length; k += 1) s += gains[k] * Math.sin((k + 1) * ph); const env = 0.5 - 0.5 * Math.cos(2 * Math.PI * syllableHz * t + phase); out[i] = s * env; } let peak = 0; for (const x of out) peak = Math.max(peak, Math.abs(x)); if (peak > 0) for (let i = 0; i < n; i += 1) out[i] = (out[i] / peak) * level; return out; } export function withSilence(samples, { before = 0, after = 0, rate = 16000 } = {}) { const a = Math.round(before * rate); const b = Math.round(after * rate); const out = new Float32Array(a + samples.length + b); out.set(samples, a); return out; }