@joplo-app/core 0.2.9 → 0.2.10

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/dist/catalog.d.ts CHANGED
@@ -78,6 +78,8 @@ export declare function captionLength(s: string): number;
78
78
  /** 说明 / explain 的建议上限(超过时 check 报 CAPTION_TOO_LONG / EXPLAIN_TOO_LONG)。 */
79
79
  export declare const CAPTION_MAX = 24;
80
80
  export declare const EXPLAIN_MAX = 48;
81
+ /** 旁白 say() 的建议上限(D74,超过时 check 报 SAY_TOO_LONG):读出来约 10 秒。 */
82
+ export declare const SAY_MAX = 80;
81
83
  /**
82
84
  * 叙事提示(D67,见 docs/research/storytelling-and-demos.md):
83
85
  * - 封面说明(flow 的 description):D61 定为 30 字以内,超过时 DESCRIPTION_TOO_LONG;
package/dist/catalog.js CHANGED
@@ -344,6 +344,8 @@ export function captionLength(s) {
344
344
  /** 说明 / explain 的建议上限(超过时 check 报 CAPTION_TOO_LONG / EXPLAIN_TOO_LONG)。 */
345
345
  export const CAPTION_MAX = 24;
346
346
  export const EXPLAIN_MAX = 48;
347
+ /** 旁白 say() 的建议上限(D74,超过时 check 报 SAY_TOO_LONG):读出来约 10 秒。 */
348
+ export const SAY_MAX = 80;
347
349
  /**
348
350
  * 叙事提示(D67,见 docs/research/storytelling-and-demos.md):
349
351
  * - 封面说明(flow 的 description):D61 定为 30 字以内,超过时 DESCRIPTION_TOO_LONG;
package/dist/compile.js CHANGED
@@ -43,6 +43,8 @@ export function compile(src, mode, opts = {}) {
43
43
  theme: src.config.theme ?? 'sketch',
44
44
  // 默认焦点行为(D70):只有作者写了才进 IR(缺省 = 开启),不用这个开关的项目 IR 不变
45
45
  ...(typeof src.config.autoFocus === 'boolean' ? { autoFocus: src.config.autoFocus } : {}),
46
+ // 朗读配置(D74):只有作者写了才进 IR;build 用它决定带哪些音频,写进站点前由 publishPayload 去掉
47
+ ...(voiceConfigOf(src.config.voice) ? { voiceConfig: voiceConfigOf(src.config.voice) } : {}),
46
48
  themes: { ...(src.themes ?? {}) },
47
49
  mode,
48
50
  routes: {},
@@ -205,6 +207,8 @@ export function compile(src, mode, opts = {}) {
205
207
  const root = toSceneNode(rootJ, 'root', ids, report, rel);
206
208
  return { id: sceneId, optionId: ctx?.qid ?? null, route: route.path, name: `${page.title}${ctx ? ` · ${ctx.def.name}` : ''}`, viewport: page.viewport ?? 'desktop', root };
207
209
  };
210
+ if (src.config.voice !== undefined && !voiceConfigOf(src.config.voice, true))
211
+ err('VOICE_CONFIG_INVALID', `config({ voice }) must be { profile?: string, narrator?: string, roles?: { [roleKey]: string } } with non-empty strings; got ${JSON.stringify(src.config.voice)}`, src.config.source ?? `${src.config.file}:1:1`);
208
212
  if (src.config.autoFocus !== undefined && typeof src.config.autoFocus !== 'boolean')
209
213
  err('AUTOFOCUS_INVALID', `config({ autoFocus }) must be true or false (default true); got ${JSON.stringify(src.config.autoFocus)}`, src.config.source ?? `${src.config.file}:1:1`);
210
214
  // 主题(D51):config.theme 必须是内置主题或 themes/<name>.css
@@ -394,6 +398,8 @@ export function compile(src, mode, opts = {}) {
394
398
  const effects = [];
395
399
  const ruleIds = [];
396
400
  const explains = [];
401
+ const says = [];
402
+ const narrates = [];
397
403
  const traces = [];
398
404
  const forks = [];
399
405
  const marks = [];
@@ -420,6 +426,18 @@ export function compile(src, mode, opts = {}) {
420
426
  effects.push({ type: 'toast', text: e.text, tone: e.tone });
421
427
  else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold')
422
428
  continue; // 镜头与焦点提示不是状态变化,下面单独归类
429
+ else if (e.type === 'say') {
430
+ if (typeof e.text === 'string' && e.text.trim())
431
+ says.push(e.text.trim());
432
+ else
433
+ err('SAY_EMPTY', 'say() needs the line the character speaks, for example say(\'I can make it!\'). Remove it to read the caption instead', st.source);
434
+ }
435
+ else if (e.type === 'narrate') {
436
+ if (typeof e.text === 'string' && e.text.trim())
437
+ narrates.push(e.text.trim());
438
+ else
439
+ err('NARRATE_EMPTY', 'narrate() needs the narrator\'s words, for example narrate(\'She sends Ajie the plan as a link, so he needs no app.\'). Remove it to read say() or the caption instead', st.source);
440
+ }
423
441
  else if (e.type === 'explain') {
424
442
  if (e.text.trim())
425
443
  explains.push(e.text.trim());
@@ -587,6 +605,8 @@ export function compile(src, mode, opts = {}) {
587
605
  ...(cues.length ? { cues } : {}),
588
606
  ...(callouts.length ? { callouts } : {}),
589
607
  ...(holdMs !== undefined ? { hold: holdMs } : {}),
608
+ ...(says.length ? { say: says.join(' ') } : {}),
609
+ ...(narrates.length ? { narrate: narrates.join(' ') } : {}),
590
610
  ...(st.source ? { source: rel(st.source) } : {}),
591
611
  };
592
612
  });
@@ -1127,3 +1147,35 @@ function stripNotes(n) {
1127
1147
  for (const c of n.children ?? [])
1128
1148
  stripNotes(c);
1129
1149
  }
1150
+ /**
1151
+ * config({ voice }) 规整(D74):去掉空白,空对象视为没写。strict = true 时形状不对返回 null(报 VOICE_CONFIG_INVALID)。
1152
+ */
1153
+ function voiceConfigOf(v, strict = false) {
1154
+ if (v === undefined || v === null)
1155
+ return null;
1156
+ if (typeof v !== 'object' || Array.isArray(v))
1157
+ return null;
1158
+ const o = v;
1159
+ const str = (x) => (typeof x === 'string' && x.trim() ? x.trim() : null);
1160
+ for (const k of Object.keys(o))
1161
+ if (!['profile', 'narrator', 'roles'].includes(k))
1162
+ return null;
1163
+ if (o.profile !== undefined && !str(o.profile))
1164
+ return null;
1165
+ if (o.narrator !== undefined && !str(o.narrator))
1166
+ return null;
1167
+ let roles;
1168
+ if (o.roles !== undefined) {
1169
+ if (!o.roles || typeof o.roles !== 'object' || Array.isArray(o.roles))
1170
+ return null;
1171
+ roles = {};
1172
+ for (const [k, val] of Object.entries(o.roles)) {
1173
+ const s = str(val);
1174
+ if (!s)
1175
+ return null;
1176
+ roles[k] = s;
1177
+ }
1178
+ }
1179
+ const out = { ...(str(o.profile) ? { profile: str(o.profile) } : {}), ...(str(o.narrator) ? { narrator: str(o.narrator) } : {}), ...(roles && Object.keys(roles).length ? { roles } : {}) };
1180
+ return Object.keys(out).length ? out : strict ? out : null;
1181
+ }
package/dist/guide.js CHANGED
@@ -200,7 +200,24 @@ Joplo already has the parts of a user story; fill them in that spirit.
200
200
  - Cover text: flow({ description }) is the cover sentence, 30 units at most (DESCRIPTION_TOO_LONG). The cover falls back to the feature goal.
