@hxnnxs/opencode-voice 0.2.1 → 0.2.3
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/CHANGELOG.md +12 -0
- package/index.js +0 -3
- package/lib/engine.js +20 -12
- package/lib/wav.js +70 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.3 - 2026-08-17
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Repaired unfinalized WAV headers before transcription so recordings interrupted by forced recorder termination remain usable.
|
|
8
|
+
|
|
9
|
+
## 0.2.2 - 2026-08-16
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Restored the TUI-only plugin export required by OpenCode 1.18.
|
|
14
|
+
|
|
3
15
|
## 0.2.1 - 2026-08-16
|
|
4
16
|
|
|
5
17
|
### Fixed
|
package/index.js
CHANGED
|
@@ -961,9 +961,6 @@ function buildCommands(ctx) {
|
|
|
961
961
|
|
|
962
962
|
const plugin = {
|
|
963
963
|
id: PLUGIN_ID,
|
|
964
|
-
// OpenCode 1.18 validates every plugin module through its server contract,
|
|
965
|
-
// even when the plugin only contributes TUI commands.
|
|
966
|
-
server: async () => ({}),
|
|
967
964
|
tui: async (api, options = {}) => {
|
|
968
965
|
const runtime = new VoiceRuntime(options || {});
|
|
969
966
|
const ctx = {
|
package/lib/engine.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Readable, Transform } from "node:stream";
|
|
|
9
9
|
import { pipeline } from "node:stream/promises";
|
|
10
10
|
import { ensureDir, replaceFile, sha256 } from "./download.js";
|
|
11
11
|
import { getAudioDir, getCacheDir, getEnginesDir, getModelPath } from "./models.js";
|
|
12
|
+
import { repairUnfinalizedWavHeader } from "./wav.js";
|
|
12
13
|
|
|
13
14
|
const require = createRequire(import.meta.url);
|
|
14
15
|
const FFMPEG_STATIC_PACKAGE = "ffmpeg-static@^5.2.0";
|
|
@@ -714,26 +715,31 @@ function buildRecorders(file, settings = {}) {
|
|
|
714
715
|
function waitForExit(proc, timeoutMs = 3000) {
|
|
715
716
|
return new Promise((resolve) => {
|
|
716
717
|
let settled = false;
|
|
718
|
+
let timer;
|
|
717
719
|
const finish = () => {
|
|
718
720
|
if (settled) return;
|
|
719
721
|
settled = true;
|
|
722
|
+
clearTimeout(timer);
|
|
720
723
|
resolve();
|
|
721
724
|
};
|
|
722
|
-
|
|
725
|
+
|
|
726
|
+
proc.once("exit", finish);
|
|
727
|
+
proc.once("error", finish);
|
|
728
|
+
if (proc.exitCode !== null || proc.signalCode !== null) {
|
|
729
|
+
finish();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
timer = setTimeout(() => {
|
|
723
734
|
try {
|
|
724
735
|
proc.kill("SIGKILL");
|
|
725
|
-
} catch {
|
|
726
|
-
|
|
736
|
+
} catch {
|
|
737
|
+
finish();
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
// Wait for the OS to close recorder file handles before reading the WAV.
|
|
741
|
+
timer = setTimeout(finish, 1000);
|
|
727
742
|
}, timeoutMs);
|
|
728
|
-
|
|
729
|
-
proc.once("exit", () => {
|
|
730
|
-
clearTimeout(timer);
|
|
731
|
-
finish();
|
|
732
|
-
});
|
|
733
|
-
proc.once("error", () => {
|
|
734
|
-
clearTimeout(timer);
|
|
735
|
-
finish();
|
|
736
|
-
});
|
|
737
743
|
});
|
|
738
744
|
}
|
|
739
745
|
|
|
@@ -896,6 +902,8 @@ export class VoiceRuntime {
|
|
|
896
902
|
throw new Error(`Model is not downloaded: ${model.name}`);
|
|
897
903
|
}
|
|
898
904
|
|
|
905
|
+
repairUnfinalizedWavHeader(audioFile);
|
|
906
|
+
|
|
899
907
|
const args = model.engine === "transcribe-cpp" ? ["--model", modelFile, "--file", audioFile] : ["-m", modelFile, "-f", audioFile, "-np", "-nt"];
|
|
900
908
|
if (settings.language && settings.language !== "auto") args.push(model.engine === "transcribe-cpp" ? "--language" : "-l", settings.language);
|
|
901
909
|
|
package/lib/wav.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
const RIFF_HEADER_BYTES = 12;
|
|
4
|
+
const CHUNK_HEADER_BYTES = 8;
|
|
5
|
+
const UINT32_MAX = 0xffffffff;
|
|
6
|
+
|
|
7
|
+
function readExactly(fd, buffer, position) {
|
|
8
|
+
return fs.readSync(fd, buffer, 0, buffer.length, position) === buffer.length;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function repairUnfinalizedWavHeader(file) {
|
|
12
|
+
let fd;
|
|
13
|
+
try {
|
|
14
|
+
fd = fs.openSync(file, "r+");
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const fileSize = fs.fstatSync(fd).size;
|
|
21
|
+
if (fileSize < RIFF_HEADER_BYTES || fileSize - 8 > UINT32_MAX) return false;
|
|
22
|
+
|
|
23
|
+
const riffHeader = Buffer.alloc(RIFF_HEADER_BYTES);
|
|
24
|
+
if (!readExactly(fd, riffHeader, 0)) return false;
|
|
25
|
+
if (riffHeader.toString("ascii", 0, 4) !== "RIFF" || riffHeader.toString("ascii", 8, 12) !== "WAVE") return false;
|
|
26
|
+
|
|
27
|
+
const declaredRiffSize = riffHeader.readUInt32LE(4);
|
|
28
|
+
let chunkOffset = RIFF_HEADER_BYTES;
|
|
29
|
+
|
|
30
|
+
while (chunkOffset + CHUNK_HEADER_BYTES <= fileSize) {
|
|
31
|
+
const chunkHeader = Buffer.alloc(CHUNK_HEADER_BYTES);
|
|
32
|
+
if (!readExactly(fd, chunkHeader, chunkOffset)) return false;
|
|
33
|
+
|
|
34
|
+
const chunkId = chunkHeader.toString("ascii", 0, 4);
|
|
35
|
+
const declaredChunkSize = chunkHeader.readUInt32LE(4);
|
|
36
|
+
const chunkDataOffset = chunkOffset + CHUNK_HEADER_BYTES;
|
|
37
|
+
|
|
38
|
+
if (chunkId === "data") {
|
|
39
|
+
const availableDataSize = fileSize - chunkDataOffset;
|
|
40
|
+
const repairRiffSize = declaredRiffSize > fileSize - 8;
|
|
41
|
+
const repairDataSize = declaredChunkSize > availableDataSize;
|
|
42
|
+
if (!repairRiffSize && !repairDataSize) return false;
|
|
43
|
+
|
|
44
|
+
const size = Buffer.alloc(4);
|
|
45
|
+
if (repairDataSize) {
|
|
46
|
+
size.writeUInt32LE(availableDataSize);
|
|
47
|
+
fs.writeSync(fd, size, 0, size.length, chunkOffset + 4);
|
|
48
|
+
}
|
|
49
|
+
if (repairRiffSize) {
|
|
50
|
+
size.writeUInt32LE(fileSize - 8);
|
|
51
|
+
fs.writeSync(fd, size, 0, size.length, 4);
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const paddedChunkSize = declaredChunkSize + (declaredChunkSize % 2);
|
|
57
|
+
const nextChunkOffset = chunkDataOffset + paddedChunkSize;
|
|
58
|
+
if (nextChunkOffset > fileSize) return false;
|
|
59
|
+
chunkOffset = nextChunkOffset;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false;
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
} finally {
|
|
66
|
+
try {
|
|
67
|
+
fs.closeSync(fd);
|
|
68
|
+
} catch {}
|
|
69
|
+
}
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hxnnxs/opencode-voice",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Local voice input plugin for OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"LICENSE"
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
|
-
"check": "node --check index.js && node --check lib/models.js && node --check lib/handy-model-catalog.js && node --check lib/download.js && node --check lib/engine.js && node --check lib/engines.js && node --check bin/opencode-voice.js && node --check scripts/package-engine-asset.mjs && node --check scripts/build-engine-registry.mjs && node --check scripts/update-handy-model-catalog.mjs",
|
|
45
|
+
"check": "node --check index.js && node --check lib/models.js && node --check lib/handy-model-catalog.js && node --check lib/download.js && node --check lib/engine.js && node --check lib/engines.js && node --check lib/wav.js && node --check bin/opencode-voice.js && node --check scripts/package-engine-asset.mjs && node --check scripts/build-engine-registry.mjs && node --check scripts/update-handy-model-catalog.mjs && npm test",
|
|
46
|
+
"test": "node --test",
|
|
46
47
|
"update-handy-model-catalog": "node scripts/update-handy-model-catalog.mjs",
|
|
47
48
|
"prepack": "npm run check"
|
|
48
49
|
},
|