// speech-accent-demo.el - PROOF: Neuron speaks with a BRITISH accent, where the
// accent is a TRANSFORM composed onto the voice (voice (+) accent, separable),
// INGESTED as geometry (not a table). Same voice, accent toggled on/off = RP/GA.

fn main() {
    let outdir: String = "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-acc02900ef4ade35e/elp/tests/examples/out/"

    // LEARN: base phonetics + lexicon + the British-RP accent transform, all as
    // ingested geometry (source -> manifold -> engram).
    let pmap: [String] = ingest_phonetics("elp/data/phonetics.psv")
    let lmap: [String] = ingest_lexicon("elp/data/lexicon.psv")
    let amap: [String] = ingest_accent("elp/data/british-accent.psv")
    println("[learn] phonemes=" + int_to_str(native_list_len(pmap) / 2) + " words=" + int_to_str(native_list_len(lmap) / 2) + " accent_targets=" + int_to_str(native_list_len(amap) / 2))

    let neuron: [String] = voice_neuron()
    let noaccent: [String] = native_list_empty()

    // -- Sentence 1: "I am Neuron." from meaning ----------------------------
    let fr1: [String] = sem_frame("describe", "I", "Neuron", "")
    let t1: String = sem_realize(fr1)
    let c1: [String] = text_phonemes(lmap, t1)
    println("[s1] " + t1 + " :: " + list_join(c1, " "))

    // separability: SAME voice, accent OFF (GA) vs ON (RP)
    let ga: [Int] = synth_codes_accent(c1, neuron, pmap, noaccent)
    let okga: Bool = write_wav(ga, 16000, outdir + "ga-neuron.wav")
    let br1: [Int] = synth_codes_accent(c1, neuron, pmap, amap)
    let okb1: Bool = write_wav(br1, 16000, outdir + "british-neuron.wav")

    // -- Sentence 2: showcases NON-RHOTICITY --------------------------------
    let fr2: [String] = sem_frame("describe", "I", "here", "")
    let t2: String = sem_realize(fr2)
    let c2: [String] = text_phonemes(lmap, t2)
    let c2rp: [String] = apply_rhoticity(c2, pmap)
    println("[s2] " + t2 + " :: GA=" + list_join(c2, " ") + "  RP=" + list_join(c2rp, " "))
    let br2: [Int] = synth_codes_accent(c2, neuron, pmap, amap)
    let okb2: Bool = write_wav(br2, 16000, outdir + "british-2.wav")

    // show an RP override read straight from the accent geometry
    let ovAA: [Int] = accent_formants(amap, "AA")
    if native_list_len(ovAA) >= 3 {
        println("[accent-geometry] AA(LOT) RP f1=" + int_to_str(native_list_get(ovAA, 0)) + " f2=" + int_to_str(native_list_get(ovAA, 1)) + " (base GA 730/1090) [PROVISIONAL]")
    }
    println("[done] ga-neuron=" + bool_to_str(okga) + " british-neuron=" + bool_to_str(okb1) + " british-2=" + bool_to_str(okb2))
}