201
201
  - Rhythm: every short step waits 3 s, so a run of trivial steps feels like a metronome. Merge trivial steps (type, then click) and give key results an explain.
202
202
 
203
- ## 6. Before handing over
203
+ ## 6. Narration: narrate() is a presenter talking, not the caption read aloud
204
+ When the board or the published site reads a demo aloud, each step reads, in order of preference: narrate() in the narrator's voice; else say(), the character's own line in that role's voice; else the caption in the narrator's voice (cards read title and sub). A caption read aloud sounds like a screen reader, so give the steps that will be heard a narrate() line, written the way a person walks a colleague through a feature. It may later be recorded by a real voice, so write how people speak.
205
+ - Short first: one sentence, two at most, mostly 3–8 seconds. Cut every word the screen already shows; the viewer is watching.
206
+ - Each line does one job: orient (who, where, what we are about to see), point (what to look at now and why it matters), connect (carry the viewer from the last step: 'Now over to Ajie'), or conclude (what this proved).
207
+ - Say what the caption cannot: the intent, the reason, the consequence. Never repeat the caption word for word; name an on-screen label only when the viewer must find it.
208
+ - Spoken sentences: subject first, active voice, one idea each. Commas and periods are the breaths; no brackets, slashes, arrows, emoji, or markdown.
209
+ - Write numbers, money, times, and versions the way they are said in the demo's language ('four hundred sixty' rather than '¥460'; 'version two' rather than 'v2').
210
+ - Transitions carry the story: role switches, time jumps, and closing cards need a line that tells the viewer why we moved.
211
+ - Plain and concrete, not flowery: no metaphors, slogans, or hype. Vivid means specific: real names, amounts, and times.
212
+ - Not every step needs its own line: a trivial step can keep its short caption, and a character's say() can carry a moment ('Count me in!').
213
+ - say() is first person, what the character would really say; narration about the characters goes in narrate().
214
+ - Open with the person and their goal; close with the one to three points, as speech, not a list read aloud. Write in the demo's language.
215
+ Wrong, it reads the interface: .click('share', 'Xiaoyu shares the itinerary', narrate('Click Share to share the itinerary.'))
216
+ Right, it says why: .click('share', 'Xiaoyu shares the itinerary', narrate('She sends it as a link, so Ajie needs no app.'))
217
+ A character speaking: .click('can_go', 'Ajie replies: I can go', say('Count me in!'))
218
+ Check: read every line aloud in order without looking at the screen. It should sound like one person telling one story, briskly.
219
+
220
+ ## 7. Before handing over
204
221
  - npx joplo outline: per feature, who it is for, the goal, each case with its expected result and coverage per option, and each scenario's steps, duration, opening and ending.
