Commit 2b2cb6d
authored
feat(stt): add energy-based VAD with silence gate and auto-stop (#249)
* loop: stt-warmup completed after 6 iterations
* refactor: extract STT startup helpers and simplify audio recorder
* feat(stt): add energy-based VAD with silence gate and auto-stop
- New VoiceActivityDetector class: adaptive noise floor, per-frame RMS
classification, trailing-silence endpointing, configurable thresholds
- AudioWorkletProcessor computes RMS in existing flush loop and posts
{samples, rms} instead of a bare Int16Array
- AudioRecorder integrates VAD via handleVadFrame() in both worklet and
ScriptProcessor paths; auto-calls stop() on trailing silence; silence
gate in processRecording() fires onNoSpeech instead of sending empty
audio to the transcription API (fixes Whisper hallucination bug)
- useSTT wires setOnNoSpeech to reset isProcessing/isRecording cleanly
without surfacing an error
- computeRms() exported helper for ScriptProcessor fallback path
* fix(stt): clear processing state when stopping a silent recording
stopRecording() called recorder.stop() before setIsProcessing(true). For
a silent take the recorder synchronously fires onNoSpeech (which sets
processing false), so the subsequent setIsProcessing(true) won and the
voice overlay was stuck in the processing state forever.
Set processing before stop() so the recorder callback (onNoSpeech or
onDataAvailable) has the final say on the processing flag.
* fix(stt): always emit a terminal signal so the voice overlay never sticks
Two remaining stuck paths after the silent-stop fix:
- processRecording() early-returned without firing onNoSpeech when a take
had no captured audio (e.g. a quick start/stop under one worklet flush,
totalSamples === 0). Now any non-emitting path (empty audio or no
detected speech) fires onNoSpeech, while a genuine abort still returns
silently.
- stopRecording() set isProcessing true even when the recorder was no
longer recording (double-stop or post auto-stop), where stop() skips
processRecording entirely and nothing clears the flag. Guard the
external path on recorder state before entering processing.
* loop: mediarecorder-stt completed after 6 iterations
* refactor(stt): extract shared helpers and cleanup
* refactor(stt): add separate arm/disarm thresholds for voice swipe
* fix(stt): prevent default touch behavior on voice gesture handlers
* feat(stt): add audio-level speech detection before emitting data1 parent ab624a0 commit 2b2cb6d
13 files changed
Lines changed: 1626 additions & 550 deletions
File tree
- frontend
- public
- src
- api
- components
- message
- settings
- hooks
- lib
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
| |||
123 | 136 | | |
124 | 137 | | |
125 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
65 | | - | |
| 73 | + | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| 77 | + | |
69 | 78 | | |
70 | 79 | | |
71 | 80 | | |
| |||
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
| 87 | + | |
| 88 | + | |
78 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
79 | 93 | | |
80 | 94 | | |
81 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
496 | 497 | | |
497 | 498 | | |
498 | 499 | | |
| 500 | + | |
499 | 501 | | |
500 | 502 | | |
501 | 503 | | |
| |||
510 | 512 | | |
511 | 513 | | |
512 | 514 | | |
| 515 | + | |
513 | 516 | | |
514 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
515 | 520 | | |
516 | 521 | | |
517 | 522 | | |
| |||
532 | 537 | | |
533 | 538 | | |
534 | 539 | | |
| 540 | + | |
535 | 541 | | |
536 | 542 | | |
537 | 543 | | |
| |||
1096 | 1102 | | |
1097 | 1103 | | |
1098 | 1104 | | |
1099 | | - | |
| 1105 | + | |
1100 | 1106 | | |
1101 | 1107 | | |
1102 | 1108 | | |
1103 | 1109 | | |
1104 | 1110 | | |
1105 | 1111 | | |
1106 | 1112 | | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1107 | 1116 | | |
1108 | 1117 | | |
1109 | 1118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| |||
0 commit comments