Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienos.com/blob/main/scripts/allen/allen_voice.py # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / scripts / allen / allen_voice.py` 107 lines ยท 5502 bytes Raw Blame History 1 """Aien's pre-recorded voice clips: choose clip ids for a turn, or none (the reply stays text-only). 2 3 The catalog (public/aien/voice/catalog.json, built by the AienVoice lane) lists every clip with 4 id, situation, tags, intent, text, file, duration, sha256, license and source. pick() maps a turn 5 to a situation, in this order: 6 1. an explicit situation from the caller (greeting, goodbye, error.busy, build.success, ...); 7 2. a pure first-turn greeting: time-of-day or return-visit greeting, then the intro menu; 8 3. the cached answer id (answers.json), e.g. "omega" -> explain.omega; 9 4. a short table of visitor intents (thanks, bye, "are you Allen", donations, vibe coding, ...). 10 No match returns []. Clips whose feature is not live ("requires") are never chosen. 11 Choice inside a situation is deterministic (hash of the turn), skipping clips already played. 12 Stdlib only. 13 """ 14 import hashlib 15 import json 16 import re 17 18 ANSWER_SITUATION = { 19 "si": "explain.sovereign_intelligence", "omega": "explain.omega", "aienos": "explain.aienos", 20 "cudapp-what": "explain.cudaplusplus", "install": "install.how", "drake": "explain.drake", 21 "learn": "learn.overview", "allen": "smalltalk.who_are_you", 22 } 23 24 # (situation, pattern over the visitor's message); first match wins. 25 INTENTS = [ 26 ("smalltalk.are_you_allen", r"\b(are you|r u|is this) allen\b|\bwhat happened to allen\b"), 27 ("smalltalk.are_you_human", r"\bare you (a )?(human|real|person|bot|robot|an? ai)\b"), 28 ("smalltalk.who_made_you", r"\bwho (made|built|created|makes) you\b"), 29 ("smalltalk.what_model", r"\bwhat (model|llm) are you\b|\bwhich model\b"), 30 ("smalltalk.name", r"\bhow do (you|i) (say|pronounce)\b.*\b(aien|your name)\b|\bpronounce\b"), 31 ("smalltalk.is_it_free", r"\b(is (it|this|aien) free|how much (does it )?cost|pricing|price)\b"), 32 ("smalltalk.how_are_you", r"\bhow are you\b|\bhow'?s it going\b|\bwhat'?s up\b"), 33 ("smalltalk.who_are_you", r"\bwho are you\b|\bwhat are you\b"), 34 ("donation.how", r"\b(donat\w*|tip|support drake|sponsor\w*|chip in)\b"), 35 ("encouragement.vibe_coder", r"\bvibe ?cod\w*\b|\bcan'?t (really )?code\b|\bnot a (real )?(coder|programmer)\b"), 36 ("encouragement.stuck", r"\b(i'?m stuck|stuck on|frustrat\w*|giving up|give up|nothing works)\b"), 37 ("academy.explain", r"\b(agent academy|academy|train (my|your) agent)\b"), 38 ("voice.help", r"\b(microphone|mic|push to talk|talk instead|voice input|speak to you)\b"), 39 ("mobile.home_screen", r"\b(home ?screen|on my phone|install (it|this|aien) on (my )?(phone|iphone|android))\b"), 40 ("repo.how", r"github\.com/[\w.-]+/[\w.-]+|\b(look at|review|check out) my (repo|code|project)\b"), 41 ("goodbye.general", r"^\s*(bye|goodbye|good night|see (you|ya)|later|cya|gotta go|i'?m off)\b"), 42 ("smalltalk.thanks", r"^\s*(thanks|thank you|thx|ty|cheers|appreciate it)\b"), 43 ] 44 INTENTS = [(s, re.compile(p, re.I)) for s, p in INTENTS] 45 46 GREETING = re.compile(r"^\s*(hi|hello|hey|hiya|yo|howdy|greetings|good (morning|afternoon|evening)|hi there|hey there|" 47 r"hello there)( (aien|allen))?[\s!.,]*$", re.I) 48 49 50 def time_situation(hour): 51 if hour is None: 52 return "greeting.first_visit" 53 if 5 <= hour < 12: 54 return "greeting.morning" 55 if 12 <= hour < 17: 56 return "greeting.afternoon" 57 if 17 <= hour < 22: 58 return "greeting.evening" 59 return "greeting.late_night" 60 61 62 class Voice: 63 def __init__(self, catalog_path, features=()): 64 with open(catalog_path, encoding="utf-8") as f: 65 cat = json.load(f) 66 self.features = frozenset(features) 67 self.clips = {c["id"]: c for c in cat["clips"]} 68 self.by_situation = {} 69 for c in cat["clips"]: 70 if set(c.get("requires", ())) <= self.features: 71 self.by_situation.setdefault(c["situation"], []).append(c["id"]) 72 73 def choose(self, situation, key, seen=()): 74 ids = self.by_situation.get(situation) 75 if not ids: 76 return None 77 fresh = [i for i in ids if i not in seen] or ids 78 h = int.from_bytes(hashlib.sha256((situation + "\0" + key).encode()).digest()[:8], "big") 79 return fresh[h % len(fresh)] 80 81 def situation_for(self, user_text, turn=0, answer_id=None): 82 if turn == 0 and GREETING.match(user_text or ""): 83 return "greeting" 84 if answer_id in ANSWER_SITUATION: 85 return ANSWER_SITUATION[answer_id] 86 for sit, pat in INTENTS: 87 if pat.search(user_text or ""): 88 return sit 89 return None 90 91 def pick(self, user_text="", situation=None, answer_id=None, turn=0, hour=None, returning=False, seen=()): 92 """Clip ids to play in order for this turn; [] means text-only.""" 93 key = "%s\0%d" % (user_text or "", turn) 94 sit = situation or self.situation_for(user_text, turn, answer_id) 95 if sit is None: 96 return [] 97 if sit == "greeting": 98 first = "greeting.return_visit" if returning else time_situation(hour) 99 out = [self.choose(first, key, seen) or self.choose("greeting.first_visit", key, seen), 100 self.choose("intro.menu", key, seen)] 101 return [i for i in out if i] 102 c = self.choose(sit, key, seen) 103 return [c] if c else [] 104 105 def files(self, ids): 106 """[{id, file, text, duration}] for the page player.""" 107 return [{k: self.clips[i][k] for k in ("id", "file", "text", "duration")} for i in ids if i in self.clips]