205
222
  - npx joplo check: CAPTION_TOO_LONG, EXPLAIN_TOO_LONG, DESCRIPTION_TOO_LONG, CARD_TEXT_TOO_LONG, SCENARIO_TOO_LONG, HAPPY_PATH_ONLY, CASE_NOT_COVERED (names the expected result).
206
223
  - Read only the captions from start to end: do they tell the story? Then look only at key frames (npx joplo render --step-id …): does the screen show it without captions?
@@ -340,11 +357,14 @@ What viewers look at in each step, and the lighter forms (spotlight, highlight,
340
357
  - Backend / architecture / logic: Diagram (relationships, grouped by business domain), Sequence (one call chain in time order), StateMachine (a lifecycle). Read npx joplo skill diagram.
341
358
  - Layout is automatic and computed at compile time; nodes never move between steps, also when parts appear with when.
342
359
  - Use trace('a','b','c') for the a→b→c call; trace.fail marks failure, trace.skip dims what was not called. Do not manually write node/edge state props or use set() to simulate calls; use trace().
343
- - shot of a Diagram node keeps its parent group (at least the group title) in frame; shot of a UI card keeps its framed container and zooms at most 1.25×. See diagram.
360
+ - shot of a Diagram node keeps its parent group (at least the group title) in frame; shot of a UI card keeps its framed container and zooms at most 1.25×, or more (up to 3×) when its text would be smaller than about 15px on screen, as on a phone layer. See diagram.
344
361
 
345
362
  ## Captions and fitting one screen
346
363
  - Keep captions within about 24 units and explain('Additional note') within about 48. CJK characters count as 1 each; all others count as 0.5; whitespace is ignored. check warns when exceeded.
347
364
  - Captions and explain notes appear below the stage, never over it. Tell one thing per step; move long content to an explanation layer. How to write them, and how to plan openings and endings: story.
365
+ - Narration (D74): the board and published site can read each step aloud during autoplay (viewers turn it on with the speaker button). Without say() the caption is read (cards read title and sub; explain is not read), which sounds like a screen reader. narrate('…') gives a step the narrator's spoken line and say('…') a character's own words, both kept apart from the caption (the caption is for the eye and stays short). How to write them: npx joplo skill story (section 6). Autoplay waits for the voice to finish plus a short breath before the next step.
366
+ Example: .type('email', 'ana@example.com', 'Ana enters the email', narrate('She invites Leo as an editor; the role can change later.')).
367
+ Voices are set up in the board (Voice → Manage providers; keys stay on this machine). config({ voice: { narrator: 'nova', roles: { leo: 'echo' } } }) picks voices per role; generated audio is bundled by build and share.
348
368
  - Autoplay reading time: CJK 8 chars/s (125ms each), Latin 15 non-whitespace chars/s; clamp to 3–7 seconds before 0.5× / 1× / 1.5× scaling. Streams, shots and edge waits can exceed 7 seconds. Shots use 700ms ease-out without overshoot.
349
369
  - Do not make viewers scroll through a long page. Fit one screen and zoom into details with shots.
350
370
  - Each page has one device, desktop by default. page({ viewport: 'mobile' }, tree) uses a Phone frame at a fixed width of 390.
@@ -507,7 +527,7 @@ Choose by the question: "what is where" → Diagram; "what happens in what order
507
527
  ## Frame with shot (what the camera keeps)
508
528
  - shot('kernel') frames the node with its parent group; when the whole group would make text too small, it keeps at least the group title. Viewers always see which domain they are in.
509
529
  - A trace with several nodes frames all of them and their group titles. shot('g_run') frames a whole domain; shot() returns to the whole layer.
510
- - UI cards and panels zoom at most 1.25× and keep their framed container (Card, Paper, Modal, Table, AppShell side…) in view, so neighbours stay visible.
530
+ - UI cards and panels zoom at most 1.25× (more, up to 3×, only when their text would be under about 15px on screen, e.g. a phone layer) and keep their framed container (Card, Paper, Modal, Table, AppShell side…) in view, so neighbours stay visible.
511
531
  - Want more context? shot the container or group. Want the reader to compare two places? shot both ids in one step.
512
532
  - Do not use zoom to read tiny text: if a diagram needs heavy zoom, split it into layers.
513
533
  - Point at a part without zooming: spotlight / highlight / callout (see focus). A callout on the framed node's group or a message's participant stays in the shot.
@@ -675,6 +695,9 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
675
695
  - DUPLICATE_ELEMENT: Duplicate element ids within a stage. Change only conflicting ids and update references.
676
696
  - CAPTION_TOO_LONG: Shorten the caption to about 24 units: CJK characters count as 1 each, all others as 0.5; whitespace is ignored. One thing per step; move long content to an explanation layer. See demo.
677
697
  - EXPLAIN_TOO_LONG: Shorten the explain note to about 48 units, using the same CJK 1 / other 0.5 calculation. Put detailed rationale in a separate explanation layer. See demo.
698
+ - SAY_TOO_LONG / NARRATE_TOO_LONG (warning): a say() or narrate() line over about 80 units (about 10 seconds aloud). Autoplay waits until it is read; say less or split the step.
699
+ - SAY_EMPTY / NARRATE_EMPTY: say() needs the character's words, narrate() the narrator's. Remove it to fall back to the caption.
700
+ - VOICE_CONFIG_INVALID: config({ voice }) takes { profile?, narrator?, roles?: { roleKey: 'voice' } } with non-empty strings. API keys never go in the config.
678
701
  - DESCRIPTION_TOO_LONG: flow({ description }) is the scenario cover sentence; keep it within 30 units, one sentence saying what this scenario shows. See story.
679
702
  - CARD_TEXT_TOO_LONG (info): a transition card's sub is over 48 units, a point over 24, or more than 4 points. Keep one sentence and a few short points; move details into steps.
680
703
  - SCENARIO_TOO_LONG (info): the scenario plays over 90 s at 1×. One scenario tells one thing: split it (happy path, then each recovery) or branch with fork(). npx joplo outline shows the pacing.
package/dist/index.d.ts CHANGED
@@ -16,3 +16,4 @@ export * from './agent-skill.js';
16
16
  export * from './pace.js';
17
17
  export * from './outline.js';
18
18
  export * from './diagram/index.js';
19
+ export * from './voice.js';
package/dist/index.js CHANGED
@@ -16,3 +16,4 @@ export * from "./agent-skill.js";
16
16
  export * from "./pace.js";
17
17
  export * from "./outline.js";
18
18
  export * from "./diagram/index.js";
19
+ export * from "./voice.js";
package/dist/schema.d.ts CHANGED
@@ -342,6 +342,8 @@ export declare const Step: z.ZodObject<{
342
342
  }>>;
343
343
  }, z.core.$strict>>>;
