Become a Pro / website · becomeapro.ai / src / lib / audio.ts
| 1 | // Pronunciation clip for a <Say> word or sentence: /audio/<slug>.mp3, made from the exact text by scripts/make-audio.mjs |
| 2 | export function audioSlug(text: string): string { |
| 3 | return text |
| 4 | .toLowerCase() |
| 5 | .normalize("NFKD") |
| 6 | .replace(/[̀-ͯ]/g, "") |
| 7 | .replace(/[^a-z0-9]+/g, "-") |
| 8 | .replace(/^-+|-+$/g, "") |
| 9 | .slice(0, 80) |
| 10 | .replace(/-+$/g, ""); |
| 11 | } |
| 12 | |
| 13 | export function audioFileFor(text: string): string { |
| 14 | return `/audio/${audioSlug(text)}.mp3`; |
| 15 | } |