Branchwell

Become a Pro / website · becomeapro.ai / src / lib / audio.ts

Raw 463 B on d27a4e234d2622fe12dfe92667dd00367e1dc2de
1// Pronunciation clip for a <Say> word or sentence: /audio/<slug>.mp3, made from the exact text by scripts/make-audio.mjs
2export 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
13export function audioFileFor(text: string): string {
14 return `/audio/${audioSlug(text)}.mp3`;
15}