344
344
  hold: z.ZodOptional<z.ZodNumber>;
345
+ say: z.ZodOptional<z.ZodString>;
346
+ narrate: z.ZodOptional<z.ZodString>;
345
347
  source: z.ZodOptional<z.ZodString>;
346
348
  }, z.core.$strict>;
347
349
  export declare const Scenario: z.ZodObject<{
@@ -508,6 +510,8 @@ export declare const Scenario: z.ZodObject<{
508
510
  }>>;
509
511
  }, z.core.$strict>>>;
510
512
  hold: z.ZodOptional<z.ZodNumber>;
513
+ say: z.ZodOptional<z.ZodString>;
514
+ narrate: z.ZodOptional<z.ZodString>;
511
515
  source: z.ZodOptional<z.ZodString>;
512
516
  }, z.core.$strict>>>;
513
517
  expected: z.ZodDefault<z.ZodString>;
@@ -663,12 +667,37 @@ export declare const Issue: z.ZodObject<{
663
667
  refs: z.ZodDefault<z.ZodArray<z.ZodString>>;
664
668
  source: z.ZodOptional<z.ZodString>;
665
669
  }, z.core.$strict>;
670
+ /** 朗读配置(D74,来自 config({ voice })):只在 dev / review IR 里,发布站去掉。 */
671
+ export declare const VoiceConfig: z.ZodObject<{
672
+ profile: z.ZodOptional<z.ZodString>;
673
+ narrator: z.ZodOptional<z.ZodString>;
674
+ roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
675
+ }, z.core.$strict>;
676
+ /**
677
+ * 发布站带上的朗读音频(D74,joplo build 写入):voices 是每个声音的指纹(旁白与各角色),
678
+ * clips 的键是 clipKey(指纹, 朗读文字),值是相对站点根目录的音频路径。没有时观众端用浏览器朗读。
679
+ */
680
+ export declare const VoiceIndex: z.ZodObject<{
681
+ narrator: z.ZodNullable<z.ZodString>;
682
+ roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
683
+ clips: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
684
+ }, z.core.$strict>;
666
685
  export declare const Project: z.ZodObject<{
667
686
  schemaVersion: z.ZodLiteral<2>;
668
687
  name: z.ZodString;
669
688
  description: z.ZodDefault<z.ZodString>;
670
689
  theme: z.ZodDefault<z.ZodString>;
671
690
  autoFocus: z.ZodOptional<z.ZodBoolean>;
691
+ voiceConfig: z.ZodOptional<z.ZodObject<{
692
+ profile: z.ZodOptional<z.ZodString>;
693
+ narrator: z.ZodOptional<z.ZodString>;
694
+ roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
695
+ }, z.core.$strict>>;
696
+ voiceIndex: z.ZodOptional<z.ZodObject<{
697
+ narrator: z.ZodNullable<z.ZodString>;
698
+ roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
699
+ clips: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
700
+ }, z.core.$strict>>;
672
701
  themes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
673
702
  mode: z.ZodEnum<{
674
703
  publish: "publish";
@@ -969,6 +998,8 @@ export declare const Project: z.ZodObject<{
969
998
  }>>;
970
999
  }, z.core.$strict>>>;
971
1000
  hold: z.ZodOptional<z.ZodNumber>;
1001
+ say: z.ZodOptional<z.ZodString>;
1002
+ narrate: z.ZodOptional<z.ZodString>;
972
1003
  source: z.ZodOptional<z.ZodString>;
973
1004
  }, z.core.$strict>>>;
