Repository navigation
Commit 5c43bd3
authored
fix(hooks): allow VAD streamInsert/streamStop during streaming (#1196)
## Description
`useVAD` exposed `stream`, `streamInsert`, and `streamStop` all through
`useModuleFactory.runForward`, which rejects calls while `isGenerating
=== true`. Once `stream()` was in flight, every `streamInsert(chunk)`
rejected with *"model is currently generating"* — making the streaming
API unusable in practice.
Add a `runSideChannel` primitive to `useModuleFactory` that only checks
`isReady` (never `isGenerating` and never flips it). Streaming hooks now
have two regimes:
- Gated (`runForward`): `forward`, `stream` — one at a time.
- Side-channel (`runSideChannel`): `streamInsert`, `streamStop` —
allowed *during* a running stream.
`useVAD.streamInsert` / `streamStop` now use `runSideChannel`.
`useTextToSpeech` and `useSpeechToText` aren't affected (they avoid
`useModuleFactory` entirely for their side-channel methods); they're
candidates for a follow-up migration onto the new primitive.
### Introduces a breaking change?
- [ ] Yes
- [x] No
### Type of change
- [x] Bug fix (change which fixes an issue)
- [ ] New feature (change which adds functionality)
- [ ] Documentation update (improves or adds clarity to existing
documentation)
- [ ] Other (chores, tests, code style improvements etc.)
### Tested on
- [ ] iOS
- [x] Android
### Testing instructions
End-to-end on the `apps/speech` Voice Activity Detection screen:
1. Build and install the speech app on an Android device (mic required;
the screen disables Start on simulators).
2. Tap **Start VAD Stream** multiple times very quick, speak and pause.
With this PR: `SPEAKING` / `SILENT` events appear in the log as
expected. Without it (`git checkout HEAD~1 --
packages/react-native-executorch/src/hooks/{useModuleFactory.ts,natural_language_processing/useVAD.ts}`
and reload Metro): `streamInsert` rejects on every 100 ms audio chunk
and no SPEAKING transition fires and error occurs.
### Related issues
Fixes #11731 parent 778c507 commit 5c43bd3
2 files changed
Lines changed: 28 additions & 18 deletions
File tree
- packages/react-native-executorch/src/hooks
- natural_language_processing
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
20 | 26 | | |
21 | 27 | | |
22 | 28 | | |
| |||
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 34 | + | |
32 | 35 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
| |||
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
| 116 | + | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| |||
0 commit comments