@illuminis/comprism 2.13.0 → 2.14.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.
|
@@ -67,14 +67,22 @@ const node_child_process_1 = require("node:child_process");
|
|
|
67
67
|
const fs = __importStar(require("node:fs"));
|
|
68
68
|
const os = __importStar(require("node:os"));
|
|
69
69
|
const path = __importStar(require("node:path"));
|
|
70
|
-
/**
|
|
71
|
-
|
|
70
|
+
/** Where this program is: on the PATH, or in Homebrew's folders. An editor
|
|
71
|
+
* opened from the Dock has no Homebrew on its PATH, and sox or ffmpeg there
|
|
72
|
+
* would otherwise look missing. */
|
|
73
|
+
function locate(command) {
|
|
72
74
|
try {
|
|
73
|
-
|
|
75
|
+
const found = (0, node_child_process_1.spawnSync)('which', [command], { encoding: 'utf8' });
|
|
76
|
+
if (found.status === 0 && found.stdout.trim())
|
|
77
|
+
return found.stdout.trim();
|
|
74
78
|
}
|
|
75
|
-
catch {
|
|
76
|
-
|
|
79
|
+
catch { /* no which */ }
|
|
80
|
+
for (const dir of ['/opt/homebrew/bin', '/usr/local/bin']) {
|
|
81
|
+
const at = path.join(dir, command);
|
|
82
|
+
if (fs.existsSync(at))
|
|
83
|
+
return at;
|
|
77
84
|
}
|
|
85
|
+
return null;
|
|
78
86
|
}
|
|
79
87
|
/**
|
|
80
88
|
* Sixteen kilohertz, one channel, everywhere.
|
|
@@ -112,7 +120,15 @@ const RECORDERS = [
|
|
|
112
120
|
function builtInReader() {
|
|
113
121
|
if (process.platform !== 'darwin')
|
|
114
122
|
return null;
|
|
115
|
-
for (const at of [
|
|
123
|
+
for (const at of [
|
|
124
|
+
// Unbundled, run from its own compiled location (the CLI): two levels up
|
|
125
|
+
// to the build's out/ folder, where native/ sits beside machine/.
|
|
126
|
+
path.join(__dirname, '..', '..', 'native', 'dictate'),
|
|
127
|
+
path.join(__dirname, '..', 'native', 'dictate'),
|
|
128
|
+
// Bundled into one file (the VS Code extension's dist/line.js): native/
|
|
129
|
+
// is copied beside the bundle itself, in the same directory.
|
|
130
|
+
path.join(__dirname, 'native', 'dictate'),
|
|
131
|
+
]) {
|
|
116
132
|
if (fs.existsSync(at))
|
|
117
133
|
return at;
|
|
118
134
|
}
|
|
@@ -120,7 +136,12 @@ function builtInReader() {
|
|
|
120
136
|
}
|
|
121
137
|
/** The first recording tool this machine has, or null. */
|
|
122
138
|
function recorder() {
|
|
123
|
-
|
|
139
|
+
for (const r of RECORDERS) {
|
|
140
|
+
const at = locate(r.command);
|
|
141
|
+
if (at)
|
|
142
|
+
return { ...r, command: at };
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
124
145
|
}
|
|
125
146
|
/**
|
|
126
147
|
* What to tell somebody who has no recording tool, or null when they do.
|
|
@@ -145,13 +166,36 @@ function missing() {
|
|
|
145
166
|
* headed off with `missing` so the person gets a sentence rather than an error.
|
|
146
167
|
*/
|
|
147
168
|
function start() {
|
|
169
|
+
// A recording tool on this computer first, as it always was; the reader in
|
|
170
|
+
// the package when there is none, so a person installs nothing to speak.
|
|
148
171
|
const tool = recorder();
|
|
149
|
-
|
|
172
|
+
const reader = tool ? null : builtInReader();
|
|
173
|
+
if (!reader && !tool)
|
|
150
174
|
throw new Error(missing() ?? 'No recording tool.');
|
|
151
175
|
const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'comprism-voice-')), 'said.wav');
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
176
|
+
let child;
|
|
177
|
+
if (reader) {
|
|
178
|
+
// The reader writes bare samples; the file gets the WAV header the other
|
|
179
|
+
// tools write, with its lengths filled in when the recording ends.
|
|
180
|
+
fs.writeFileSync(file, wavHeader(0));
|
|
181
|
+
child = (0, node_child_process_1.spawn)(reader, ['--raw', RATE], { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
182
|
+
child.stdout?.on('data', (chunk) => { try {
|
|
183
|
+
fs.appendFileSync(file, chunk);
|
|
184
|
+
}
|
|
185
|
+
catch { /* discarded */ } });
|
|
186
|
+
child.once('close', () => {
|
|
187
|
+
try {
|
|
188
|
+
const size = fs.statSync(file).size;
|
|
189
|
+
const fd = fs.openSync(file, 'r+');
|
|
190
|
+
fs.writeSync(fd, wavHeader(size - 44), 0, 44, 0);
|
|
191
|
+
fs.closeSync(fd);
|
|
192
|
+
}
|
|
193
|
+
catch { /* discarded before it finished */ }
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
child = (0, node_child_process_1.spawn)(tool.command, tool.args(file), { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
198
|
+
}
|
|
155
199
|
let stopped = null;
|
|
156
200
|
// The recorder never outlives the session. Closing the window or ending the
|
|
157
201
|
// process while it listens would otherwise leave a microphone recording to a
|
|
@@ -214,7 +258,26 @@ function start() {
|
|
|
214
258
|
});
|
|
215
259
|
return stopped;
|
|
216
260
|
};
|
|
217
|
-
return { file, by: tool.name, stop };
|
|
261
|
+
return { file, by: reader ? 'built in microphone reader' : tool.name, stop };
|
|
262
|
+
}
|
|
263
|
+
/** A 44 byte WAV header for 16 bit, one channel samples at RATE. */
|
|
264
|
+
function wavHeader(dataBytes) {
|
|
265
|
+
const rate = Number(RATE);
|
|
266
|
+
const h = Buffer.alloc(44);
|
|
267
|
+
h.write('RIFF', 0, 'ascii');
|
|
268
|
+
h.writeUInt32LE(36 + dataBytes, 4);
|
|
269
|
+
h.write('WAVE', 8, 'ascii');
|
|
270
|
+
h.write('fmt ', 12, 'ascii');
|
|
271
|
+
h.writeUInt32LE(16, 16);
|
|
272
|
+
h.writeUInt16LE(1, 20);
|
|
273
|
+
h.writeUInt16LE(1, 22);
|
|
274
|
+
h.writeUInt32LE(rate, 24);
|
|
275
|
+
h.writeUInt32LE(rate * 2, 28);
|
|
276
|
+
h.writeUInt16LE(2, 32);
|
|
277
|
+
h.writeUInt16LE(16, 34);
|
|
278
|
+
h.write('data', 36, 'ascii');
|
|
279
|
+
h.writeUInt32LE(dataBytes, 40);
|
|
280
|
+
return h;
|
|
218
281
|
}
|
|
219
282
|
/** Delete the recording and the folder holding it. Always, and immediately. */
|
|
220
283
|
function discard(file) {
|
package/out/server.generated.js
CHANGED
|
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BUILD_COMMIT = exports.HOME_SERVER = void 0;
|
|
4
4
|
// Written by the build. Do not edit.
|
|
5
5
|
exports.HOME_SERVER = "https://completionprism.illuminis.ai";
|
|
6
|
-
exports.BUILD_COMMIT = "
|
|
6
|
+
exports.BUILD_COMMIT = "ed53bf43b2053157d9877d948e9d3cf75fc4828f";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@illuminis/comprism",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "CompletionPrism in your terminal. A thin shell: what you type goes to CompletionPrism's front door, and what it answers comes back.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|