dsh-folia 4.26.0-pre.21 → 4.26.0-pre.22
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/lib/voice/record.js +15 -2
- package/package.json +1 -1
package/lib/voice/record.js
CHANGED
|
@@ -131,8 +131,19 @@ export function createVoiceRecorder(deps) {
|
|
|
131
131
|
const audioPath = join(dir, 'input.wav');
|
|
132
132
|
const startedAt = Date.now();
|
|
133
133
|
let result = null;
|
|
134
|
+
let usedPlain = false;
|
|
134
135
|
try {
|
|
135
|
-
|
|
136
|
+
const ff = await resolveFfmpeg(null);
|
|
137
|
+
result = await runFfmpeg(ff, [...dshowArgs(device, opts), audioPath], opts.maxMs + 8000);
|
|
138
|
+
// 兜底:某些环境(实测 dsh web / Electron 主进程)里 ffmpeg 不接受 -af silencedetect,
|
|
139
|
+
// 会立刻非零退出。这时退化成"固定时长采集":宁可少一点智能,也不能录不到。
|
|
140
|
+
if (result && result.code !== 0) {
|
|
141
|
+
const args = dshowArgs(device, opts);
|
|
142
|
+
const cut = args.indexOf('-af');
|
|
143
|
+
const plain = cut >= 0 ? args.slice(0, cut).concat(args.slice(cut + 2)) : args;
|
|
144
|
+
const retry = await runFfmpeg(ff, [...plain, audioPath], opts.maxMs + 8000);
|
|
145
|
+
if (retry && retry.code === 0) { result = retry; usedPlain = true; }
|
|
146
|
+
}
|
|
136
147
|
} catch {
|
|
137
148
|
rmSync(dir, { recursive: true, force: true });
|
|
138
149
|
lastCode = 'ffmpeg-missing';
|
|
@@ -146,7 +157,9 @@ export function createVoiceRecorder(deps) {
|
|
|
146
157
|
lastCode = 'no-device';
|
|
147
158
|
continue;
|
|
148
159
|
}
|
|
149
|
-
|
|
160
|
+
let ended = detectSpeechEnd(stderr);
|
|
161
|
+
// 固定时长兜底采集里没有 silencedetect 标记 ⇒ 直接按 maxMs 当语音段,别误判成 no-speech
|
|
162
|
+
if (!ended && usedPlain) ended = { speechEnd: opts.maxMs / 1000 };
|
|
150
163
|
if (!ended) {
|
|
151
164
|
rmSync(dir, { recursive: true, force: true });
|
|
152
165
|
lastCode = 'no-speech';
|