dsh-folia 4.26.0-pre.18 → 4.26.0-pre.19

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/client.js CHANGED
@@ -20822,6 +20822,7 @@ window.__ModuleLoader__.load({
20822
20822
  const map = {
20823
20823
  'no-device': '没找到麦克风,先打字吧',
20824
20824
  'ffmpeg-missing': '缺少 ffmpeg,先打字吧',
20825
+ 'unsupported-platform': '这个系统不支持桌面录音,用浏览器打开 DSH 才能语音',
20825
20826
  'asr-not-ready': '语音模型还没下载,我来准备一下…',
20826
20827
  timeout: '这次没听清,再说一次或直接打字',
20827
20828
  'no-speech': '没听到声音,再说一次或直接打字',
@@ -860,7 +860,8 @@ export function registerPetChatRoutes(webServer, c) {
860
860
  };
861
861
  if (!result.ok) {
862
862
  const hints = {
863
- 'no-device': '没找到麦克风(检查系统录音设备)',
863
+ 'no-device': '没找到可用麦克风(检查系统录音设备或是否被其它程序占用)',
864
+ 'unsupported-platform': '这个系统不支持桌面录音,用浏览器打开 DSH 才能语音',
864
865
  'ffmpeg-missing': '缺少 ffmpeg,无法录音',
865
866
  timeout: '录音超时,再说一次',
866
867
  'no-speech': '没听到声音,再说一次或直接打字',
@@ -112,36 +112,51 @@ export function createVoiceRecorder(deps) {
112
112
  */
113
113
  async function record(options = {}) {
114
114
  const opts = { ...RECORD_DEFAULTS, ...options };
115
+ // 非 Windows:没有 dshow,宿主录音不可用(浏览器模式请用前端 getUserMedia 通道)
116
+ if (process.platform !== 'win32') return { ok: false, code: 'unsupported-platform' };
115
117
  let devices;
116
118
  try {
117
119
  devices = await listDevices();
118
120
  } catch {
119
121
  return { ok: false, code: 'ffmpeg-missing' };
120
122
  }
121
- const device = pickDevice(devices);
122
- if (!device) return { ok: false, code: 'no-device' };
123
-
124
- const dir = mkdtempSync(join(tmpdir(), 'folia-voice-'));
125
- const audioPath = join(dir, 'input.wav');
126
- const startedAt = Date.now();
127
- let result;
128
- try {
129
- result = await runFfmpeg(await resolveFfmpeg(null), [...dshowArgs(device, opts), audioPath], opts.maxMs + 8000);
130
- } catch {
131
- rmSync(dir, { recursive: true, force: true });
132
- return { ok: false, code: 'timeout' };
123
+ const preferred = pickDevice(devices);
124
+ if (!preferred) return { ok: false, code: 'no-device' };
125
+ // 跨机器:不同机器的第一个"像麦克风"的设备不一定真能开(被占用/驱动不同)
126
+ // ⇒ 依次尝试最多 3 个音频设备,任一成功即返回。
127
+ const candidates = [preferred, ...devices.filter((d) => d !== preferred)].slice(0, 3);
128
+ let lastCode = 'no-speech';
129
+ for (const device of candidates) {
130
+ const dir = mkdtempSync(join(tmpdir(), 'folia-voice-'));
131
+ const audioPath = join(dir, 'input.wav');
132
+ const startedAt = Date.now();
133
+ let result = null;
134
+ try {
135
+ result = await runFfmpeg(await resolveFfmpeg(null), [...dshowArgs(device, opts), audioPath], opts.maxMs + 8000);
136
+ } catch {
137
+ rmSync(dir, { recursive: true, force: true });
138
+ lastCode = 'ffmpeg-missing';
139
+ continue;
140
+ }
141
+ const ms = Date.now() - startedAt;
142
+ const stderr = String((result && result.stderr) || '');
143
+ if (result && result.code !== 0) {
144
+ // 这个设备打不开(占用/驱动)⇒ 换下一个
145
+ rmSync(dir, { recursive: true, force: true });
146
+ lastCode = 'no-device';
147
+ continue;
148
+ }
149
+ const ended = detectSpeechEnd(stderr);
150
+ if (!ended) {
151
+ rmSync(dir, { recursive: true, force: true });
152
+ lastCode = 'no-speech';
153
+ continue;
154
+ }
155
+ const size = probeSize(audioPath);
156
+ if (!size) { rmSync(dir, { recursive: true, force: true }); lastCode = 'no-speech'; continue; }
157
+ return { ok: true, audioPath, dir, ms, device, speech: ended, audioSeconds: Number((ended.speechEnd || 0).toFixed(2)) };
133
158
  }
134
- const ms = Date.now() - startedAt;
135
- const stderr = String((result && result.stderr) || '');
136
- const ended = detectSpeechEnd(stderr);
137
- if (!ended) {
138
- rmSync(dir, { recursive: true, force: true });
139
- return { ok: false, code: result && result.code !== 0 ? 'timeout' : 'no-speech' };
140
- }
141
- const size = probeSize(audioPath);
142
- if (!size) { rmSync(dir, { recursive: true, force: true }); return { ok: false, code: 'no-speech' }; }
143
- return { ok: true, audioPath, dir, ms, speech: ended, audioSeconds: Number((ended.speechEnd || 0).toFixed(2)) };
144
- }
159
+ return { ok: false, code: lastCode }; }
145
160
 
146
161
  return { listDevices, record };
147
162
  }
@@ -154,9 +169,13 @@ export async function defaultResolveFfmpeg() {
154
169
  const env = process.env.DSH_FOLIA_FFMPEG;
155
170
  if (env && env.trim()) return env.trim();
156
171
  const exe = process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg';
157
- const cached = join(process.env.USERPROFILE || process.env.HOME || '', '.dsh-folia', 'ffmpeg', exe);
158
172
  const { existsSync } = await import('node:fs');
159
- if (existsSync(cached)) return cached;
173
+ const candidates = [
174
+ join(process.env.USERPROFILE || process.env.HOME || '', '.dsh-folia', 'ffmpeg', exe),
175
+ join(process.env.APPDATA || '', 'dsh-desktop', 'ffmpeg', exe),
176
+ ];
177
+ for (const p of candidates) { if (p && existsSync(p)) return p; }
178
+ // 交给 PATH:调用方会用 spawn 试一次,ENOENT 时会明确回 ffmpeg-missing
160
179
  return exe;
161
180
  }
162
181
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
- "version": "4.26.0-pre.18",
3
+ "version": "4.26.0-pre.19",
4
4
  "description": "DSH 壁纸引擎:本机 WE 壁纸实时渲染,视频/网页/开机动画/桌宠皮肤,一键拉取在线素材。",
5
5
  "type": "module",
6
6
  "engines": {