dsh-laivox-tts 0.7.23 → 0.7.24

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/README.en.md CHANGED
@@ -38,7 +38,7 @@ This installs the prebuilt package from npm—nothing is compiled locally and no
38
38
 
39
39
  ### Install from GitHub Release or offline package
40
40
 
41
- If npm is unavailable or you prefer pinning a release tarball, install via URL or download `dsh-laivox-tts.tgz` from [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) (replace `latest/download` with `download/v0.7.23` to pin a version):
41
+ If npm is unavailable or you prefer pinning a release tarball, install via URL or download `dsh-laivox-tts.tgz` from [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) (replace `latest/download` with `download/v0.7.24` to pin a version):
42
42
 
43
43
  ```sh
44
44
  dsh plugin --profile desktop add "https://github.com/xiaolai181/dsh_laivox_tts/releases/latest/download/dsh-laivox-tts.tgz"
package/README.md CHANGED
@@ -40,7 +40,7 @@ dsh plugin --profile desktop add dsh-laivox-tts
40
40
 
41
41
  ### GitHub Release 链接或离线安装包安装
42
42
 
43
- 如需锁定版本或无法直连 npm,可使用 Release 下载链接(将 `latest/download` 替换为 `download/v0.7.23` 可锁定版本),或从 [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) 下载 `dsh-laivox-tts.tgz` 到本地后安装:
43
+ 如需锁定版本或无法直连 npm,可使用 Release 下载链接(将 `latest/download` 替换为 `download/v0.7.24` 可锁定版本),或从 [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) 下载 `dsh-laivox-tts.tgz` 到本地后安装:
44
44
 
45
45
  ```sh
46
46
  dsh plugin --profile desktop add "https://github.com/xiaolai181/dsh_laivox_tts/releases/latest/download/dsh-laivox-tts.tgz"
package/lib/client.js CHANGED
@@ -4603,7 +4603,7 @@ function applySpokenParts(parts, { speakText, roles } = {}) {
4603
4603
  }
4604
4604
 
4605
4605
  // src/domain/script-lines.mjs
4606
- var EXTRACT_SCRIPT = true;
4606
+ var EXTRACT_SCRIPT = false;
4607
4607
  function removedRanges(text, removed) {
4608
4608
  const hidden = new Set(removed ?? []);
4609
4609
  return sourceLines(text).filter((line2) => hidden.has(line2.id)).map((line2) => ({ start: line2.start, end: line2.start + line2.text.length }));
@@ -5496,7 +5496,7 @@ function PlanSheet({ dialog, answer, narratorSetting, account }) {
5496
5496
  plan.aiPlan?.selection && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: modelIdentity(plan.aiPlan.selection) }),
5497
5497
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { children: [
5498
5498
  translate("\u9884\u8BA1 {requests} \u6B21\u5E38\u89C4\u8BF7\u6C42\uFF0C\u4F7F\u7528 DSH \u6A21\u578B\u989D\u5EA6\u3002", { requests: plan.estimate.requests }),
5499
- plan.estimate.cast > 0 ? translate("\u7F16\u5267\u6BCF\u6BB5\u53EF\u80FD\u518D\u9009\u89D2\u4E00\u6B21\u3001\u518D\u8865\u5199\u4E00\u6B21\uFF0C\u901A\u5E38\u4E0D\u8D85\u8FC7 {max} \u6B21\u3002", { max: plan.estimate.requests + 2 * plan.estimate.cast }) : "",
5499
+ plan.estimate.cast > 0 ? EXTRACT_SCRIPT ? translate("\u7F16\u5267\u6BCF\u6BB5\u53EF\u80FD\u518D\u9009\u89D2\u4E00\u6B21\u3001\u518D\u8865\u5199\u4E00\u6B21\uFF0C\u901A\u5E38\u4E0D\u8D85\u8FC7 {max} \u6B21\u3002", { max: plan.estimate.requests + 2 * plan.estimate.cast }) : translate("\u6A21\u578B\u8F93\u51FA\u9700\u8981\u4FEE\u590D\u65F6\uFF0C\u8BF7\u6C42\u6570\u53EF\u80FD\u589E\u52A0\u3002") : "",
5500
5500
  plan.estimate.provisional ? translate("\u6E05\u6D17\u5B8C\u6210\u540E\uFF0C\u7F16\u5267\u6B21\u6570\u53EF\u80FD\u8C03\u6574\u3002") : ""
5501
5501
  ] })
5502
5502
  ] }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-laivox-tts",
3
- "version": "0.7.23",
3
+ "version": "0.7.24",
4
4
  "private": false,
5
5
  "description": "把 TXT、EPUB、PDF 小说做成单人朗读或多角色有声书,也能一键朗读对话里的 AI 回答,支持本地书架与 MP3/WAV 导出。",
