dsh-line-bot 0.10.7 → 0.10.9

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.10.9
2
+
3
+ - 上傳或重設參考音後立即清掉語音偵測快取,面板不會再顯示上一段參考音的秒數。
4
+
5
+ ## 0.10.8
6
+
7
+ - 上傳自訂參考音後自動去掉開頭靜音並裁切到前 15 秒。13 分鐘的錄音整段丟給 CosyVoice3 會讓語音合成卡住;現在只保留一小段乾淨人聲,上傳後可直接測試。
8
+
1
9
  ## 0.10.7
2
10
 
3
11
  - 修正自訂參考音無法上傳:`/api/line-bot/action` 的請求上限從 2MB 提高到 32MB。20MB 音檔轉成 data URL 後約 27MB,先前會在面板顯示「上傳失敗:請求內容過大」。
package/client.js CHANGED
@@ -1428,7 +1428,7 @@ window.__ModuleLoader__.load({
1428
1428
  h(Btn, { onClick: () => voiceInputRef.current && voiceInputRef.current.click(), disabled: !!busy }, '上傳參考音'),
1429
1429
  h('input', { ref: voiceInputRef, type: 'file', accept: 'audio/*', style: { display: 'none' }, onChange: uploadVoice }),
1430
1430
  ),
1431
- h('div', { style: S.hint }, '目前參考音:' + (voiceStatus.reference?.path || '(尚未設定,預設會用插件內建的 12–16 秒片段)')),
1431
+ h('div', { style: S.hint }, '目前參考音:' + (voiceStatus.reference?.path || '(尚未設定,預設會用插件內建的 12–16 秒片段)') + '(上傳後會自動去開頭靜音並裁到前 15 秒)'),
1432
1432
  voiceStatus.reference?.path ? h('div', { style: S.row }, h(Btn, { onClick: resetVoiceReference, disabled: !!busy }, '改用內建預設參考音')) : null,
1433
1433
  h('div', { style: S.grid },
1434
1434
  h(Field, { label: '引擎', hint: 'auto 會依系統自動挑選' }, h('select', { value: voiceCfg.provider || 'auto', onChange: (event) => update({ voice: { provider: event.target.value } }), style: S.input }, ['auto', 'mlx', 'gguf'].map((item) => h('option', { key: item, value: item }, item)))),
package/lib/host.mjs CHANGED
@@ -51,7 +51,7 @@ const { createVision } = visionMod
51
51
  const { createTts } = ttsMod
52
52
  const { chunkText, clip, inQuietWindow, jsonFail, jsonOk, maskSecret, readJsonBody, safeArray, sleep, readJsonSafe } = utilMod
53
53
 
54
- export const VERSION = '0.10.7'
54
+ export const VERSION = '0.10.9'
55
55
 
56
56
  // 環境變數提供的 Cloudflare API Token(方便用 shell 注入、不用把 token 寫進設定檔)。
57
57
  // 設定檔裡的 token 優先;兩者都沒有時才用環境變數。
@@ -2866,11 +2866,13 @@ export async function create({ ctx, config: pluginConfig, logger: upstream }) {
2866
2866
  if (buffer.length > 20 * 1024 * 1024) throw new Error('音檔超過 20MB')
2867
2867
  const saved = await tts.saveReferenceBuffer(buffer, String(payload.filename || 'reference'), String(payload.ext || '.wav'))
2868
2868
  store.patch({ voice: { referencePath: saved.path } }, { silent: true })
2869
+ tts.invalidate()
2869
2870
  voiceCache = { at: 0, value: null }
2870
2871
  return { path: saved.path, seconds: saved.seconds }
2871
2872
  }
2872
2873
  case 'voice-reset-reference':
2873
2874
  store.patch({ voice: { referencePath: '' } }, { silent: true })
2875
+ tts.invalidate()
2874
2876
  voiceCache = { at: 0, value: null }
2875
2877
  return { path: tts.referencePath() }
2876
2878
  case 'meme-send': {
package/lib/tts.mjs CHANGED
@@ -279,6 +279,11 @@ export function createTts({ dir, logger, getConfig }) {
279
279
  return crispVersion(bin).ok
280
280
  }
281
281
 
282
+ function invalidate() {
283
+ detectCache = { at: 0, value: null }
284
+ refCache = { at: 0, key: '', value: null }
285
+ }
286
+
282
287
  function detect({ force = false, validate = false } = {}) {
283
288
  const now = Date.now()
284
289
  if (!force && !validate && detectCache.value && now - detectCache.at < 120000) return detectCache.value
@@ -619,8 +624,19 @@ export function createTts({ dir, logger, getConfig }) {
619
624
  const ffmpeg = which('ffmpeg')
620
625
  if (!ffmpeg) throw new Error('需要 ffmpeg 才能轉換音檔')
621
626
  const dest = path.join(paths.refDir, `upload-${Date.now()}.wav`)
622
- await run(ffmpeg, ['-hide_banner', '-loglevel', 'error', '-y', '-i', src, '-ac', '1', '-ar', '16000', '-c:a', 'pcm_s16le', dest], { timeout: 120000 })
627
+ // 語音克隆只需要一小段乾淨的人聲;整段 10 幾分鐘的錄音會讓模型合成卡死。
628
+ // 先去掉開頭靜音,再取前 15 秒(失敗時退回單純截前 15 秒)。
629
+ const trimArgs = ['-hide_banner', '-loglevel', 'error', '-y', '-i', src,
630
+ '-af', 'silenceremove=start_periods=1:start_duration=0.2:start_threshold=-40dB,atrim=0:15,asetpts=N/SR/TB',
631
+ '-ac', '1', '-ar', '16000', '-c:a', 'pcm_s16le', dest]
632
+ try {
633
+ await run(ffmpeg, trimArgs, { timeout: 120000 })
634
+ if (referenceInfoFor(dest).seconds < 1) throw new Error('裁切後沒有聲音')
635
+ } catch {
636
+ await run(ffmpeg, ['-hide_banner', '-loglevel', 'error', '-y', '-i', src, '-t', '15', '-ac', '1', '-ar', '16000', '-c:a', 'pcm_s16le', dest], { timeout: 120000 })
637
+ }
623
638
  const info = referenceInfoFor(dest)
639
+ try { fs.unlinkSync(src) } catch { /* 原始上傳檔可留可不留 */ }
624
640
  return { path: dest, ...info }
625
641
  }
626
642
 
@@ -657,5 +673,5 @@ export function createTts({ dir, logger, getConfig }) {
657
673
  }
658
674
  }
659
675
 
660
- return { detect, install, synthesize, status, saveReferenceBuffer, referencePath, paths }
676
+ return { detect, invalidate, install, synthesize, status, saveReferenceBuffer, referencePath, paths }
661
677
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-line-bot",
3
- "version": "0.10.7",
3
+ "version": "0.10.9",
4
4
  "description": "把 LINE 官方帳號(Messaging API)接進 DeepSeek Harness 的插件:內建 Cloudflare Tunnel、人設選擇(大肥魚或插件自訂)、主動傳訊與完整設定面板。",
5
5
  "type": "module",
6
6
  "main": "index.js",