Skip to content

Commit 3bcb1f6

Browse files
committed
feat(voicerec): add push-to-talk mode and topic routing
1 parent d580402 commit 3bcb1f6

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/nodes/browser/voicerec.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,42 @@ export const voicerecRuntime = {
1010
this.status(status);
1111
});
1212

13-
this.status({ text: 'Starting...', fill: 'yellow' });
14-
this.mainThread('start', {
15-
lang: this.config.lang || 'en-US',
16-
continuous: this.config.continuous !== false,
17-
interimResults: this.config.interimResults || false
18-
});
13+
const isPushToTalk = this.config.mode === 'push-to-talk';
14+
15+
// In push-to-talk mode, don't auto-start - wait for push signal
16+
if (isPushToTalk) {
17+
this.status({ text: 'Ready', fill: 'yellow' });
18+
} else {
19+
// Continuous mode - start immediately
20+
this.status({ text: 'Starting...', fill: 'yellow' });
21+
this.mainThread('start', {
22+
lang: this.config.lang || 'en-US',
23+
topic: this.config.topic || '',
24+
mode: this.config.mode || 'continuous',
25+
autoRestart: this.config.continuous !== false,
26+
interimResults: this.config.interimResults || false
27+
});
28+
}
1929
},
2030

2131
onInput(msg) {
22-
if (msg.payload === 'stop') {
32+
const payload = typeof msg.payload === 'string' ? msg.payload.toLowerCase() : '';
33+
const isPushToTalk = this.config.mode === 'push-to-talk';
34+
35+
// Handle stop/release commands
36+
if (payload === 'stop' || payload === 'release') {
2337
this.mainThread('stop', {});
24-
} else {
25-
this.status({ text: 'Starting...', fill: 'yellow' });
38+
return;
39+
}
40+
41+
// Handle start/push commands
42+
if (payload === 'start' || payload === 'push' || payload === '') {
43+
this.status({ text: isPushToTalk ? 'Recording...' : 'Starting...', fill: 'yellow' });
2644
this.mainThread('start', {
2745
lang: this.config.lang || 'en-US',
28-
continuous: this.config.continuous !== false,
46+
topic: this.config.topic || '',
47+
mode: this.config.mode || 'continuous',
48+
autoRestart: !isPushToTalk && this.config.continuous !== false,
2949
interimResults: this.config.interimResults || false
3050
});
3151
}

0 commit comments

Comments
 (0)