dsh-folia 4.26.0-pre.55 → 4.26.0-pre.56
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 +14 -0
- package/package.json +1 -1
package/lib/voice/record.js
CHANGED
|
@@ -119,6 +119,14 @@ export function detectAutoStop(stderr, options = {}) {
|
|
|
119
119
|
/** 生成 dshow 输入参数(Windows);其它平台没有 dshow,直接报 no-device。 */
|
|
120
120
|
export function dshowArgs(device, options = {}) {
|
|
121
121
|
const opts = { ...RECORD_DEFAULTS, ...options };
|
|
122
|
+
// 路由会把没传的参数显式传成 undefined:
|
|
123
|
+
// { ...DEFAULTS, ...{ maxMs: undefined } } 会把默认值覆盖成 undefined,
|
|
124
|
+
// 接着 timeoutMs = NaN ⇒ setTimeout(NaN) 立刻触发 ⇒ /record 0.2s 就回“录音超时”。
|
|
125
|
+
// 这里逐项兜底成默认值(0 是合法值,只认真正的非数字)。
|
|
126
|
+
for (const key of ['maxMs', 'silenceDb', 'silenceMs', 'sampleRate']) {
|
|
127
|
+
const n = Number(opts[key]);
|
|
128
|
+
if (!Number.isFinite(n) || n <= 0) opts[key] = RECORD_DEFAULTS[key];
|
|
129
|
+
}
|
|
122
130
|
return [
|
|
123
131
|
'-hide_banner', '-y',
|
|
124
132
|
'-f', 'dshow', '-i', `audio=${device}`,
|
|
@@ -144,6 +152,12 @@ export function createVoiceRecorder(deps) {
|
|
|
144
152
|
*/
|
|
145
153
|
async function record(options = {}) {
|
|
146
154
|
const opts = { ...RECORD_DEFAULTS, ...options };
|
|
155
|
+
|
|
156
|
+
// route passes explicit undefined: overrides defaults -> timeout NaN -> instant timeout
|
|
157
|
+
for (const key of ['maxMs', 'silenceDb', 'silenceMs', 'sampleRate']) {
|
|
158
|
+
const n = Number(opts[key]);
|
|
159
|
+
if (!Number.isFinite(n) || n <= 0) opts[key] = RECORD_DEFAULTS[key];
|
|
160
|
+
}
|
|
147
161
|
// 非 Windows:没有 dshow,宿主录音不可用(浏览器模式请用前端 getUserMedia 通道)
|
|
148
162
|
if (process.platform !== 'win32') return { ok: false, code: 'unsupported-platform' };
|
|
149
163
|
let devices;
|