6
6
  "license": "MIT",
@@ -1,7 +1,9 @@
1
1
  import { hasSpeakable, isSeparator, sourceLines } from './segment.mjs'
2
2
  import { stripSpeakerPrefix } from './spoken-text.mjs'
3
3
 
4
- export const EXTRACT_SCRIPT = true
4
+ // New multi-role scripts only. A saved version 3 script and a job that already
5
+ // started as extract-v1 keep working whatever this says.
6
+ export const EXTRACT_SCRIPT = false
5
7
  export const SCRIPT_VERSION = 3
6
8
 
7
9
  const openers = { '「': '」', '『': '』', '“': '”' }
package/src/host/cast.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto'
2
2
  import { normalizeInstruct } from '../domain/voice-direction.mjs'
3
3
  import { ROLE_AGES } from '../domain/voice-assignment.mjs'
4
- import { dialogueMatches, hasSpeakable } from '../domain/segment.mjs'
4
+ import { dialogueMatches, hasSpeakable, isSeparator, sourceLines } from '../domain/segment.mjs'
5
5
  import { alignLine, uncoveredSpeakable } from '../domain/script-lines.mjs'
6
6
 
7
7
  export const EMOTIONS = ['neutral', 'happy', 'sad', 'angry', 'afraid', 'tense', 'gentle']