974
1005
  expected: z.ZodDefault<z.ZodString>;
@@ -1007,3 +1038,5 @@ export type Fork = z.infer<typeof Fork>;
1007
1038
  export type Mark = z.infer<typeof Mark>;
1008
1039
  export type Cue = z.infer<typeof Cue>;
1009
1040
  export type Callout = z.infer<typeof Callout>;
1041
+ export type VoiceConfig = z.infer<typeof VoiceConfig>;
1042
+ export type VoiceIndex = z.infer<typeof VoiceIndex>;
package/dist/schema.js CHANGED
@@ -167,6 +167,10 @@ export const Step = z.strictObject({
167
167
  callouts: z.array(Callout).optional(),
168
168
  /** 自动播放时这一步至少停留的毫秒数(D70,来自 hold;未按速度缩放);没有时省略。 */
169
169
  hold: z.number().int().positive().max(30_000).optional(),
170
+ /** 角色台词(D74,来自 say(),多个按空格连接):用这一步角色的声音读;没有时省略。发布站保留。 */
171
+ say: z.string().min(1).optional(),
172
+ /** 旁白(D74,来自 narrate()):用旁白的声音读,优先于台词和字幕;没有时省略。发布站保留。 */
173
+ narrate: z.string().min(1).optional(),
170
174
  source: Source,
171
175
  });
