@lovelace_lol/polymer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -0
- package/dist/index.d.ts +2603 -0
- package/dist/index.js +1031 -0
- package/dist/test.cjs +1519 -0
- package/dist/worker/agency-worker.js +972 -0
- package/dist/worker/manifest.edn +1 -0
- package/package.json +57 -0
- package/shadow-cljs.edn +173 -0
- package/src/polymer/animation/agency.cljs +84 -0
- package/src/polymer/animation/domain.cljs +110 -0
- package/src/polymer/animation/planner.cljs +88 -0
- package/src/polymer/animation/runtime.cljs +137 -0
- package/src/polymer/animation/scheduler.cljs +178 -0
- package/src/polymer/animation/service.cljs +981 -0
- package/src/polymer/animation/state.cljs +112 -0
- package/src/polymer/blink/agency.cljs +131 -0
- package/src/polymer/blink/planner.cljs +115 -0
- package/src/polymer/blink/scheduler.cljs +90 -0
- package/src/polymer/blink/snippet.cljs +50 -0
- package/src/polymer/blink/state.cljs +102 -0
- package/src/polymer/camera_context/agency.cljs +132 -0
- package/src/polymer/camera_context/domain.cljs +186 -0
- package/src/polymer/camera_context/planner.cljs +50 -0
- package/src/polymer/camera_context/scheduler.cljs +113 -0
- package/src/polymer/camera_context/state.cljs +121 -0
- package/src/polymer/character.cljs +471 -0
- package/src/polymer/conversation/agency.cljs +83 -0
- package/src/polymer/conversation/domain.cljs +35 -0
- package/src/polymer/conversation/effector.cljs +130 -0
- package/src/polymer/conversation/planner.cljs +178 -0
- package/src/polymer/conversation/scheduler.cljs +202 -0
- package/src/polymer/conversation/service.cljs +329 -0
- package/src/polymer/conversation/state.cljs +186 -0
- package/src/polymer/core.cljs +172 -0
- package/src/polymer/eye_head/agency.cljs +75 -0
- package/src/polymer/eye_head/domain.cljs +133 -0
- package/src/polymer/eye_head/goap.cljs +106 -0
- package/src/polymer/eye_head/scheduler.cljs +176 -0
- package/src/polymer/eye_head/service.cljs +259 -0
- package/src/polymer/eye_head/snippet.cljs +92 -0
- package/src/polymer/eye_head/state.cljs +167 -0
- package/src/polymer/gaze/agency.cljs +85 -0
- package/src/polymer/gaze/domain.cljs +211 -0
- package/src/polymer/gaze/goap.cljs +208 -0
- package/src/polymer/gaze/scheduler.cljs +184 -0
- package/src/polymer/gaze/state.cljs +202 -0
- package/src/polymer/gesture/agency.cljs +185 -0
- package/src/polymer/gesture/goap.cljs +461 -0
- package/src/polymer/gesture/scheduler.cljs +122 -0
- package/src/polymer/gesture/snippet.cljs +198 -0
- package/src/polymer/gesture/state.cljs +273 -0
- package/src/polymer/lipsync/agency.cljs +593 -0
- package/src/polymer/lipsync/articulation/jaw.cljs +258 -0
- package/src/polymer/lipsync/articulation/snippet.cljs +605 -0
- package/src/polymer/lipsync/articulation/tongue.cljs +418 -0
- package/src/polymer/lipsync/articulation/visemes.cljs +429 -0
- package/src/polymer/lipsync/goap.cljs +132 -0
- package/src/polymer/lipsync/pronunciation/effector.cljs +51 -0
- package/src/polymer/lipsync/scheduler.cljs +302 -0
- package/src/polymer/lipsync/state.cljs +202 -0
- package/src/polymer/nlp/phonemes.cljs +164 -0
- package/src/polymer/prosodic/agency.cljs +196 -0
- package/src/polymer/prosodic/goap.cljs +122 -0
- package/src/polymer/prosodic/scheduler.cljs +99 -0
- package/src/polymer/prosodic/snippet.cljs +106 -0
- package/src/polymer/prosodic/state.cljs +139 -0
- package/src/polymer/runtime/embody.cljs +117 -0
- package/src/polymer/runtime/embody_wasm.cljs +177 -0
- package/src/polymer/runtime/rust_embody_host.cljs +645 -0
- package/src/polymer/society.cljs +239 -0
- package/src/polymer/stream.cljs +130 -0
- package/src/polymer/transcription/agency.cljs +69 -0
- package/src/polymer/transcription/domain.cljs +68 -0
- package/src/polymer/transcription/effector.cljs +611 -0
- package/src/polymer/transcription/planner.cljs +203 -0
- package/src/polymer/transcription/scheduler.cljs +225 -0
- package/src/polymer/transcription/service.cljs +209 -0
- package/src/polymer/transcription/state.cljs +239 -0
- package/src/polymer/tts/agency.cljs +503 -0
- package/src/polymer/tts/azure.cljs +290 -0
- package/src/polymer/tts/planner.cljs +178 -0
- package/src/polymer/tts/runtime.cljs +624 -0
- package/src/polymer/tts/scheduler.cljs +162 -0
- package/src/polymer/tts/state.cljs +191 -0
- package/src/polymer/worker.cljs +70 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
(ns polymer.transcription.state
|
|
2
|
+
(:require [clojure.string :as str]
|
|
3
|
+
[polymer.transcription.domain :as domain]))
|
|
4
|
+
|
|
5
|
+
;; Transcription state tracks recognition session lifecycle and ordered transcript
|
|
6
|
+
;; facts. Browser APIs such as Web Speech and microphone access are handled by
|
|
7
|
+
;; the agency's effector, outside these pure transitions.
|
|
8
|
+
|
|
9
|
+
(def default-config
|
|
10
|
+
{:provider "webSpeech"
|
|
11
|
+
:lang "en-US"
|
|
12
|
+
:continuous true
|
|
13
|
+
:interimResults true
|
|
14
|
+
:maxAlternatives 1
|
|
15
|
+
:maxRetries 2
|
|
16
|
+
:retryDelayMs 100
|
|
17
|
+
:minConfidence 0
|
|
18
|
+
:agentFilteringEnabled true
|
|
19
|
+
:interruptDetectionEnabled true
|
|
20
|
+
:requireAgentReferenceForInterruption true
|
|
21
|
+
:interruptionDebugLogging false
|
|
22
|
+
:interruptionVolumeThreshold 0.035
|
|
23
|
+
:interruptionReferenceScale 0.45
|
|
24
|
+
:interruptionReferenceOffset 0.015
|
|
25
|
+
:interruptionHoldMs 150})
|
|
26
|
+
|
|
27
|
+
(defn finite-number?
|
|
28
|
+
[value]
|
|
29
|
+
(and (number? value) (js/isFinite value)))
|
|
30
|
+
|
|
31
|
+
(defn number-or
|
|
32
|
+
[value fallback]
|
|
33
|
+
(if (finite-number? value) value fallback))
|
|
34
|
+
|
|
35
|
+
(defn clamp
|
|
36
|
+
[lo hi value]
|
|
37
|
+
(min hi (max lo value)))
|
|
38
|
+
|
|
39
|
+
(defn normalize-config
|
|
40
|
+
[config]
|
|
41
|
+
(let [input (merge default-config (domain/data-map config))]
|
|
42
|
+
{:provider (domain/text-or (:provider input) (:provider default-config))
|
|
43
|
+
:lang (domain/text-or (:lang input) (:lang default-config))
|
|
44
|
+
:continuous (boolean (:continuous input))
|
|
45
|
+
:interimResults (boolean (:interimResults input))
|
|
46
|
+
:maxAlternatives (int (clamp 1 10 (number-or (:maxAlternatives input)
|
|
47
|
+
(:maxAlternatives default-config))))
|
|
48
|
+
:maxRetries (int (clamp 0 10 (number-or (:maxRetries input)
|
|
49
|
+
(:maxRetries default-config))))
|
|
50
|
+
:retryDelayMs (int (clamp 0 5000 (number-or (:retryDelayMs input)
|
|
51
|
+
(:retryDelayMs default-config))))
|
|
52
|
+
:minConfidence (clamp 0 1 (number-or (:minConfidence input)
|
|
53
|
+
(:minConfidence default-config)))
|
|
54
|
+
:agentFilteringEnabled (boolean (:agentFilteringEnabled input))
|
|
55
|
+
:interruptDetectionEnabled (boolean (:interruptDetectionEnabled input))
|
|
56
|
+
:requireAgentReferenceForInterruption (boolean (:requireAgentReferenceForInterruption input))
|
|
57
|
+
:interruptionDebugLogging (boolean (:interruptionDebugLogging input))
|
|
58
|
+
:interruptionVolumeThreshold (clamp 0 1 (number-or (:interruptionVolumeThreshold input)
|
|
59
|
+
(:interruptionVolumeThreshold default-config)))
|
|
60
|
+
:interruptionReferenceScale (clamp 0 4 (number-or (:interruptionReferenceScale input)
|
|
61
|
+
(:interruptionReferenceScale default-config)))
|
|
62
|
+
:interruptionReferenceOffset (clamp 0 1 (number-or (:interruptionReferenceOffset input)
|
|
63
|
+
(:interruptionReferenceOffset default-config)))
|
|
64
|
+
:interruptionHoldMs (int (clamp 0 2000 (number-or (:interruptionHoldMs input)
|
|
65
|
+
(:interruptionHoldMs default-config))))}))
|
|
66
|
+
|
|
67
|
+
(defn default-state
|
|
68
|
+
[config]
|
|
69
|
+
{:agency "transcription"
|
|
70
|
+
:status "idle"
|
|
71
|
+
:active false
|
|
72
|
+
:sessionId nil
|
|
73
|
+
:sequence 0
|
|
74
|
+
:currentTranscript nil
|
|
75
|
+
:isFinal false
|
|
76
|
+
:lastPartial nil
|
|
77
|
+
:lastFinal nil
|
|
78
|
+
:lastError nil
|
|
79
|
+
:lastTtsEvent nil
|
|
80
|
+
:agentSpeaking false
|
|
81
|
+
:agentSpeechStatus "idle"
|
|
82
|
+
:agentWords #{}
|
|
83
|
+
:agentScript ""
|
|
84
|
+
:lastEvent nil
|
|
85
|
+
:retryCount 0
|
|
86
|
+
:startedCount 0
|
|
87
|
+
:stoppedCount 0
|
|
88
|
+
:partialCount 0
|
|
89
|
+
:finalCount 0
|
|
90
|
+
:errorCount 0
|
|
91
|
+
:ignoredCount 0
|
|
92
|
+
:interruptionCount 0
|
|
93
|
+
:config (normalize-config config)})
|
|
94
|
+
|
|
95
|
+
(defn config->state
|
|
96
|
+
[config]
|
|
97
|
+
(default-state config))
|
|
98
|
+
|
|
99
|
+
(defn visible-state
|
|
100
|
+
[state]
|
|
101
|
+
(clj->js state))
|
|
102
|
+
|
|
103
|
+
(defn configure
|
|
104
|
+
[state config]
|
|
105
|
+
(assoc state :config (normalize-config (merge (:config state)
|
|
106
|
+
(domain/data-map config)))))
|
|
107
|
+
|
|
108
|
+
(defn reset-state
|
|
109
|
+
[state]
|
|
110
|
+
(default-state (:config state)))
|
|
111
|
+
|
|
112
|
+
(defn next-session-id
|
|
113
|
+
[]
|
|
114
|
+
(str "transcription:" (.now js/Date) ":" (rand-int 1000000)))
|
|
115
|
+
|
|
116
|
+
(defn start-session
|
|
117
|
+
[state now-ms]
|
|
118
|
+
(-> state
|
|
119
|
+
(assoc :active true
|
|
120
|
+
:status "starting"
|
|
121
|
+
:sessionId (next-session-id)
|
|
122
|
+
:lastError nil
|
|
123
|
+
:retryCount 0
|
|
124
|
+
:lastEvent {:type "transcription.status"
|
|
125
|
+
:status "starting"
|
|
126
|
+
:at now-ms})
|
|
127
|
+
(update :startedCount inc)))
|
|
128
|
+
|
|
129
|
+
(defn provider-started
|
|
130
|
+
[state now-ms]
|
|
131
|
+
(assoc state
|
|
132
|
+
:status "listening"
|
|
133
|
+
:lastError nil
|
|
134
|
+
:lastEvent {:type "transcription.status"
|
|
135
|
+
:status "listening"
|
|
136
|
+
:reason "provider-started"
|
|
137
|
+
:at now-ms}))
|
|
138
|
+
|
|
139
|
+
(defn stop-session
|
|
140
|
+
[state now-ms reason]
|
|
141
|
+
(-> state
|
|
142
|
+
(assoc :active false
|
|
143
|
+
:status "idle"
|
|
144
|
+
:currentTranscript nil
|
|
145
|
+
:isFinal false
|
|
146
|
+
:lastEvent {:type "transcription.status"
|
|
147
|
+
:status "idle"
|
|
148
|
+
:reason reason
|
|
149
|
+
:at now-ms})
|
|
150
|
+
(update :stoppedCount inc)))
|
|
151
|
+
|
|
152
|
+
(defn next-sequence
|
|
153
|
+
[state]
|
|
154
|
+
(inc (:sequence state)))
|
|
155
|
+
|
|
156
|
+
(defn record-partial
|
|
157
|
+
[state fact]
|
|
158
|
+
(-> state
|
|
159
|
+
(assoc :status "listening"
|
|
160
|
+
:sequence (:sequence fact)
|
|
161
|
+
:currentTranscript (:text fact)
|
|
162
|
+
:isFinal false
|
|
163
|
+
:lastPartial fact
|
|
164
|
+
:lastEvent fact)
|
|
165
|
+
(update :partialCount inc)))
|
|
166
|
+
|
|
167
|
+
(defn record-final
|
|
168
|
+
[state fact]
|
|
169
|
+
(-> state
|
|
170
|
+
(assoc :status "listening"
|
|
171
|
+
:sequence (:sequence fact)
|
|
172
|
+
:currentTranscript (:text fact)
|
|
173
|
+
:isFinal true
|
|
174
|
+
:lastPartial nil
|
|
175
|
+
:lastFinal fact
|
|
176
|
+
:lastEvent fact
|
|
177
|
+
:retryCount 0)
|
|
178
|
+
(update :finalCount inc)))
|
|
179
|
+
|
|
180
|
+
(defn record-error
|
|
181
|
+
[state error now-ms retrying?]
|
|
182
|
+
(-> state
|
|
183
|
+
(assoc :status (if retrying? "retrying" "error")
|
|
184
|
+
:lastError error
|
|
185
|
+
:lastEvent {:type "transcription.error"
|
|
186
|
+
:message error
|
|
187
|
+
:retrying retrying?
|
|
188
|
+
:at now-ms})
|
|
189
|
+
(update :errorCount inc)
|
|
190
|
+
(update :retryCount (fn [count] (if retrying? (inc count) count)))))
|
|
191
|
+
|
|
192
|
+
(defn record-ignored
|
|
193
|
+
[state ignored]
|
|
194
|
+
(-> state
|
|
195
|
+
(assoc :lastEvent ignored)
|
|
196
|
+
(update :ignoredCount inc)))
|
|
197
|
+
|
|
198
|
+
(defn record-interruption
|
|
199
|
+
[state fact]
|
|
200
|
+
(-> state
|
|
201
|
+
(assoc :lastEvent fact)
|
|
202
|
+
(update :interruptionCount inc)))
|
|
203
|
+
|
|
204
|
+
(defn record-tts-status
|
|
205
|
+
[state fact]
|
|
206
|
+
(let [speaking? (boolean (:speaking fact))
|
|
207
|
+
phrase (or (:phrase fact) (:text fact))
|
|
208
|
+
words (or (some-> phrase domain/word-set)
|
|
209
|
+
(some->> (:words fact) (map str/lower-case) set))]
|
|
210
|
+
(cond-> (assoc state
|
|
211
|
+
:agentSpeaking speaking?
|
|
212
|
+
:agentSpeechStatus (:status fact)
|
|
213
|
+
:lastTtsEvent fact
|
|
214
|
+
:lastEvent fact)
|
|
215
|
+
words (assoc :agentWords words
|
|
216
|
+
:agentScript (str/lower-case (or phrase
|
|
217
|
+
(str/join " " (:words fact)))))
|
|
218
|
+
(not speaking?) (assoc :agentWords #{}
|
|
219
|
+
:agentScript ""))))
|
|
220
|
+
|
|
221
|
+
(defn prepare-agent-speech
|
|
222
|
+
[state text append?]
|
|
223
|
+
(let [script (str/lower-case (or text ""))
|
|
224
|
+
words (domain/word-set script)]
|
|
225
|
+
(assoc state
|
|
226
|
+
:agentSpeaking true
|
|
227
|
+
:agentSpeechStatus "speaking"
|
|
228
|
+
:agentScript (if append?
|
|
229
|
+
(str/trim (str (:agentScript state) " " script))
|
|
230
|
+
script)
|
|
231
|
+
:agentWords (if append?
|
|
232
|
+
(into (:agentWords state) words)
|
|
233
|
+
words))))
|
|
234
|
+
|
|
235
|
+
(defn record-agent-word
|
|
236
|
+
[state word]
|
|
237
|
+
(let [token (str/lower-case (or word ""))]
|
|
238
|
+
(cond-> state
|
|
239
|
+
(seq token) (update :agentWords conj token))))
|