@@ -20,6 +20,8 @@ export const CAST = [
20
20
  '3. 复用 roles 里已有角色的 ref(c1、c2 这种短编号);旁白固定写 narrator。同一人物的别称复用同一个 ref,不要重复建角色。',
21
21
  '4. 新角色先在 roles 声明 {"ref":"new1","name":"角色名","gender":"female|male|","age":"child|teen|young|middle|elder|"},最多 12 个,再在 items 中用 ref 引用。age 按原文线索判断年龄段:child 儿童,teen 少年,young 青年,middle 中年,elder 老年;没有线索时留空。没有新角色时 roles 为空数组。',
22
22
  '5. 笔录、剧本或聊天里,段首如果只是纯角色名加冒号,instruct 只描述冒号后面真正说出的话。不要改写原文。',
23
+ '6. segments 里带 "scene":true 的段,和上一段之间隔着分场符(如 ※※※、——),场景已经切换:从这一段起,没写名字的引号对白不要沿用分场前的说话人,按分场后的动作、称呼和对话双方重新判断。',
24
+ '7. 带 "cont":"X" 的段,和前一段同属一行以「X:」开头、没有引号的笔录或聊天,被切成了几段。X 只是纯名字时,这一段仍是 X 在说,继续标 X,不要改标 narrator;X 带动作或神态时忽略 cont,按第 1 条判断。',
23
25
  '',
24
26
  '【表演方式】每段给出 emotion、intensity、instruct:',
25
27
  '1. emotion 只能是 neutral,happy,sad,angry,afraid,tense,gentle 之一;intensity 只能是整数 0、1、2(0 平淡,1 明显,2 强烈);neutral 时 intensity 必须为 0。',
@@ -31,7 +33,7 @@ export const CAST = [
31
33
  '',
32
34
  '【输出】',
33
35
  'items 每条用紧凑键以节省输出:s=segmentId,r=角色 ref(已知角色用 c1、c2,旁白用 narrator,新角色用 new1),e=emotion,n=intensity,i=instruct,a=该段原文去掉空白后的前 8 个字(不足 8 个字就写到段尾,标点照算,空白不算)。',
34
- '每个输入 segmentId 恰好返回一条,保留原编号,禁止遗漏或重复。用 context 辅助判断,但只标注 segments。引号内对白不确定说话人时,新建“男人”“女人”“陌生人”这类称呼,不得用 narrator。没有引号、也看不出是内心独白的叙述、动作、环境,才用 narrator。不确定情绪时用 neutral、强度 0。旁白的 instruct 写「自然叙述,语气平稳。」;对白的 instruct 写「自然交谈,语速适中。」。只返回一个 JSON 对象,不要 Markdown 或任何说明文字。',
36
+ '每个输入 segmentId 恰好返回一条,保留原编号,禁止遗漏或重复。用 context 辅助判断,但只标注 segments。scene、cont 只是提示,不写进输出。引号内对白不确定说话人时,新建“男人”“女人”“陌生人”这类称呼,不得用 narrator。没有引号、也看不出是内心独白的叙述、动作、环境,才用 narrator。不确定情绪时用 neutral、强度 0。旁白的 instruct 写「自然叙述,语气平稳。」;对白的 instruct 写「自然交谈,语速适中。」。只返回一个 JSON 对象,不要 Markdown 或任何说明文字。',
35
37
  '示例输入 segments [{"segmentId":41,"text":"  他走进了房间。"},{"segmentId":42,"text":"“快走,他们马上就到了!”"}]',
36
38
  '示例输出 {"roles":[{"ref":"new1","name":"林月","gender":"female","age":"young"}],"items":[{"s":41,"r":"narrator","e":"neutral","n":0,"i":"客观叙述,语气平稳。","a":"他走进了房间。"},{"s":42,"r":"new1","e":"tense","n":1,"i":"压低嗓音,带着警惕。","a":"“快走,他们马上"}]}',
37
39
  ].join('\n')
@@ -140,6 +142,38 @@ function castResult(value, segments, bookRoles, lookupRoles = bookRoles) {
140
142
  return accepted
141
143
  }
142
144
 
145
+ const leadingName = /^\s*([^\s,。!?;:、]{1,6})[::]/u
146
+ const attributionEnd = /[说說問问答道喊叫叹嘆]$/u
147
+
148
+ // Hints only; the model still decides the speaker.
149
+ // scene: a separator or decorative line (kept, or removed by cleaning) lies between
150
+ // this part and the previous speakable part.
151
+ // cont: this part continues an unquoted "名字:" line the segmenter cut into pieces.
152
+ export function castHints(text, segments) {
153
+ const lines = sourceLines(String(text ?? ''))
154
+ const breaks = new Array(lines.length + 1).fill(0)
155
+ for (let i = 0; i < lines.length; i++) {
156
+ const body = lines[i].text
157
+ breaks[i + 1] = breaks[i] + (body.trim() && (isSeparator(body) || !hasSpeakable(body)) ? 1 : 0)
158
+ }
159
+ const hints = new Map()
160
+ let previous = null
161
+ for (const part of segments) {
162
+ if (!hasSpeakable(part.text)) continue
163
+ const hint = {}
164
+ if (previous && Number.isInteger(part.line) && Number.isInteger(previous.line)
165
+ && breaks[part.line] - breaks[previous.line + 1] > 0) hint.scene = true
166
+ const line = lines[part.line]
167
+ if (previous?.line === part.line && line && part.start > line.start) {
168
+ const lead = leadingName.exec(line.text)
169
+ if (lead && !attributionEnd.test(lead[1]) && dialogueMatches(line.text).next().done) hint.cont = lead[1].normalize('NFKC')
170
+ }
171
+ if (hint.scene || hint.cont) hints.set(part.id, hint)
172
+ previous = part
173
+ }
174
+ return hints
175
+ }
176
+
143
177
  // palette carries the directions already accepted in this chapter so the model
144
178
  // can reuse narrator wording verbatim and keep each speaker's tone continuous.
145
179
  export async function recoverCastBatch(group, bookRoles, context, request, palette = { narrator: [], roles: [] }, lookupRoles = bookRoles) {
@@ -171,7 +205,12 @@ export async function recoverCastBatch(group, bookRoles, context, request, palet
171
205
  const reply = await request(repair ? CAST + '\n' + REPAIR : CAST, {
172
206
  roles: promptRoles(roles),
173
207
  palette: promptPalette, context: contextLines, segments: segments.map(part => {
174
- const body = { segmentId: part.id, text: part.text }
208
+ const body = {
209
+ segmentId: part.id,
210
+ text: part.text,
211
+ ...(part.scene ? { scene: true } : {}),
212
+ ...(part.cont ? { cont: part.cont } : {}),
213
+ }
175
214
  if (!repair) return body
176
215
  const index = group.indexOf(part)
177
216
  return { ...body, before: neighbor(group[index - 1]), after: neighbor(group[index + 1]) }
@@ -7,8 +7,8 @@ import { voiceAssignments } from '../domain/voice-assignment.mjs'
7
7
  import { messageFor } from '../domain/messages.mjs'
8
8
  import { addModelUsage, normalizeModelUsage } from './model-usage.mjs'
9
9
 
10
- import { NARRATOR, extractRoster, extractWindow, narrationSlice, recoverCastBatch } from './cast.mjs'
11
- import { EXTRACT_SCRIPT, partsFromLines, splitOversized, uncoveredSpeakable } from '../domain/script-lines.mjs'
10
+ import { NARRATOR, castHints, extractRoster, extractWindow, narrationSlice, recoverCastBatch } from './cast.mjs'
11
+ import { partsFromLines, splitOversized, uncoveredSpeakable } from '../domain/script-lines.mjs'
12
12
  import { assertModelProviderReady, createStreamGate, MODEL_IDLE_MS, MODEL_TOTAL_MS, readModelStream } from './model-stream.mjs'
13
13
 
14
14
  export { EMOTIONS, NARRATOR } from './cast.mjs'
@@ -463,7 +463,7 @@ export function createEditorialService(llm, library, {
463
463
  }
464
464
  let annotations = {}
465
465
  let scriptLines = null
466
- if (spec.cast && EXTRACT_SCRIPT && progress.script === 'extract-v1') {
466
+ if (spec.cast && progress.script === 'extract-v1') {
467
467
  progress.stage = 'scripting'
468
468
  const windowLimit = Number.isSafeInteger(extractChars) && extractChars > 0 ? extractChars : extractWindowChars(spec.selection)
469
469
  progress.windows ??= extractSourceWindows(chapter.text, removed, windowLimit).map(item => ({ ...item, state: 'pending', splits: 0 }))
@@ -566,6 +566,7 @@ export function createEditorialService(llm, library, {
566
566
  progress.castWindow ??= progress.cast?.length ? LEGACY_CAST_WINDOW
567
567
  : { chars: castWindow.chars, segments: castSegmentsFor(spec.selection, castWindow.segments) }
568
568
  const groups = windows(segments, progress.castWindow.chars, progress.castWindow.segments)
569
+ const hints = castHints(chapter.text, segments)
569
570
  progress.cast ??= []
570
571
  progress.castTotal = groups.length
571
572
  progress.stage = 'scripting'
@@ -598,6 +599,7 @@ export function createEditorialService(llm, library, {
598
599
  return { text: part.text, roleName: names.get(note?.roleId) ?? '' }
599
600
  })
600
601
  const spoken = group.filter(part => !isSeparator(part.text))
602
+ .map(part => (hints.has(part.id) ? { ...part, ...hints.get(part.id) } : part))
601
603
  signal.throwIfAborted()
602
604
  const request = async (prompt, payload) => {
603
605
  assertModelProviderReady(spec.selection?.provider, gate)
package/src/host/jobs.mjs CHANGED
@@ -75,7 +75,7 @@ function retakeStored(row, part) {
75
75
  return Boolean(row) && part.retake === true && row.writeId && row.writeId === part.localWriteId
76
76
  }
77
77
 
78
- export function createJobQueue({ library, editorial, llm, gatewayFor, errorCode, logger, synthesize = synthesizePart, edgeConcurrency = EDGE_CONCURRENCY, autoResumeWaits = EDGE_AUTO_RESUME_WAITS, transientWindow = LAIVOX_TRANSIENT_WINDOW }) {
78
+ export function createJobQueue({ library, editorial, llm, gatewayFor, errorCode, logger, synthesize = synthesizePart, edgeConcurrency = EDGE_CONCURRENCY, autoResumeWaits = EDGE_AUTO_RESUME_WAITS, transientWindow = LAIVOX_TRANSIENT_WINDOW, extractScripts = EXTRACT_SCRIPT }) {
79
79
  let guardBookExport = async (_book, run) => run()
80
80
  let flight
81
81
  let dispatcher
@@ -229,7 +229,8 @@ export function createJobQueue({ library, editorial, llm, gatewayFor, errorCode,
229
229
  const choice = spec.laivoxNarratorDefault
230
230
  const narratorDefault = gateway && (!choice?.account || choice.account === gateway.account) ? choice ?? null : null
231
231
  const legacyCast = Array.isArray(progress.cast) && progress.cast.length > 0 && progress.script !== 'extract-v1'
232
- if (EXTRACT_SCRIPT && (spec.mode === 'multi' || (spec.purpose === 'cast' && spec.mode === 'reading')) && !legacyCast && !progress.parts?.length && (spec.cast || chapter.editorial?.version === 3)) {
232
+ const extractJob = spec.cast ? extractScripts : chapter.editorial?.version === 3
233
+ if ((spec.mode === 'multi' || (spec.purpose === 'cast' && spec.mode === 'reading')) && !legacyCast && !progress.parts?.length && extractJob) {
233
234
  progress.script = 'extract-v1'
234
235
  progress.speakText = 'extract-v1'
235
236
  progress.segmentVersion = 3
@@ -954,7 +955,7 @@ export function createJobQueue({ library, editorial, llm, gatewayFor, errorCode,
954
955
  signal?.throwIfAborted()
955
956
  const estimated = await library.estimateGroup(group.map(row => row.id), input, {
956
957
  cleanWindow: CLEAN_WINDOW, castWindow: { chars: CAST_WINDOW, segments: castSegmentsFor(resolved) },
957
- extract: EXTRACT_SCRIPT, extractChars: extractWindowChars(resolved),
958
+ extract: extractScripts, extractChars: extractWindowChars(resolved),
958
959
  })
959
960
  for (const item of estimated) counted.set(item.id, item)
960
961
  }