nx_voice_read_gate.nx source
↩ module page · 155 lines · 7045 B
1// nx_voice_read_gate.nx -- REFEREE for VOICE-CLONE-001 rung 5-FUSE (voice reads words).
2//
3// Two parametric speakers read two words from a shared phoneme inventory:
4// spk1 : warp 1.00, F0 120 spk2 : warp 1.20, F0 175
5// WORD_A = /a/ /i/ /u/ WORD_B = /u/ /i/ /a/ (same sounds, reordered)
6//
7// PROVES (measured via rung-1 voiceprint distance, printed):
8// ARTICULATION : each speaker's WORD_A has 3 spectrally-distinct SEGMENTS
9// (>1M) -> the voice reads the sequence, doesn't sustain a sound.
10// SPEAKER IDENTITY DOMINATES CONTENT (the fuse) -- measured on the WHOLE
11// utterance (averaging out per-phoneme context, as real speaker-ID does):
12// same_voice = dist(spkX wordA, spkX wordB) must be SMALL
13// diff_voice = dist(spk1 wordY, spk2 wordY) must be LARGE
14// assert max(same_voice) * 2 < min(diff_voice)
15// i.e. a speaker stays recognizably THEMSELVES across different words, while a
16// different speaker reading the same word is clearly a different voice ->
17// "this voice reads this text."
18//
19// Evidence -> stdout + knowledge/status/voice_read_gate.log. Exit 0 GREEN / 1 RED.
20// Sovereign x86_64 throughout. license_tier: ORIGINAL
21import "nx_syscalls_x86_64.nx"
22import "nx_voice_read.nx"
23import "nx_voiceprint.nx"
24
25const DUR: i64 = 1200
26const CAP: i64 = 4096
27const WHOLE: i64 = 3600 // 3 phonemes * DUR
28
29func gp(logfd: i64, s: *u8) -> i64 {
30 var n: i64 = 0
31 while s[n] != (0 as u8) { n = n + 1 }
32 sys_write(1, s, n)
33 if logfd > 0 { sys_write(logfd, s, n) }
34 return 0
35}
36func gn(logfd: i64, v: i64) -> i64 {
37 let bb: *u8 = sys_mmap(28)
38 var m: i64 = v
39 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m }
40 let t: *u8 = sys_mmap(28)
41 var k: i64 = 0
42 if m == 0 { t[0] = 48 as u8; k = 1 }
43 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
44 var i: i64 = 0
45 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
46 sys_write(1, bb, k)
47 if logfd > 0 { sys_write(logfd, bb, k) }
48 return 0
49}
50func sethz(seq: *i64, idx: i64, f1: i64, f2: i64, f3: i64, v: i64, dur: i64) -> i64 {
51 seq[idx * PH_REC + 0] = f1
52 seq[idx * PH_REC + 1] = f2
53 seq[idx * PH_REC + 2] = f3
54 seq[idx * PH_REC + 3] = v
55 seq[idx * PH_REC + 4] = dur
56 return 0
57}
58// per-segment voiceprint (articulation): skip 400 transition, 760-sample window
59func seg_vp(pcm: *u8, segstart: i64, vp: *i64) -> i64 {
60 let p: *u8 = (pcm as i64 + (segstart + 400) * 2) as *u8
61 return nx_voiceprint_extract(p, 760, vp)
62}
63// whole-utterance voiceprint (speaker identity): all voiced frames, skip cold-start
64func whole_vp(pcm: *u8, vp: *i64) -> i64 {
65 let p: *u8 = (pcm as i64 + 400 * 2) as *u8
66 return nx_voiceprint_extract(p, WHOLE - 400, vp)
67}
68
69func wordA(seq: *i64) -> i64 {
70 sethz(seq, 0, 730, 1090, 2440, 1, DUR) // /a/
71 sethz(seq, 1, 270, 2290, 3010, 1, DUR) // /i/
72 sethz(seq, 2, 300, 870, 2440, 1, DUR) // /u/
73 return 0
74}
75func wordB(seq: *i64) -> i64 {
76 sethz(seq, 0, 300, 870, 2440, 1, DUR) // /u/
77 sethz(seq, 1, 270, 2290, 3010, 1, DUR) // /i/
78 sethz(seq, 2, 730, 1090, 2440, 1, DUR) // /a/
79 return 0
80}
81
82func main() -> i64 {
83 let logfd: i64 = sys_openat_append("knowledge/status/voice_read_gate.log\x00" as *u8, 0x1a4)
84 gp(logfd, "VOICE-READ-GATE VOICE-CLONE-001 rung5-FUSE\n\x00" as *u8)
85
86 let seq: *i64 = sys_mmap(PH_REC * 8 * 4) as *i64
87
88 // render the four (speaker x word) utterances
89 let pA1: *u8 = sys_mmap(CAP * 2)
90 let pA2: *u8 = sys_mmap(CAP * 2)
91 let pB1: *u8 = sys_mmap(CAP * 2)
92 let pB2: *u8 = sys_mmap(CAP * 2)
93 wordA(seq); nx_voice_read(seq, 3, 120, 100, 100, pA1, CAP) // spk1 word A
94 wordA(seq); nx_voice_read(seq, 3, 175, 120, 100, pA2, CAP) // spk2 word A
95 wordB(seq); nx_voice_read(seq, 3, 120, 100, 100, pB1, CAP) // spk1 word B
96 wordB(seq); nx_voice_read(seq, 3, 175, 120, 100, pB2, CAP) // spk2 word B
97
98 // ARTICULATION (per-segment) on word A
99 let a1s0: *i64 = sys_mmap(VP_WORDS * 8) as *i64
100 let a1s1: *i64 = sys_mmap(VP_WORDS * 8) as *i64
101 let a1s2: *i64 = sys_mmap(VP_WORDS * 8) as *i64
102 seg_vp(pA1, 0, a1s0); seg_vp(pA1, 1200, a1s1); seg_vp(pA1, 2400, a1s2)
103 let a2s0: *i64 = sys_mmap(VP_WORDS * 8) as *i64
104 let a2s1: *i64 = sys_mmap(VP_WORDS * 8) as *i64
105 let a2s2: *i64 = sys_mmap(VP_WORDS * 8) as *i64
106 seg_vp(pA2, 0, a2s0); seg_vp(pA2, 1200, a2s1); seg_vp(pA2, 2400, a2s2)
107 let art1_01: i64 = nx_voiceprint_distance(a1s0, a1s1)
108 let art1_12: i64 = nx_voiceprint_distance(a1s1, a1s2)
109 let art1_02: i64 = nx_voiceprint_distance(a1s0, a1s2)
110 let art2_01: i64 = nx_voiceprint_distance(a2s0, a2s1)
111 let art2_12: i64 = nx_voiceprint_distance(a2s1, a2s2)
112 let art2_02: i64 = nx_voiceprint_distance(a2s0, a2s2)
113
114 // SPEAKER IDENTITY (whole utterance)
115 let WA1: *i64 = sys_mmap(VP_WORDS * 8) as *i64
116 let WA2: *i64 = sys_mmap(VP_WORDS * 8) as *i64
117 let WB1: *i64 = sys_mmap(VP_WORDS * 8) as *i64
118 let WB2: *i64 = sys_mmap(VP_WORDS * 8) as *i64
119 whole_vp(pA1, WA1); whole_vp(pA2, WA2); whole_vp(pB1, WB1); whole_vp(pB2, WB2)
120 let same1: i64 = nx_voiceprint_distance(WA1, WB1) // spk1: word A vs word B
121 let same2: i64 = nx_voiceprint_distance(WA2, WB2) // spk2: word A vs word B
122 let diffA: i64 = nx_voiceprint_distance(WA1, WA2) // word A: spk1 vs spk2
123 let diffB: i64 = nx_voiceprint_distance(WB1, WB2) // word B: spk1 vs spk2
124
125 gp(logfd, " artic spk1 0-1=\x00" as *u8); gn(logfd, art1_01); gp(logfd, " 1-2=\x00" as *u8); gn(logfd, art1_12); gp(logfd, " 0-2=\x00" as *u8); gn(logfd, art1_02); gp(logfd, "\n\x00" as *u8)
126 gp(logfd, " artic spk2 0-1=\x00" as *u8); gn(logfd, art2_01); gp(logfd, " 1-2=\x00" as *u8); gn(logfd, art2_12); gp(logfd, " 0-2=\x00" as *u8); gn(logfd, art2_02); gp(logfd, "\n\x00" as *u8)
127 gp(logfd, " same_voice spk1=\x00" as *u8); gn(logfd, same1); gp(logfd, " spk2=\x00" as *u8); gn(logfd, same2); gp(logfd, "\n\x00" as *u8)
128 gp(logfd, " diff_voice wordA=\x00" as *u8); gn(logfd, diffA); gp(logfd, " wordB=\x00" as *u8); gn(logfd, diffB); gp(logfd, "\n\x00" as *u8)
129
130 var maxsame: i64 = same1
131 if same2 > maxsame { maxsame = same2 }
132 var mindiff: i64 = diffA
133 if diffB < mindiff { mindiff = diffB }
134
135 var ok: i64 = 1
136 if art1_01 < 1000000 { ok = 0 }
137 if art1_12 < 1000000 { ok = 0 }
138 if art1_02 < 1000000 { ok = 0 }
139 if art2_01 < 1000000 { ok = 0 }
140 if art2_12 < 1000000 { ok = 0 }
141 if art2_02 < 1000000 { ok = 0 }
142 if mindiff < 1000000 { ok = 0 } // voices genuinely differ
143 if maxsame * 2 >= mindiff { ok = 0 } // speaker identity dominates content
144
145 if ok == 1 {
146 gp(logfd, "VOICE-READ-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8)
147 if logfd > 0 { sys_close(logfd) }
148 sys_exit(0)
149 return 0
150 }
151 gp(logfd, "VOICE-READ-GATE result=FAIL verdict=RED\n\x00" as *u8)
152 if logfd > 0 { sys_close(logfd) }
153 sys_exit(1)
154 return 1
155}