File size: 2,424 Bytes
63dd1f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
import sys
import time
from pathlib import Path

from audio_ear.recorder import record_to_wav
from audio_ear.feature_extractor import extract_features
from hdc_encoder.encoder import encode
from dream_engine.consolidator import DreamEngine
from dream_engine.helix_memory import HelixMemory

def log_success(intent: str, details: dict) -> None:
    from cognition.mind import VitalisMind
    mind = VitalisMind()
    mind.ledger.append({"type": "success", "intent": intent, "details": details})

def log_failure(intent: str, error: str) -> None:
    from cognition.mind import VitalisMind
    mind = VitalisMind()
    mind.ledger.append({"type": "failure", "intent": intent, "error": error})

def cmd_listen(args: argparse.Namespace) -> None:
    out_path = Path(args.output or f"/tmp/live_{int(time.time())}.wav")
    print(f"🔊 Recording {args.duration}s -> {out_path}")
    record_to_wav(duration_sec=args.duration, out_path=out_path)
    mfcc, prosody = extract_features(out_path)
    hv = encode(mfcc, prosody)
    
    helix_path = Path.home() / ".vitalis_workspace" / "helix_memory.pkl"
    helix = HelixMemory(helix_path)
    dreamer = DreamEngine(helix)
    dreamer.ingest(hv, meta={"source": str(out_path), "prosody": prosody})
    
    log_success("listen_live", {"file": str(out_path)})
    print("✅ Ingested into DreamEngine.")

def cmd_dream(args: argparse.Namespace) -> None:
    helix_path = Path.home() / ".vitalis_workspace" / "helix_memory.pkl"
    helix = HelixMemory(helix_path)
    dreamer = DreamEngine(helix)
    dreamer.dream(force=True)
    print("💤 Consolidation complete.")

def build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(prog="vitalis")
    sub = parser.add_subparsers(dest="command", required=True)

    p_listen = sub.add_parser("listen")
    p_listen.add_argument("-d", "--duration", type=int, default=10)
    p_listen.add_argument("-o", "--output", type=str)
    p_listen.set_defaults(func=cmd_listen)

    p_dream = sub.add_parser("dream")
    p_dream.set_defaults(func=cmd_dream)

    return parser

def main(argv: list | None = None) -> None:
    parser = build_parser()
    args = parser.parse_args(argv)
    try: args.func(args)
    except Exception as exc:
        log_failure(intent=args.command, error=str(exc))
        print(f"❌ Failed: {exc}", file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    main()