172
176
  export const Scenario = z.strictObject({
@@ -269,6 +273,21 @@ export const Issue = z.strictObject({
269
273
  refs: z.array(z.string()).default([]),
270
274
  source: Source,
271
275
  });
276
+ /** 朗读配置(D74,来自 config({ voice })):只在 dev / review IR 里,发布站去掉。 */
277
+ export const VoiceConfig = z.strictObject({
278
+ profile: z.string().min(1).optional(),
279
+ narrator: z.string().min(1).optional(),
280
+ roles: z.record(z.string(), z.string().min(1)).optional(),
281
+ });
282
+ /**
283
+ * 发布站带上的朗读音频(D74,joplo build 写入):voices 是每个声音的指纹(旁白与各角色),
284
+ * clips 的键是 clipKey(指纹, 朗读文字),值是相对站点根目录的音频路径。没有时观众端用浏览器朗读。
285
+ */
286
+ export const VoiceIndex = z.strictObject({
287
+ narrator: z.string().min(1).nullable(),
288
+ roles: z.record(z.string(), z.string().min(1)).default({}),
289
+ clips: z.record(z.string(), z.string().min(1)).default({}),
290
+ });
272
291
  export const Project = z.strictObject({
273
292
  schemaVersion: z.literal(SCHEMA_VERSION),
274
293
  name: z.string().min(1),
@@ -277,6 +296,8 @@ export const Project = z.strictObject({
277
296
  theme: z.string().min(1).default('sketch'),
278
297
  /** 默认焦点行为(D70):缺省 = 开启;false = 只按作者写的镜头与提示呈现(config({ autoFocus: false }))。发布站保留。 */
279
298
  autoFocus: z.boolean().optional(),
299
+ voiceConfig: VoiceConfig.optional(),
300
+ voiceIndex: VoiceIndex.optional(),
280
301
  /** 作者主题(D51):主题名 → CSS 原文(themes/<name>.css);渲染时自动限定在舞台范围内。发布站同样打包。 */
281
302
  themes: z.record(z.string(), z.string()).default({}),
282
303
  /** dev = 含全部方案(本地看板);publish = 只含选定方案,且去掉创作侧信息(D33);review = 评审版:全部方案,同样去掉创作侧信息(D63)。 */
package/dist/validate.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { orderedFeatures } from "./features.js";
2
2
  import { Project } from "./schema.js";
3
- import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, INTERACTIVE_TYPES, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
3
+ import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, SAY_MAX, INTERACTIVE_TYPES, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
4
4
  import { scenarioEstimateMs } from "./outline.js";
5
5
  import { walkNodes, findNode, replay } from "./player.js";
6
6
  import { JoploError } from "./result.js";
@@ -205,6 +205,12 @@ export function validate(project, opts = { mode: 'all' }) {
205
205
  if (el > EXPLAIN_MAX)
206
206
  emit('warning', 'EXPLAIN_TOO_LONG', `explain note length is ${el} units (recommended maximum: ${EXPLAIN_MAX}; CJK characters count as 1 each, all others as 0.5; whitespace is not counted). Move long content to a separate explanation layer, for example layers: { why: layer('Design rationale', <Why />) }, then switch to it with shot`, at, r);
207
207
  }
208
+ // 朗读(D74):一段大约 SAY_MAX 个“字”读出来约 10 秒,再长观众会等得不耐烦
209
+ for (const [fn, code, text] of [['say', 'SAY_TOO_LONG', st.say], ['narrate', 'NARRATE_TOO_LONG', st.narrate]]) {
210
+ const sl = text ? captionLength(text) : 0;
211
+ if (sl > SAY_MAX)
212
+ emit('warning', code, `${fn}() is ${sl} units (recommended maximum: ${SAY_MAX}, about 10 seconds read aloud; CJK characters count as 1 each, all others as 0.5). Autoplay waits until it is read, so say less or split the step`, at, r);
213
+ }
208
214
  }
209
215
  }
210
216
  focusStructureDiagnostics(p, scenarios, emit); // 焦点提示(D70)
@@ -0,0 +1,30 @@
1
+ import type { Project, Step } from './schema.js';
2
+ /**
3
+ * 默认说话风格(D74):像讲解人介绍功能,而不是朗读;用文字本身的语言、母语口音读(这就是“跟随语言”:
4
+ * 同一个音色读中文就是中文母语的读法,读英文就是英文的读法)。发给支持 instructions 的模型。
5
+ */
6
+ export declare const DEFAULT_STYLE = "You are the narrator of a short product demo. Speak like a friendly presenter walking a colleague through a new feature: warm, clear and relaxed, at a natural conversational pace, never like reading a list. Pause briefly at commas and between sentences. Read the text in its own language with a natural native accent; never translate it.";
7
+ /** 读完之后、进下一步之前的换气(毫秒,1× 速度)。 */
8
+ export declare const VOICE_BREATH_MS = 450;
9
+ /** 把几句话连成一段朗读:句末没有标点时补一个(中文“。”,其他“.”)。 */
10
+ export declare function joinSpoken(parts: (string | null | undefined)[]): string;
11
+ /**
12
+ * 这一步读什么、用谁的声音(D74):narrate()(旁白的声音)> say()(这一步角色的声音;没有角色时旁白)>
13
+ * 字幕(旁白的声音;过渡卡读标题和副标题)。caption 是这一步在当前语言下显示的字幕(网页用 stepCaption,服务端用 step.caption);
14
+ * speaker 是这一步的说话角色(speakerRoleAt)。text 为空串表示这一步不读;role 为 null 表示旁白。
15
+ */
16
+ export declare function spokenLine(step: Step, caption: string, speaker: string | null): {
17
+ text: string;
18
+ role: string | null;
19
+ };
20
+ /** 这一步要读的文字(不关心是谁读)。 */
21
+ export declare function narrationText(step: Step, caption: string): string;
22
+ /** 第 index 步(1 起)的说话角色:用户操作取这一步之后导演所在层画面的角色 id;没有角色、系统步骤与过渡卡为 null。say() 用它的声音。 */
23
+ export declare function speakerRoleAt(project: Project, scenarioId: string, index: number): string | null;
24
+ /** 音频片段的键:声音指纹 + 规整后的朗读文字(空白合并)。 */
25
+ export declare function clipKey(fingerprint: string, text: string): string;
26
+ /** 某个角色(null = 旁白)用哪个声音指纹;角色没有单独的声音时用旁白的。 */
27
+ export declare function voiceFingerprint(voices: {
28
+ narrator: string | null;
29
+ roles: Record<string, string>;
30
+ }, roleId: string | null): string | null;
package/dist/voice.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * 朗读(D74)的纯函数:看板、发布站、服务端(生成与 build)共用。
3
+ *
4
+ * - 读什么:narrationText —— 有 say() 读 say;过渡卡读标题和副标题;其余读字幕(字幕由调用方按当前语言给出,
5
+ * 自动字幕在网页里本地化)。explain 不读。
6
+ * - 谁来读:speakerRoleAt —— 用户操作取这一步导演层画面的角色(与字幕说话人同一来源);系统步骤、过渡卡用旁白。
7
+ * - 音频片段的键:clipKey(声音指纹, 朗读文字)。指纹由服务端按 profile 与音色算出(不含 Key),
8
+ * 同一段文字换了声音或改了字就是新键,旧音频自然失效,不需要另记“过期”。
9
+ * - 节奏:每一步停留 = max(画面停留, 声音时长 + VOICE_BREATH_MS),换气按播放速度缩放。
10
+ */
11
+ import { cameraAt, layersOf, roleOfScene } from "./player.js";
12
+ /**
13
+ * 默认说话风格(D74):像讲解人介绍功能,而不是朗读;用文字本身的语言、母语口音读(这就是“跟随语言”:
14
+ * 同一个音色读中文就是中文母语的读法,读英文就是英文的读法)。发给支持 instructions 的模型。
15
+ */
16
+ export const DEFAULT_STYLE = 'You are the narrator of a short product demo. Speak like a friendly presenter walking a colleague through a new feature: warm, clear and relaxed, at a natural conversational pace, never like reading a list. Pause briefly at commas and between sentences. Read the text in its own language with a natural native accent; never translate it.';
17
+ /** 读完之后、进下一步之前的换气(毫秒,1× 速度)。 */
18
+ export const VOICE_BREATH_MS = 450;
19
+ /** 一段文字是不是以中日韩文字为主(决定拼接时用全角句号)。 */
20
+ const mostlyWide = (t) => [...t].filter((ch) => (ch.codePointAt(0) ?? 0) > 0x2e80).length * 2 >= [...t.replace(/\s/g, '')].length;
21
+ /** 全角句号与句末标点(写成转义:源码里不放 CJK 字面量)。 */
22
+ const WIDE_STOP = '\u3002';
23
+ const SENTENCE_END = /[\u3002\uff01\uff1f!?.\u2026:\uff1a;\uff1b,\uff0c]$/;
24
+ /** 把几句话连成一段朗读:句末没有标点时补一个(中文“。”,其他“.”)。 */
25
+ export function joinSpoken(parts) {
26
+ const xs = parts.map((p) => (p ?? '').trim()).filter(Boolean);
27
+ return xs
28
+ .map((p, i) => (i < xs.length - 1 && !SENTENCE_END.test(p) ? p + (mostlyWide(p) ? WIDE_STOP : '.') : p))
29
+ .join(xs.some(mostlyWide) ? '' : ' ');
30
+ }
31
+ /**
32
+ * 这一步读什么、用谁的声音(D74):narrate()(旁白的声音)> say()(这一步角色的声音;没有角色时旁白)>
33
+ * 字幕(旁白的声音;过渡卡读标题和副标题)。caption 是这一步在当前语言下显示的字幕(网页用 stepCaption,服务端用 step.caption);
34
+ * speaker 是这一步的说话角色(speakerRoleAt)。text 为空串表示这一步不读;role 为 null 表示旁白。
35
+ */
36
+ export function spokenLine(step, caption, speaker) {
37
+ if (step.narrate?.trim())
38
+ return { text: step.narrate.trim(), role: null };
39
+ if (step.say?.trim())
40
+ return { text: step.say.trim(), role: speaker };
41
+ if (step.action.type === 'card')
42
+ return { text: joinSpoken([step.action.title, step.action.sub]), role: null };
43
+ return { text: caption.trim(), role: null };
44
+ }
45
+ /** 这一步要读的文字(不关心是谁读)。 */
46
+ export function narrationText(step, caption) {
47
+ return spokenLine(step, caption, null).text;
48
+ }
49
+ /** 第 index 步(1 起)的说话角色:用户操作取这一步之后导演所在层画面的角色 id;没有角色、系统步骤与过渡卡为 null。say() 用它的声音。 */
50
+ export function speakerRoleAt(project, scenarioId, index) {
51
+ const step = project.scenarios[scenarioId]?.steps[index - 1];
52
+ if (!step || step.kind !== 'user')
53
+ return null;
54
+ const layer = cameraAt(project, scenarioId, index).directorLayer;
55
+ const sceneId = layersOf(project, scenarioId).find((l) => l.id === layer)?.sceneId;
56
+ return roleOfScene(project, sceneId)?.id ?? null;
57
+ }
58
+ /** 53 位的字符串哈希(cyrb53),两个种子拼成 26 位十六进制;同步、无依赖,网页与服务端结果一致。 */
59
+ function cyrb53(s, seed) {
60
+ let h1 = 0xdeadbeef ^ seed;
61
+ let h2 = 0x41c6ce57 ^ seed;
62
+ for (let i = 0; i < s.length; i++) {
63
+ const ch = s.charCodeAt(i);
64
+ h1 = Math.imul(h1 ^ ch, 2654435761);
65
+ h2 = Math.imul(h2 ^ ch, 1597334677);
66
+ }
67
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
68
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
69
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0);
70
+ }
71
+ /** 音频片段的键:声音指纹 + 规整后的朗读文字(空白合并)。 */
72
+ export function clipKey(fingerprint, text) {
73
+ const s = `${fingerprint}\n${text.replace(/\s+/g, ' ').trim()}`;
74
+ return `c${cyrb53(s, 1).toString(16).padStart(14, '0')}${cyrb53(s, 7).toString(16).padStart(14, '0')}`;
75
+ }
76
+ /** 某个角色(null = 旁白)用哪个声音指纹;角色没有单独的声音时用旁白的。 */
77
+ export function voiceFingerprint(voices, roleId) {
78
+ return (roleId ? voices.roles[roleId] : undefined) ?? voices.narrator;
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Joplo 编译器、校验器与播放器(IR v2)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@joplo-app/kit": "0.2.9",
22
+ "@joplo-app/kit": "0.2.10",
23
23
  "elkjs": "0.12.1",
24
24
  "zod": "4.6.7"
25
25
  },