@luxass/pi-voice 0.2.0 → 0.3.0
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/LICENSE +21 -0
- package/README.md +15 -14
- package/package.json +17 -5
- package/src/index.ts +167 -69
- package/src/profile.ts +7 -3
- package/src/setup.ts +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lucas Nørgård
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -8,23 +8,24 @@ Record speech and paste the transcription into [Pi](https://github.com/badlogic/
|
|
|
8
8
|
pi install npm:@luxass/pi-voice
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Requires Node.js 24+ and microphone access. Linux also needs `libasound.so.2`. Run `/voice setup` to choose a local or API transcription profile and an input device. Local transcription uses GGUF models; the model picker can download Whisper or Parakeet models.
|
|
12
12
|
|
|
13
13
|
## Use
|
|
14
14
|
|
|
15
|
-
Press **Ctrl+Shift+V** or run `/voice` to start recording. Press it again to stop, transcribe, and paste the result into the composer. The extension does not send your message for you.
|
|
15
|
+
Press **Ctrl+Shift+V** or run `/voice` to start recording. Requirements are checked before the microphone starts. If something is missing, Voice explains it and offers to open setup. Completing setup does not start recording; press the shortcut or run `/voice` again when you are ready. Press it again to stop, transcribe, and paste the result into the composer. The extension does not send your message for you.
|
|
16
16
|
|
|
17
|
-
| Command | Purpose
|
|
18
|
-
| ---------------------- |
|
|
19
|
-
| `/voice` | Start or stop recording and transcribe on stop.
|
|
20
|
-
| `/voice cancel` | Discard the current recording.
|
|
21
|
-
| `/voice
|
|
22
|
-
| `/voice
|
|
23
|
-
| `/voice profile`
|
|
24
|
-
| `/voice profile
|
|
25
|
-
| `/voice
|
|
26
|
-
| `/voice
|
|
17
|
+
| Command | Purpose |
|
|
18
|
+
| ---------------------- | ---------------------------------------------------- |
|
|
19
|
+
| `/voice` | Start or stop recording and transcribe on stop. |
|
|
20
|
+
| `/voice cancel` | Discard the current recording. |
|
|
21
|
+
| `/voice setup` | Choose a profile and input, then check requirements. |
|
|
22
|
+
| `/voice device` | Choose an input device or the system default. |
|
|
23
|
+
| `/voice profile add` | Create a local or API transcription profile. |
|
|
24
|
+
| `/voice profile` | Switch between saved profiles. |
|
|
25
|
+
| `/voice profile model` | Change the active profile's model. |
|
|
26
|
+
| `/voice status` | Show the current profile and input device. |
|
|
27
|
+
| `/voice doctor` | Check recording and transcription setup. |
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
A local profile without an explicit model uses the first GGUF model in `~/.cache/agent-voice`. Set `AGENT_VOICE_MODEL_DIR` to keep models elsewhere. For API transcription, `/voice profile add` asks for the endpoint, model, request format, and **name of an environment variable** holding the API key. Keep the key in your environment, not in the settings file.
|
|
29
30
|
|
|
30
|
-
Settings are
|
|
31
|
+
Settings are loaded once at boot from Pi's agent directory, using `voice-settings.json`. Set `AGENT_VOICE_SETTINGS` to use a different file. TypeBox validates known fields, while extra keys are accepted without warnings. If the file is missing, Voice shows a setup hint. If it cannot be loaded or validated, Voice shows the errors and keeps `/voice setup` available. Loading never rewrites the file. Setup saves a complete configuration and updates it in memory; manual file edits require `/reload`. A recording keeps the profile it started with.
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/pi-voice",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Record voice input with /voice, transcribe locally or through an API, and paste it into Pi's composer.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"dictation",
|
|
7
|
+
"pi",
|
|
8
|
+
"pi-extension",
|
|
9
|
+
"pi-package",
|
|
10
|
+
"speech-to-text",
|
|
11
|
+
"transcription",
|
|
12
|
+
"voice",
|
|
13
|
+
"whisper"
|
|
7
14
|
],
|
|
15
|
+
"license": "MIT",
|
|
8
16
|
"repository": {
|
|
9
17
|
"type": "git",
|
|
10
18
|
"url": "https://github.com/luxass/pi-extensions",
|
|
@@ -12,20 +20,24 @@
|
|
|
12
20
|
},
|
|
13
21
|
"files": [
|
|
14
22
|
"src",
|
|
15
|
-
"README.md"
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
16
25
|
],
|
|
17
26
|
"type": "module",
|
|
18
27
|
"publishConfig": {
|
|
19
28
|
"access": "public"
|
|
20
29
|
},
|
|
21
30
|
"dependencies": {
|
|
22
|
-
"@luxass/agent-voice": "0.
|
|
31
|
+
"@luxass/agent-voice": "0.5.0"
|
|
23
32
|
},
|
|
24
33
|
"peerDependencies": {
|
|
25
34
|
"@earendil-works/pi-ai": "*",
|
|
26
35
|
"@earendil-works/pi-coding-agent": "*",
|
|
27
36
|
"@earendil-works/pi-tui": "*"
|
|
28
37
|
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=24"
|
|
40
|
+
},
|
|
29
41
|
"pi": {
|
|
30
42
|
"extensions": [
|
|
31
43
|
"./src/index.ts"
|
package/src/index.ts
CHANGED
|
@@ -9,19 +9,23 @@ import { Key } from "@earendil-works/pi-tui";
|
|
|
9
9
|
import {
|
|
10
10
|
createRecorder,
|
|
11
11
|
getActiveProfile,
|
|
12
|
-
listInputDevices,
|
|
13
12
|
loadVoiceSettings,
|
|
14
13
|
runDoctor,
|
|
15
14
|
saveVoiceSettings,
|
|
16
15
|
transcribe,
|
|
16
|
+
type DoctorCheck,
|
|
17
17
|
type DoctorCheckId,
|
|
18
|
+
type Recorder,
|
|
19
|
+
type VoiceSettings,
|
|
18
20
|
} from "@luxass/agent-voice";
|
|
19
21
|
|
|
20
22
|
import { pickLocalModel, promptProfile } from "./profile";
|
|
23
|
+
import { promptInputDevice, promptSetup } from "./setup";
|
|
21
24
|
|
|
22
25
|
const SUBCOMMANDS = [
|
|
23
26
|
{ value: "record", description: "start/stop recording, transcribe on stop" },
|
|
24
27
|
{ value: "cancel", description: "discard the in-progress recording" },
|
|
28
|
+
{ value: "setup", description: "configure transcription and input, then check requirements" },
|
|
25
29
|
{ value: "device", description: "select input device" },
|
|
26
30
|
{ value: "profile", description: "select transcription profile" },
|
|
27
31
|
{ value: "profile add", description: "create a transcription profile" },
|
|
@@ -35,50 +39,135 @@ const DOCTOR_FIXES: Partial<Record<DoctorCheckId, string>> = {
|
|
|
35
39
|
model: "run /voice profile model",
|
|
36
40
|
};
|
|
37
41
|
|
|
42
|
+
function formatChecks(checks: DoctorCheck[]): string {
|
|
43
|
+
return checks
|
|
44
|
+
.map(({ id, ok, detail, fix }) =>
|
|
45
|
+
ok ? `✓ ${id}: ${detail}` : `✗ ${id}: ${detail} → ${DOCTOR_FIXES[id] ?? fix}`,
|
|
46
|
+
)
|
|
47
|
+
.join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function statusText(settings: VoiceSettings, state = "idle"): string {
|
|
51
|
+
const { name, transcription } = getActiveProfile(settings);
|
|
52
|
+
const model =
|
|
53
|
+
transcription.type === "api"
|
|
54
|
+
? transcription.model
|
|
55
|
+
: basename(transcription.model ?? "auto model", ".gguf");
|
|
56
|
+
return `voice ${state} · ${name} · ${model} · ${settings.inputDevice?.name ?? "system default"}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
38
59
|
export default function voice(pi: ExtensionAPI) {
|
|
39
60
|
const path = process.env.AGENT_VOICE_SETTINGS ?? join(getAgentDir(), "voice-settings.json");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
let configuration = loadVoiceSettings(path);
|
|
62
|
+
let recorder: Recorder | undefined;
|
|
63
|
+
let recording: { settings: VoiceSettings; recorder: Recorder } | undefined;
|
|
64
|
+
let busy = false;
|
|
65
|
+
|
|
66
|
+
function setupMessage(): string {
|
|
67
|
+
return [
|
|
68
|
+
"Voice needs setup. Run /voice setup.",
|
|
69
|
+
...configuration.errors.map(({ path, message }) => `${path}: ${message}`),
|
|
70
|
+
].join("\n");
|
|
50
71
|
}
|
|
51
72
|
|
|
52
|
-
function
|
|
53
|
-
|
|
73
|
+
function save(settings: VoiceSettings): void {
|
|
74
|
+
saveVoiceSettings(path, settings);
|
|
75
|
+
configuration = { settings, errors: [] };
|
|
54
76
|
}
|
|
55
77
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
78
|
+
function showStatus(ui: ExtensionContext["ui"], settings: VoiceSettings, state?: string): void {
|
|
79
|
+
ui.setStatus("voice", statusText(settings, state ?? (recording ? "● recording" : "idle")));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function setup(ctx: ExtensionContext): Promise<void> {
|
|
83
|
+
if (!ctx.hasUI) {
|
|
84
|
+
ctx.ui.notify("Run /voice setup in an interactive Pi session", "info");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (recording) {
|
|
88
|
+
ctx.ui.notify("Stop recording before running setup", "warning");
|
|
67
89
|
return;
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
|
|
92
|
+
const draft = await promptSetup(ctx.ui, configuration.settings);
|
|
93
|
+
if (draft == null) return;
|
|
94
|
+
const checks = await runDoctor(draft);
|
|
95
|
+
save(draft);
|
|
96
|
+
const ready = checks.every(({ ok }) => ok);
|
|
97
|
+
showStatus(ctx.ui, draft, ready ? "ready" : "needs setup");
|
|
98
|
+
ctx.ui.notify(
|
|
99
|
+
ready
|
|
100
|
+
? "Voice is ready. Press Ctrl+Shift+V or run /voice to record."
|
|
101
|
+
: `Voice profile saved. Finish these requirements before recording:\n${formatChecks(checks.filter(({ ok }) => !ok))}`,
|
|
102
|
+
ready ? "info" : "warning",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function offerSetup(ctx: ExtensionContext, message: string): Promise<void> {
|
|
107
|
+
ctx.ui.notify(message, configuration.errors.length > 0 ? "warning" : "info");
|
|
108
|
+
if (ctx.hasUI && (await ctx.ui.confirm("Voice needs setup", "Open voice setup now?"))) {
|
|
109
|
+
await setup(ctx);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Pi reports recording, transcription and save errors from these handlers.
|
|
114
|
+
async function toggle(ctx: ExtensionContext): Promise<void> {
|
|
115
|
+
if (busy) return;
|
|
116
|
+
busy = true;
|
|
71
117
|
try {
|
|
72
|
-
|
|
118
|
+
if (recording) {
|
|
119
|
+
const active = recording;
|
|
120
|
+
recording = undefined;
|
|
121
|
+
showStatus(ctx.ui, active.settings, "transcribing…");
|
|
122
|
+
try {
|
|
123
|
+
const audio = await active.recorder.stop();
|
|
124
|
+
const text = await transcribe(audio, getActiveProfile(active.settings).transcription);
|
|
125
|
+
ctx.ui.pasteToEditor(text);
|
|
126
|
+
ctx.ui.notify("Transcription pasted into the composer", "info");
|
|
127
|
+
} finally {
|
|
128
|
+
showStatus(ctx.ui, active.settings);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const { settings } = configuration;
|
|
134
|
+
if (!settings) {
|
|
135
|
+
await offerSetup(ctx, setupMessage());
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const checks = await runDoctor(settings);
|
|
139
|
+
if (checks.some(({ ok }) => !ok)) {
|
|
140
|
+
await offerSetup(ctx, formatChecks(checks.filter(({ ok }) => !ok)));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const active = {
|
|
145
|
+
settings: structuredClone(settings),
|
|
146
|
+
recorder: (recorder ??= await createRecorder()),
|
|
147
|
+
};
|
|
148
|
+
recording = active;
|
|
149
|
+
showStatus(ctx.ui, active.settings, "starting…");
|
|
73
150
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
151
|
+
await active.recorder.start({
|
|
152
|
+
input: active.settings.inputDevice,
|
|
153
|
+
onError: (error) => {
|
|
154
|
+
recording = undefined;
|
|
155
|
+
showStatus(ctx.ui, active.settings);
|
|
156
|
+
ctx.ui.notify(`Recording failed: ${error.message}`, "error");
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
recording = undefined;
|
|
161
|
+
showStatus(ctx.ui, active.settings);
|
|
162
|
+
throw error;
|
|
79
163
|
}
|
|
164
|
+
if (!active.recorder.isRecording) return;
|
|
165
|
+
showStatus(ctx.ui, active.settings);
|
|
166
|
+
ctx.ui.notify(
|
|
167
|
+
`Recording from ${active.settings.inputDevice?.name ?? "system default"}… run again to transcribe`,
|
|
168
|
+
);
|
|
80
169
|
} finally {
|
|
81
|
-
|
|
170
|
+
busy = false;
|
|
82
171
|
}
|
|
83
172
|
}
|
|
84
173
|
|
|
@@ -96,63 +185,68 @@ export default function voice(pi: ExtensionAPI) {
|
|
|
96
185
|
return items.length > 0 ? items : null;
|
|
97
186
|
},
|
|
98
187
|
handler: async (args, ctx) => {
|
|
99
|
-
|
|
188
|
+
const command = args.trim().replaceAll(/\s+/gu, " ");
|
|
189
|
+
switch (command) {
|
|
100
190
|
case "":
|
|
101
191
|
case "record": {
|
|
102
192
|
await toggle(ctx);
|
|
103
193
|
return;
|
|
104
194
|
}
|
|
105
|
-
|
|
106
195
|
case "cancel": {
|
|
107
|
-
if (!
|
|
108
|
-
|
|
109
|
-
|
|
196
|
+
if (!recording) return;
|
|
197
|
+
const active = recording;
|
|
198
|
+
recording = undefined;
|
|
199
|
+
await active.recorder.cancel();
|
|
200
|
+
showStatus(ctx.ui, active.settings);
|
|
110
201
|
ctx.ui.notify("Recording discarded");
|
|
111
202
|
return;
|
|
112
203
|
}
|
|
204
|
+
case "setup": {
|
|
205
|
+
await setup(ctx);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
113
209
|
|
|
210
|
+
const { settings } = configuration;
|
|
211
|
+
if (!settings) {
|
|
212
|
+
ctx.ui.notify(setupMessage(), configuration.errors.length > 0 ? "warning" : "info");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
switch (command) {
|
|
114
216
|
case "device": {
|
|
115
|
-
if (
|
|
217
|
+
if (recording) {
|
|
116
218
|
ctx.ui.notify("Stop recording before changing the input", "warning");
|
|
117
219
|
return;
|
|
118
220
|
}
|
|
119
|
-
const
|
|
120
|
-
const selected = await ctx.ui.select("Voice input device", [
|
|
121
|
-
"System default",
|
|
122
|
-
...devices.map((device) => device.name),
|
|
123
|
-
]);
|
|
221
|
+
const selected = await promptInputDevice(ctx.ui, settings.inputDevice);
|
|
124
222
|
if (selected == null) return;
|
|
125
|
-
settings.inputDevice =
|
|
126
|
-
|
|
127
|
-
showStatus(ctx.ui);
|
|
128
|
-
ctx.ui.notify(`Voice input: ${selected}`);
|
|
223
|
+
settings.inputDevice = selected.inputDevice;
|
|
224
|
+
save(settings);
|
|
225
|
+
showStatus(ctx.ui, settings);
|
|
226
|
+
ctx.ui.notify(`Voice input: ${selected.inputDevice?.name ?? "system default"}`);
|
|
129
227
|
return;
|
|
130
228
|
}
|
|
131
229
|
|
|
132
230
|
case "profile": {
|
|
133
|
-
if (!settings.profiles) {
|
|
134
|
-
ctx.ui.notify("No profiles yet; run /voice profile add", "warning");
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
231
|
const selected = await ctx.ui.select(
|
|
138
232
|
"Voice transcription profile",
|
|
139
233
|
Object.keys(settings.profiles),
|
|
140
234
|
);
|
|
141
235
|
if (selected == null) return;
|
|
142
236
|
settings.activeProfile = selected;
|
|
143
|
-
|
|
144
|
-
showStatus(ctx.ui);
|
|
237
|
+
save(settings);
|
|
238
|
+
showStatus(ctx.ui, settings);
|
|
145
239
|
ctx.ui.notify(`Voice profile: ${selected}`);
|
|
146
240
|
return;
|
|
147
241
|
}
|
|
148
242
|
|
|
149
243
|
case "profile add": {
|
|
150
|
-
const added = await promptProfile(ctx.ui, Object.keys(settings.profiles
|
|
244
|
+
const added = await promptProfile(ctx.ui, Object.keys(settings.profiles));
|
|
151
245
|
if (!added) return;
|
|
152
246
|
settings.profiles = { ...settings.profiles, [added.name]: added.profile };
|
|
153
247
|
settings.activeProfile = added.name;
|
|
154
|
-
|
|
155
|
-
showStatus(ctx.ui);
|
|
248
|
+
save(settings);
|
|
249
|
+
showStatus(ctx.ui, settings);
|
|
156
250
|
ctx.ui.notify(`Voice profile: ${added.name}`);
|
|
157
251
|
return;
|
|
158
252
|
}
|
|
@@ -165,26 +259,22 @@ export default function voice(pi: ExtensionAPI) {
|
|
|
165
259
|
: await pickLocalModel(ctx.ui);
|
|
166
260
|
if (!model) return;
|
|
167
261
|
transcription.model = model;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
settings.activeProfile = name;
|
|
171
|
-
saveVoiceSettings(path, settings);
|
|
172
|
-
showStatus(ctx.ui);
|
|
262
|
+
save(settings);
|
|
263
|
+
showStatus(ctx.ui, settings);
|
|
173
264
|
ctx.ui.notify(`Voice profile ${name}: ${model}`);
|
|
174
265
|
return;
|
|
175
266
|
}
|
|
176
267
|
|
|
177
268
|
case "doctor": {
|
|
178
269
|
const checks = await runDoctor(settings);
|
|
179
|
-
|
|
180
|
-
ok ? `✓ ${id}: ${detail}` : `✗ ${id}: ${detail} → ${DOCTOR_FIXES[id] ?? fix}`,
|
|
181
|
-
);
|
|
182
|
-
ctx.ui.notify(lines.join("\n"), checks.every(({ ok }) => ok) ? "info" : "warning");
|
|
270
|
+
ctx.ui.notify(formatChecks(checks), checks.every(({ ok }) => ok) ? "info" : "warning");
|
|
183
271
|
return;
|
|
184
272
|
}
|
|
185
273
|
|
|
186
274
|
case "status": {
|
|
187
|
-
ctx.ui.notify(
|
|
275
|
+
ctx.ui.notify(
|
|
276
|
+
statusText(recording?.settings ?? settings, recording ? "● recording" : "idle"),
|
|
277
|
+
);
|
|
188
278
|
return;
|
|
189
279
|
}
|
|
190
280
|
|
|
@@ -199,10 +289,18 @@ export default function voice(pi: ExtensionAPI) {
|
|
|
199
289
|
});
|
|
200
290
|
|
|
201
291
|
pi.on("session_start", (_event, ctx) => {
|
|
202
|
-
|
|
292
|
+
const { settings, errors } = configuration;
|
|
293
|
+
if (settings) {
|
|
294
|
+
showStatus(ctx.ui, settings);
|
|
295
|
+
} else {
|
|
296
|
+
ctx.ui.setStatus("voice", "[voice] needs setup · /voice setup");
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (errors.length > 0) ctx.ui.notify(setupMessage(), "warning");
|
|
203
300
|
});
|
|
204
301
|
|
|
205
|
-
pi.on("session_shutdown", () => {
|
|
206
|
-
|
|
302
|
+
pi.on("session_shutdown", async () => {
|
|
303
|
+
recording = undefined;
|
|
304
|
+
await recorder?.cancel();
|
|
207
305
|
});
|
|
208
306
|
}
|
package/src/profile.ts
CHANGED
|
@@ -24,11 +24,13 @@ function download(ui: ExtensionUIContext, name: string): Promise<string> {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Pick an installed GGUF model or download one from the catalog.
|
|
29
|
+
*/
|
|
28
30
|
export async function pickLocalModel(ui: ExtensionUIContext): Promise<string | undefined> {
|
|
29
31
|
const models = listLocalModels();
|
|
30
32
|
const picked = await ui.select(
|
|
31
|
-
"
|
|
33
|
+
"Local GGUF model",
|
|
32
34
|
models.map((model) => label(model)),
|
|
33
35
|
);
|
|
34
36
|
const model = models.find((candidate) => label(candidate) === picked);
|
|
@@ -64,7 +66,9 @@ async function promptApi(ui: ExtensionUIContext): Promise<TranscriptionProfile |
|
|
|
64
66
|
};
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Ask for a profile name and transcription settings. Cancellation returns undefined.
|
|
71
|
+
*/
|
|
68
72
|
export async function promptProfile(
|
|
69
73
|
ui: ExtensionUIContext,
|
|
70
74
|
existing: readonly string[],
|
package/src/setup.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { listInputDevices, type InputDevice, type VoiceSettings } from "@luxass/agent-voice";
|
|
3
|
+
|
|
4
|
+
import { promptProfile } from "./profile";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An undefined result means cancellation, not selection of the system default.
|
|
8
|
+
*/
|
|
9
|
+
export async function promptInputDevice(
|
|
10
|
+
ui: ExtensionUIContext,
|
|
11
|
+
current?: InputDevice,
|
|
12
|
+
): Promise<{ inputDevice: InputDevice | undefined } | undefined> {
|
|
13
|
+
const keep = current == null ? undefined : `Keep ${current.name}`;
|
|
14
|
+
const selected = await ui.select("Voice input", [
|
|
15
|
+
...(keep == null ? [] : [keep]),
|
|
16
|
+
"System default",
|
|
17
|
+
"Choose input device",
|
|
18
|
+
]);
|
|
19
|
+
if (selected == null) return undefined;
|
|
20
|
+
if (selected === keep) return { inputDevice: current };
|
|
21
|
+
if (selected === "System default") return { inputDevice: undefined };
|
|
22
|
+
|
|
23
|
+
const devices = await listInputDevices();
|
|
24
|
+
const picked = await ui.select(
|
|
25
|
+
"Voice input device",
|
|
26
|
+
devices.map(({ name, id }) => `${name} · ${id}`),
|
|
27
|
+
);
|
|
28
|
+
const inputDevice = devices.find(({ name, id }) => `${name} · ${id}` === picked);
|
|
29
|
+
return inputDevice == null ? undefined : { inputDevice };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Collect a setup draft. The caller checks and saves it after every dialog completes.
|
|
34
|
+
*/
|
|
35
|
+
export async function promptSetup(
|
|
36
|
+
ui: ExtensionUIContext,
|
|
37
|
+
settings?: VoiceSettings,
|
|
38
|
+
): Promise<VoiceSettings | undefined> {
|
|
39
|
+
const profiles = settings?.profiles ?? {};
|
|
40
|
+
const existing = Object.keys(profiles);
|
|
41
|
+
let activeProfile: string;
|
|
42
|
+
let nextProfiles = profiles;
|
|
43
|
+
const selected =
|
|
44
|
+
existing.length === 0
|
|
45
|
+
? "Create new profile"
|
|
46
|
+
: await ui.select("Voice transcription", [
|
|
47
|
+
...existing.map((name) => `Use ${name}`),
|
|
48
|
+
"Create new profile",
|
|
49
|
+
]);
|
|
50
|
+
if (selected == null) return undefined;
|
|
51
|
+
if (selected === "Create new profile") {
|
|
52
|
+
const added = await promptProfile(ui, existing);
|
|
53
|
+
if (added == null) return undefined;
|
|
54
|
+
activeProfile = added.name;
|
|
55
|
+
nextProfiles = { ...profiles, [added.name]: added.profile };
|
|
56
|
+
} else {
|
|
57
|
+
activeProfile = selected.slice("Use ".length);
|
|
58
|
+
}
|
|
59
|
+
const input = await promptInputDevice(ui, settings?.inputDevice);
|
|
60
|
+
return input == null
|
|
61
|
+
? undefined
|
|
62
|
+
: {
|
|
63
|
+
...settings,
|
|
64
|
+
activeProfile,
|
|
65
|
+
profiles: nextProfiles,
|
|
66
|
+
inputDevice: input.inputDevice,
|
|
67
|
+
};
|
|
68
|
+
}
|