nx_tts_speak.nx
buildroot/runtime/nx_tts_speak.nx
about
nx_tts_speak.nx -- R2.3: TEXT-TO-SPEECH. The GENERATOR that supersedes the fixed-word demos (nx_tts_word "hi",
nx_tts_seq "hello"): a grapheme-to-phoneme (G2P) front-end maps ANY English text -> a phoneme sequence, then the
phoneme synthesizer (formant source-filter, continuous cascade state = the proven nx_tts_seq core) renders it to
a WAV. G2P = a small EXCEPTION DICTIONARY for common irregular words (English spelling is irregular: "love","you"
don't follow rules) + rule-based letter->sound with digraph lookahead (th/sh/ch/ee/oo/ai/...) for the rest --
exactly how real G2P works (dict + rules fallback). Synthesizes "i love you" (inventory-friendly, no plosives) to
web_assets for /listen. Robotic formant quality (honest), but it now generalizes past 2 words. license_tier: ORIGINAL expect_exit: 0
dependencies 5 imports · 0 importers
imports: nx_syscalls.nxnx_f32.nxnx_f32_sincos.nxnx_f32_exp.nxnx_f32_cvt.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 13 | const F_MAGIC_1500: i64 = 1500 |
| 14 | const F_MAGIC_2500: i64 = 2500 |
| 15 | const F_MAGIC_1150: i64 = 1150 |
| 16 | const F_MAGIC_2900: i64 = 2900 |
| 17 | const F_MAGIC_1850: i64 = 1850 |
| 18 | const F_MAGIC_2250: i64 = 2250 |
| 19 | const F_MAGIC_1200: i64 = 1200 |
| 20 | const F_MAGIC_1100: i64 = 1100 |
| 21 | const F_MAGIC_2200: i64 = 2200 |
| 22 | const F_MAGIC_1700: i64 = 1700 |
| 23 | const F_MAGIC_2700: i64 = 2700 |
| 24 | const F_MAGIC_1300: i64 = 1300 |
| 25 | const F_MAGIC_1600: i64 = 1600 |
| 26 | const F_MAGIC_2400: i64 = 2400 |
| 27 | const F_MAGIC_1400: i64 = 1400 |
| 28 | const F_MAGIC_5000: i64 = 5000 |
| 29 | const F_MAGIC_7000: i64 = 7000 |
| 30 | const F_MAGIC_8000: i64 = 8000 |
| 31 | const F_MAGIC_2000: i64 = 2000 |
| 32 | const F_MAGIC_3000: i64 = 3000 |
| 33 | const F_MAGIC_4000: i64 = 4000 |
| 34 | const F_MAGIC_6000: i64 = 6000 |
| 35 | const F_MAGIC_1103515245: i64 = 1103515245 |
| 36 | const F_MAGIC_12345: i64 = 12345 |
| 37 | const F_MAGIC_32768: i64 = 32768 |
| 38 | const F_MAGIC_131072: i64 = 131072 |
| 39 | const F_MAGIC_32767: i64 = 32767 |
| 41 | const SR: i64 = 16000 |
| 42 | const F_PI: i64 = 0x40490FDB |
| 43 | const F_2PI: i64 = 0x40C90FDB |
| 44 | const F_ONE: i64 = 0x3F800000 |
| 46 | const EXC_VOICED: i64 = 0 |
| 47 | const EXC_NASAL: i64 = 1 |
| 48 | const EXC_NOISE: i64 = 2 |
| 49 | const EXC_VFRIC: i64 = 3 |
| 50 | const EXC_SIL: i64 = 4 |
| 52 | const P_SIL: i64=0 |
| 53 | const P_A: i64=1 // ah (father) |
| 54 | const P_E: i64=2 // eh (bet) |
| 55 | const P_I: i64=3 // ee (see) |
| 56 | const P_O: i64=4 // oh (go) |
| 57 | const P_U: i64=5 // oo (boot) |
| 58 | const P_UH: i64=6 // uh (cup/schwa) |
| 59 | const P_M: i64=7 |
| 60 | const P_N: i64=8 |
| 61 | const P_L: i64=9 |
| 62 | const P_R: i64=10 |
| 63 | const P_H: i64=11 |
| 64 | const P_V: i64=12 |
| 65 | const P_Z: i64=13 |
| 66 | const P_S: i64=14 |
| 67 | const P_F: i64=15 |
| 68 | const P_W: i64=16 |
| 69 | const P_Y: i64=17 |
| 70 | const P_SH: i64=18 |
| 71 | const NPH: i64=19 |
| 72 | const WAV_PATH: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/web_assets/ng_elara_iloveyou.wav" as *u8 |
functions
| 74 | func tw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 75 | func tn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } |
| 78 | func set_ph(f1: *i64, f2: *i64, f3: *i64, ex: *i64, id: i64, a: i64, b: i64, c: i64, e: i64) -> i64 { f1[id]=a; f2[id]=b; f3[id]=c; ex[id]=e; return 0 } called by 1: build_tables |
| 79 | func build_tables(f1: *i64, f2: *i64, f3: *i64, ex: *i64) -> i64 |
| 103 | func lc(c: u8) -> u8 { if c>=(65 as u8) { if c<=(90 as u8) { return (c+(32 as u8)) as u8 } } return c } |
| 104 | func streq(a: *u8, b: *u8, n: i64) -> i64 { var i: i64=0; while i<n { if lc(a[i])!=b[i] { return 0 } i=i+1 } return 1 } |
| 106 | func emit(out: *i64, o: *i64, id: i64) -> i64 { out[o[0]]=id; o[0]=o[0]+1; return 0 } |
| 109 | func dict_word(w: *u8, wl: i64, out: *i64, o: *i64) -> i64 |
| 121 | func letter_ph(c: u8) -> i64 |
| 141 | func rules_word(w: *u8, wl: i64, out: *i64, o: *i64) -> i64 |
| 155 | func g2p(text: *u8, tl: i64, out: *i64) -> i64 |
| 178 | func reson_ab(F: i64, BW: i64, out2: *i64) -> i64 |
| 187 | func cascade(x: i64, ab: *i64, st: *i64) -> i64 |
| 195 | func f32_to_int(m: i64) -> i64 called by 1: main |
| 203 | func glottal(phase: i64, period: i64) -> i64 |
| 211 | func prng(st: *i64) -> i64 { st[0] = (st[0]*F_MAGIC_1103515245 + F_MAGIC_12345) & 0x7FFFFFFF; return st[0] } called by 1: render |
| 212 | func pB(buf: *u8, po: *i64, b: i64) -> i64 { buf[po[0]] = (b & 0xFF) as u8; po[0]=po[0]+1; return 0 } |
| 213 | func pU16(buf: *u8, po: *i64, v: i64) -> i64 { pB(buf,po,v); pB(buf,po,v>>8); return 0 } |
| 214 | func pU32(buf: *u8, po: *i64, v: i64) -> i64 { pB(buf,po,v); pB(buf,po,v>>8); pB(buf,po,v>>16); pB(buf,po,v>>24); return 0 } |
| 215 | func pStr(buf: *u8, po: *i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ buf[po[0]]=s[i]; po[0]=po[0]+1; i=i+1 } return 0 } called by 1: main |
| 218 | func render(id: i64, f1: *i64, f2: *i64, f3: *i64, ex: *i64, dur: i64, smp: *i64, so: *i64, st: *i64, rng: *i64, ntotal: i64, pacc: *i64) -> i64 |
| 250 | func main() -> i64 |