sisyo 1.6.8 → 1.8.0

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.
Files changed (53) hide show
  1. package/LICENSE +16 -16
  2. package/README.md +167 -162
  3. package/bin/known-hashes.json +100 -7
  4. package/package.json +1 -1
  5. package/templates/.claude/rules/agents-and-tests.md +32 -0
  6. package/templates/.claude/rules/docs.md +19 -19
  7. package/templates/.claude/skills/fastapi-best-practices/ASYNC-PATTERNS.md +121 -121
  8. package/templates/.claude/skills/fastapi-best-practices/DATABASE.md +153 -153
  9. package/templates/.claude/skills/fastapi-best-practices/DEPENDENCIES.md +140 -140
  10. package/templates/.claude/skills/fastapi-best-practices/PROJECT-STRUCTURE.md +90 -90
  11. package/templates/.claude/skills/fastapi-best-practices/PYDANTIC-GUIDE.md +155 -155
  12. package/templates/.claude/skills/fastapi-best-practices/SKILL.md +123 -123
  13. package/templates/.claude/skills/g6-style/SKILL.md +125 -0
  14. package/templates/.claude/skills/g6-style/references/checks.md +58 -0
  15. package/templates/.claude/skills/g6-style/references/imagery.md +103 -0
  16. package/templates/.claude/skills/g6-style/references/motion.md +121 -0
  17. package/templates/.claude/skills/g6-style/references/sections.md +263 -0
  18. package/templates/.claude/skills/g6-style/references/tokens.md +197 -0
  19. package/templates/.claude/skills/hindsight/SKILL.md +175 -172
  20. package/templates/.claude/skills/hoang-auth/SKILL.md +188 -0
  21. package/templates/.claude/skills/html-docs/SKILL.md +207 -207
  22. package/templates/.claude/skills/i18n-multilang/SKILL.md +153 -0
  23. package/templates/.claude/skills/i18n-multilang/assets/languages.json +47 -0
  24. package/templates/.claude/skills/i18n-multilang/assets/plural-vectors.json +46 -0
  25. package/templates/.claude/skills/i18n-multilang/assets/project/README.md +17 -0
  26. package/templates/.claude/skills/i18n-multilang/assets/project/gitattributes.txt +6 -0
  27. package/templates/.claude/skills/i18n-multilang/assets/project/gitignore.txt +4 -0
  28. package/templates/.claude/skills/i18n-multilang/assets/project/glossary.json +6 -0
  29. package/templates/.claude/skills/i18n-multilang/assets/project/i18n.config.json +22 -0
  30. package/templates/.claude/skills/i18n-multilang/assets/project/locales/__source__/common.json +10 -0
  31. package/templates/.claude/skills/i18n-multilang/assets/project/notes/common.json +5 -0
  32. package/templates/.claude/skills/i18n-multilang/assets/project/style.md +20 -0
  33. package/templates/.claude/skills/i18n-multilang/references/format.md +100 -0
  34. package/templates/.claude/skills/i18n-multilang/references/languages.md +97 -0
  35. package/templates/.claude/skills/i18n-multilang/references/layout-and-versioning.md +256 -0
  36. package/templates/.claude/skills/i18n-multilang/references/numbers.md +161 -0
  37. package/templates/.claude/skills/i18n-multilang/references/platform-unity.md +142 -0
  38. package/templates/.claude/skills/i18n-multilang/references/platform-web.md +107 -0
  39. package/templates/.claude/skills/i18n-multilang/references/translation.md +143 -0
  40. package/templates/.claude/skills/i18n-multilang/references/voice.md +271 -0
  41. package/templates/.claude/skills/i18n-multilang/scripts/i18n.py +1041 -0
  42. package/templates/.claude/skills/i18n-multilang/scripts/numwords.py +1013 -0
  43. package/templates/.claude/skills/i18n-multilang/scripts/voice.py +478 -0
  44. package/templates/.claude/skills/react-page-oriented/SKILL.md +407 -407
  45. package/templates/.claude/skills/react-page-oriented/triggers.md +12 -12
  46. package/templates/.claude/skills/terraform-best-practices/SKILL.md +341 -341
  47. package/templates/.claude/skills/typesafe-jev/SKILL.md +148 -148
  48. package/templates/.claude/skills/vibe-docs/SKILL.md +242 -242
  49. package/templates/SISYO.md +37 -37
  50. package/templates/docs/99_progress/features.md +7 -7
  51. package/templates/docs/99_progress/handoff.md +19 -19
  52. package/templates/docs/99_progress/todo.md +15 -15
  53. package/templates/docs/MAP.md +26 -26
@@ -0,0 +1,107 @@
1
+ # Web and apps (i18next)
2
+
3
+ The standard format **is** i18next's, so a site that already uses `i18next`, `react-i18next` or `next-i18next` needs
4
+ configuration, not conversion.
5
+
6
+ ## Project setup
7
+
8
+ - `i18n/` at the repository root as everywhere ([layout-and-versioning.md](layout-and-versioning.md)), or point
9
+ `localesDir` / `layout` at the folder the site already has:
10
+ - one file per language (`src/i18n/locales/en.json`): `"layout": "{lang}.json"` (namespace `translation`)
11
+ - per namespace (`public/locales/en/common.json`): `"layout": "{lang}/{ns}.json"`
12
+ - `capabilities: ["rtl", "shaping"]`: browsers render every script. All 40 languages are open, provided the layout is
13
+ checked right-to-left (below).
14
+ - Use the registry codes. A site that used `jp` renames the folder to `ja` and redirects old URLs.
15
+
16
+ ## i18next configuration
17
+
18
+ ```ts
19
+ import i18n from 'i18next'
20
+ import { initReactI18next } from 'react-i18next'
21
+ import manifest from '../../i18n/manifest.json' // written by "i18n.py pack"
22
+
23
+ const ready = Object.entries(manifest.languages).filter(([, l]) => l.status === 'ready').map(([code]) => code)
24
+ const fallbackLng = Object.fromEntries(
25
+ Object.entries(manifest.languages).map(([code, l]) => [code, l.fallback]),
26
+ )
27
+
28
+ i18n.use(initReactI18next).init({
29
+ lng: pickLanguage(ready), // below
30
+ supportedLngs: ready,
31
+ fallbackLng: { ...fallbackLng, default: [manifest.fallbackLanguage] },
32
+ load: 'currentOnly', // "pt-BR" is a language, not "pt" + region
33
+ ns: ['common'], defaultNS: 'common',
34
+ interpolation: { escapeValue: false }, // React escapes; keep the default {{ }} delimiters
35
+ returnNull: false,
36
+ })
37
+ ```
38
+
39
+ Keep i18next's defaults for everything the format relies on: `{{ }}` interpolation, `:` namespace separator, `.` key
40
+ separator, `_` plural separator, JSON v4 plurals.
41
+
42
+ Loading the texts, by size of the site:
43
+ - **Small site**: import the JSON of each language lazily (`import.meta.glob('../../i18n/locales/*/*.json')` in
44
+ Vite, dynamic `import()` elsewhere) and `i18n.addResourceBundle(lng, ns, data)`. Nothing is fetched at runtime.
45
+ - **Larger site / translations updated without a deploy**: `i18next-http-backend` with
46
+ `loadPath: '<cdn>/locales/{{lng}}/{{ns}}.json'` (the repository layout served as is), or fetch the pack file named
47
+ in the CDN manifest and add each namespace: `Object.entries(pack.strings).forEach(([ns, s]) =>
48
+ i18n.addResourceBundle(lng, ns, s, true, true))`. Flat dotted keys in the pack are read by i18next as they are.
49
+ - **Next.js**: `next-i18next` or the App Router's own i18n routing with the same files; locales list from the
50
+ manifest.
51
+
52
+ ## Choosing the language
53
+
54
+ ```ts
55
+ function pickLanguage(ready: string[], wantedList = navigator.languages ?? [navigator.language]): string {
56
+ const find = (code?: string) => code && ready.find(r => r.toLowerCase() === code.toLowerCase())
57
+ const saved = find(localStorage.getItem('lang') ?? undefined)
58
+ if (saved) return saved
59
+ const alias = (code: string) => Object.keys(manifest.languages).find(k =>
60
+ (manifest.languages[k].aliases ?? []).some(a => a.toLowerCase() === code.toLowerCase()))
61
+ for (const wanted of wantedList) {
62
+ let loc: Intl.Locale
63
+ try { loc = new Intl.Locale(wanted).maximize() } catch { continue } // zh-TW -> zh-Hant-TW
64
+ const hit = find(wanted) ?? find(alias(wanted)) ?? find(`${loc.language}-${loc.script}`)
65
+ ?? find(loc.language) ?? find(alias(loc.language))
66
+ ?? (loc.language === 'zh' ? undefined : ready.find(r => r.split('-')[0] === loc.language))
67
+ if (hit) return hit // es-MX -> es; pt-PT -> pt-BR when that is the only Portuguese
68
+ }
69
+ return find('en') ?? manifest.sourceLanguage
70
+ }
71
+ ```
72
+
73
+ This is the matching rule of [languages.md](languages.md) in code (tested on zh-TW, zh-MY, pt-PT, es-MX, no, iw, tl
74
+ and others); a game ports the same steps. Save the choice when the user changes it (`localStorage`, and the account
75
+ profile if there is one). A URL that names a language (`/ja/…`) wins over both.
76
+
77
+ ## Page-level rules
78
+
79
+ - `<html lang="{code}" dir="{ltr|rtl}">` updated on every language change (`dir` comes from the manifest).
80
+ - Right-to-left: use logical CSS (`margin-inline-start`, `padding-inline-end`, `text-align: start`), flip directional
81
+ icons, test one Arabic page before declaring it done.
82
+ - Language switcher: the same picker rules as the games ([languages.md](languages.md)): searchable, rows
83
+ `English name (native name)`, a globe icon. `Intl.DisplayNames` may add the name in the current language as a third
84
+ search term.
85
+ - Numbers, dates, currency, lists and relative times: `Intl.NumberFormat`, `Intl.DateTimeFormat`, `Intl.ListFormat`,
86
+ `Intl.RelativeTimeFormat` with the active language, then pass the result into a `{{placeholder}}`.
87
+ - Fonts: a font stack with system CJK / Thai / Arabic fallbacks; do not ship one webfont for all scripts.
88
+ - SEO for public pages: one URL per language (`/en/…`, `/ja/…`), `<link rel="alternate" hreflang="…">` for every
89
+ ready language plus `x-default`, translated `<title>` and meta description (keep them in a `seo` namespace), and a
90
+ sitemap that lists the alternates. Static sites are generated per language from the same
91
+ locale files at build.
92
+ - Never build a sentence in JSX from fragments; use one key with placeholders, or `<Trans>` when markup must sit
93
+ inside the sentence (web-only namespace, see [format.md](format.md)).
94
+
95
+ ## Checks for a web project
96
+
97
+ - `python i18n.py check` in CI; `i18n.py pack` before a release so `manifest.json` is current.
98
+ - A script (or `i18next-parser` in check mode) that fails when the code uses a key the source lacks.
99
+ - A visual pass per new language on the main pages at phone width: overflow, clipped buttons, mixed directions.
100
+
101
+ ## Apps
102
+
103
+ | App type | How it uses the standard |
104
+ |---|---|
105
+ | React Native, Electron, Capacitor | i18next exactly as above; packs bundled, optional CDN update |
106
+ | Native iOS / Android, Flutter | the texts are still authored in `i18n/locales` (one source, same translation loop). No exporter exists yet: when the first such app appears, add an export step to `pack` that writes `.xcstrings` / `strings.xml` / `.arb` from the locale files, and keep those generated files out of hand editing |
107
+ | Store listing (name, subtitle, description, keywords, what's new) | a `store` namespace translated with the same loop; note the stores' length limits in `notes/store.json` |
@@ -0,0 +1,143 @@
1
+ # Translating with an agent
2
+
3
+ The agent is the translator. The tool hands over exactly what needs translating, with context, and refuses answers
4
+ that would break the app. Nothing is sent to an outside translation service.
5
+
6
+ ## The loop for one language
7
+
8
+ ```bash
9
+ python <skill>/scripts/i18n.py status # which languages need work
10
+ python <skill>/scripts/i18n.py todo --lang ja --limit 150 --out todo.ja.json
11
+ # translate: write done.ja.json
12
+ python <skill>/scripts/i18n.py apply done.ja.json # validates, writes locales/ja, stamps meta
13
+ python <skill>/scripts/i18n.py todo --lang ja … # repeat until "0 of 0"
14
+ python <skill>/scripts/i18n.py check --lang ja
15
+ ```
16
+
17
+ Keep `todo` / `done` files in a scratch folder, not in the repository.
18
+
19
+ `todo.<lang>.json` gives, per text: `id` (`ns:key`), `state` (`missing`, `stale`, `incomplete`), `source`,
20
+ `reference` (the same text in the reference language, when it is current), `note` (context, `max` length),
21
+ `current` (the old translation of a stale text: change only what the new source requires), `forms` (the plural forms
22
+ this language needs), `voice: true` (the line is spoken aloud in this language: see "Voice lines" below). At the top:
23
+ the language, its plural forms, and the glossary for it.
24
+
25
+ The answer file:
26
+
27
+ ```json
28
+ {
29
+ "lang": "ru",
30
+ "items": {
31
+ "shop:title": "Магазин",
32
+ "shop:buy": "Купить за {{price}} монет",
33
+ "shop:items": { "one": "{{count}} предмет", "few": "{{count}} предмета", "many": "{{count}} предметов", "other": "{{count}} предмета" }
34
+ }
35
+ }
36
+ ```
37
+
38
+ `apply` rejects an item (and says why) when a placeholder is lost or invented, a plural form is missing, a forbidden
39
+ word appears, the note's `max` is exceeded, or the key is locked. Fix and apply again; accepted items are already saved.
40
+
41
+ ## Order and scale
42
+
43
+ 1. **English first** when the source is not English. It becomes the `reference` every other language sees, which
44
+ steadies meaning for languages where direct Vietnamese→X data is thin.
45
+ 2. Then the other voice languages, then the rest.
46
+ 3. Work in batches of 100–200 texts per language so every item gets attention and the answer file stays reviewable.
47
+ One namespace at a time (`--ns`) keeps context coherent.
48
+ 4. Many languages at once: one sub-agent per language (or per small group), each running the loop above on its own
49
+ `--lang`. They write different files, so they do not collide; run `check` and `pack` once at the end, in the lead.
50
+ Translation batches are execution work: give them to the cheaper model tier, and keep the lead on the session
51
+ model for the review.
52
+
53
+ ## Before translating: read
54
+
55
+ - `i18n/style.md`: audience, tone, form of address, per-language rules. If it is empty, fill in the top part from the
56
+ product's docs first: a translation without a brief guesses the register.
57
+ - `i18n/glossary.json`: `keep` (names never translated), `terms` (fixed translations), `forbidden`.
58
+ - The `note` of each text. When a short text has no note and its meaning is unclear ("Open", "Back", "Light"), look
59
+ at where the key is used in the code before translating, then add the note so the next language does not ask again.
60
+
61
+ ## Rules for the translation itself
62
+
63
+ - Translate the **meaning for that screen**, not the words. A button is an action; a title is a noun phrase.
64
+ - **Placeholders** `{{name}}` are copied exactly, moved to where the grammar wants them. Never translate, rename or
65
+ drop one. (`{{count}}` may be omitted from a `_one` / `_zero` / `_two` form that spells the number out.)
66
+ - **Plural forms**: write every form the language has, each a full natural sentence. For es / pt / fr / it / ca the
67
+ `many` form (exact millions) is normally the `other` wording. Where a noun must agree with the number (Russian,
68
+ Polish, Arabic), make it agree; do not paste one form into all slots.
69
+ - **Length**: stay near the source length for buttons, tabs and labels. German, Russian, Finnish and Greek run 20–35%
70
+ longer: prefer the shorter natural wording. `max` in a note is a hard limit.
71
+ - **Register**: one form of address per language for the whole product, taken from `style.md` (for example informal
72
+ `du` / `tu` / `tú` in a children's game, polite form for payment and account screens if the brief says so).
73
+ - **Names and brands** in `keep` stay as written, in Latin letters, in every language.
74
+ - **Punctuation and typography of the target language**: full-width 、。!? in Japanese and Chinese; ¿…? ¡…! in
75
+ Spanish; in French a **no-break space (U+00A0)** before `: ; ! ?` (not a plain space, which lets the mark wrap
76
+ alone onto the next line, and not the narrow U+202F, which many game fonts lack; `check` warns about the plain
77
+ space); „…“ in German; no space before 。; the ellipsis character where the language uses it. Keep line breaks
78
+ (`\n`) and leading/trailing spaces as in the source.
79
+ - **Scripts**: zh-Hans and zh-Hant are different vocabularies as well as different characters (软件 / 軟體): translate
80
+ each, do not convert. pt-BR and pt-PT differ in wording and spelling.
81
+ - **Do not localise what the app formats**: digits, dates, prices and units arrive through placeholders already
82
+ formatted.
83
+ - **Digits written in the source sentence** keep their value. A whole number below 10,000 has no grouping mark in any
84
+ language (`1500`); from 10,000 up use the target language's grouping (`12,000` en, `12.000` de / vi, `12 000` fr
85
+ and ru with a no-break space). If the source itself has `1.500`, fix the source to `1500` first.
86
+ - **Culture**: replace an idiom by the natural expression of the target language; keep jokes only if they survive.
87
+ Nothing that reads as religious, political or rude in the target market.
88
+ - If a source text is itself wrong or unclear, do not translate around it: fix the source (or ask), then translate.
89
+
90
+ ## Voice lines (`"voice": true` in `todo`)
91
+
92
+ The line will be spoken by the voice in this language, so translate it for the ear as well as the eye:
93
+
94
+ - Short, natural spoken sentences. No abbreviations, symbols (`%`, `&`, `+`, `/`), emoji or brackets that a voice
95
+ would have to guess: write the words.
96
+ - Numbers as plain digits without a grouping mark, so the tool can read them.
97
+ - Japanese and Korean put counters on numbers (`3つ`, `105まい`, `3개`), and the counter changes how the number is
98
+ read. Write the natural sentence; the tool will then mark the line `blocked`, and the same pass that translated it
99
+ writes its spoken text:
100
+
101
+ ```bash
102
+ python <skill>/scripts/voice.py plan --lang ja # which lines are blocked, and why
103
+ python <skill>/scripts/voice.py say --lang ja --id game:say.reward "ほしを せんごひゃっこと コインを ひゃくごまい もらったよ!"
104
+ ```
105
+
106
+ `say` ties the spoken text to the shown text and checks that it says the same numbers ([numbers.md](numbers.md)).
107
+ - Changing the words of a voice line puts its clip one step behind the text: the clip must be remade, or kept on
108
+ purpose if the old words still fit ([voice.md](voice.md) §5). Do not reword a voiced line for taste alone.
109
+
110
+ ## Review before it counts
111
+
112
+ 1. `i18n.py check` with no errors; read every warning ("no … characters", "identical to the source", "Vietnamese
113
+ letters are left") and fix or consciously accept it.
114
+ 2. Self-review each batch once as a reader of that language: does every line sound like something a native app would
115
+ say on that screen?
116
+ 3. For the voice languages and the product's main markets, a second agent (fresh context) spot-checks a sample of
117
+ 30–50 texts by translating them back and comparing meaning. Disagreements are fixed, not averaged.
118
+ 4. Layout: after a language is first added, capture the main screens in that language (the product's screenshot
119
+ tests) and look for clipped or overflowing text. German and Russian find most overflow; Thai and CJK find most
120
+ font gaps.
121
+
122
+ ## Corrections from people
123
+
124
+ A person's correction outranks the agent's wording. Apply it and lock it:
125
+
126
+ ```bash
127
+ python <skill>/scripts/i18n.py apply fix.ja.json --lock
128
+ ```
129
+
130
+ A locked text is never overwritten by a later `apply` unless `--force` is passed, and `--force` needs the owner's
131
+ word. When the source of a locked text changes, it shows up as `stale` with `"locked": true` in `todo`: propose the
132
+ new translation to the owner instead of applying it silently.
133
+
134
+ ## Adopting translations that already exist
135
+
136
+ A project that already has translations shows them as `untracked`: present, but
137
+ never stamped against a source text. After checking that they match the current source, record that:
138
+
139
+ ```bash
140
+ python <skill>/scripts/i18n.py stamp --lang en # or --all
141
+ ```
142
+
143
+ From then on a source change marks exactly the affected texts `stale`.
@@ -0,0 +1,271 @@
1
+ # Voice
2
+
3
+ ## Contents
4
+ 1. Scope: voice is opt-in
5
+ 2. Where the voice comes from: the project's voice backend
6
+ 3. Declaring voice in a project
7
+ 4. The pipeline
8
+ 5. Text version and voice version: when the text changes first
9
+ 6. Rules on a voice server
10
+ 7. Checking every clip
11
+ 8. Files, formats, storage
12
+ 9. In the app
13
+
14
+ ## 1. Scope: voice is opt-in
15
+
16
+ - **Most products have no voice at all.** Text is the standard; voice is an option a few products add. A product
17
+ whose config has no `voice.languages` or no `voice.sets` has nothing to do with this file.
18
+ - Text and voice are separate. A product has text in up to 40 languages and voice in **zero to ten**, each with its
19
+ own version (section 5). Voice does not follow text one to one: a story game voices its dialogue, a game of
20
+ buttons voices nothing.
21
+ - Voice exists only for (a) the languages in `voice.languages` and (b) the lines selected by `voice.sets`. Both are
22
+ empty by default. **Do not add a language or a set because it seems useful: the owner names them.**
23
+ - The ten default voice languages: en, ja, es, pt-BR, ko, zh-Hans, de, fr, vi, id (`"voice": true` in the registry).
24
+ Another language needs three things first: a voice for it in the backend, a registry entry with `"voice": true`
25
+ (the project's `extraLanguages`), and number rules for it in `scripts/numwords.py`.
26
+
27
+ ## 2. Where the voice comes from: the project's voice backend
28
+
29
+ This skill ships no TTS engine and names none. A product with voice has **one voice backend** chosen by its owner
30
+ (a self-hosted TTS or voice-cloning server, or a hosted TTS service) and one voice family on it. The backend is
31
+ described where agents will read it: in the project's `SISYO.md`, or in a file that `SISYO.md` points to (for
32
+ example `docs/09_integrations/voice-backend.md`). In this file its address is written `<voice-host>`; the real
33
+ address, like any key, belongs in the project's private docs and environment, never in a shared skill.
34
+
35
+ **Before generating anything, read that description**, and the backend's own README if it has one. It must answer:
36
+
37
+ | Question | Why it matters |
38
+ |---|---|
39
+ | Address, and which endpoint is used for synthesis | so nothing else on the server is touched |
40
+ | Where the API key lives (an env file on the server, a secret store) | the key is never printed, copied or committed |
41
+ | The voice name for each language | goes into `voice.voicePattern` / `voice.voices`; a clip is tied to the voice that made it |
42
+ | Whose voice it is and under what consent or licence | what may be done with it: commercial use, which languages, what is forbidden |
43
+ | Endpoints and actions that are forbidden | on some servers a write to history or profiles destroys the owner's saved work |
44
+ | Capacity: what else runs on the machine, allowed concurrency, time windows | a bulk run must not starve other services |
45
+ | Who operates and restarts it | an agent does not |
46
+
47
+ If the description is missing or does not answer these, stop and ask the owner. Do not guess a backend, and do not
48
+ switch to another TTS service because the named one is unavailable.
49
+
50
+ Rules that hold for any backend:
51
+ - Choose the voice by the **language of the text**. A voice made for one language gives other languages an accent
52
+ and misreads them: a language without its own voice in the backend is not synthesised with another one. Ask the
53
+ owner.
54
+ - A cloned voice is a real person's. It is used only within their written consent. **Never export, upload, share or
55
+ re-encode the reference recordings or the voice profiles**, and never send them, or the voice, to another service.
56
+ Generated clips are product assets and may be published; the references may not. Never use the voice for fraud,
57
+ to impersonate the person, or to pass voice authentication.
58
+ - Label output as AI-generated where a law or platform requires it.
59
+ - No other voice or TTS service is used for shipped audio unless the owner says so for that product.
60
+
61
+ ## 3. Declaring voice in a project
62
+
63
+ `i18n.config.json`:
64
+
65
+ ```json
66
+ "voice": {
67
+ "languages": ["vi", "en", "ja"],
68
+ "fallback": "en",
69
+ "voicePattern": "Narrator-{lang}",
70
+ "sets": {
71
+ "common": { "include": ["voice:*"] },
72
+ "chapter01": { "include": ["chapter01:dlg.*", "chapter01:hint.*"], "exclude": ["chapter01:*.title"] }
73
+ },
74
+ "numberStyle": { "vi": { "four": "tư" } },
75
+ "format": "mp3"
76
+ }
77
+ ```
78
+
79
+ - A **voice line is a text key**. Its id is `ns:key`; its words are that key's translation. There is no second list
80
+ of sentences to keep in step.
81
+ - A **set** is a group of lines downloaded together (shared lines, one chapter, one feature). Patterns are shell-style
82
+ (`*`) on `ns:key`; a line belongs to the first set that matches. Keep a set to what one screen or chapter needs, so
83
+ the app downloads little at a time.
84
+ - `voicePattern`: the backend's voice name per language, with `{lang}` replaced by the language code (default
85
+ `{lang}`); `voices` (`{"pt-BR": "Narrator-pt"}`) overrides single languages. The voice name is part of every
86
+ clip's identity: changing it makes all clips of that language stale.
87
+ - `fallback`: the voice language used when the user's text language has no voice (`"en"`), or `"none"` for silence.
88
+ A product decision: for young children, hearing English under Thai text may be worse than no voice.
89
+ - **Spoken-text overrides** in `i18n/voice/speak/<lang>.json`, for a line whose spoken words differ from the shown
90
+ text (a number with a symbol or a counter, an abbreviation, a name that needs a phonetic spelling, "v2.0"). Write
91
+ them with `voice.py say`, which ties each one to the shown text and checks its numbers
92
+ ([numbers.md](numbers.md)):
93
+
94
+ ```json
95
+ { "game:say.reward": { "text": "<the shown text it was written for>", "speak": "<what is said, no digits>" } }
96
+ ```
97
+ - A plural key or a text with a `{{placeholder}}` cannot be one clip. Give it fixed spoken words with `say`, split
98
+ it into fixed lines, or leave it out of the set.
99
+ - **A new spoken line the owner asked for** goes where an existing set's pattern selects it (name the key to match,
100
+ for example `game:say.reward` for the set `game:say.*`), or the set's `include` gains a pattern for it. That is
101
+ filling a set the owner already has, not adding one. A new set, or voice for lines nobody asked voice for, is the
102
+ owner's call.
103
+
104
+ ## 4. The pipeline
105
+
106
+ ```bash
107
+ python <skill>/scripts/voice.py plan # per language and set: ready / behind / new / stale / blocked
108
+ python <skill>/scripts/voice.py say --lang ja --id ns:key "…" # settle each blocked line (or fix its shown text)
109
+ python <skill>/scripts/voice.py plan --lang vi --out todo.vi.json # the lines to make, with speak text and numbers
110
+ # make and check the clips with the project's voice tool (sections 6 and 7)
111
+ python <skill>/scripts/voice.py add --lang vi --map clips.vi.json # register them
112
+ python <skill>/scripts/voice.py pack # sets + voice manifest for the CDN
113
+ ```
114
+
115
+ These tools never talk to a voice backend. They decide **what** must be said and keep the record; making the audio
116
+ is the project's own voice tool.
117
+
118
+ `plan` gives each line a state:
119
+
120
+ | State | Meaning | Do |
121
+ |---|---|---|
122
+ | `ok` | a registered clip matches the current spoken text and voice | nothing |
123
+ | `missing` | no clip yet | synthesise |
124
+ | `behind` | the text changed a little and someone decided the old clip still fits (`voice.py keep`): it keeps playing | synthesise again when voice is next updated |
125
+ | `stale` | the spoken text (or the voice name) changed since the clip was made, and nobody has decided: the line is left out, so it is silent | decide: `voice.py keep`, or synthesise again (section 5) |
126
+ | `blocked` | the spoken text is unsettled: a number or symbol the tool will not guess, a placeholder, an override written for an older text or one that does not say the text's numbers ([numbers.md](numbers.md)) | fix the shown text, or `voice.py say` |
127
+ | `untranslated` | the text in that language is missing or stale | translate first |
128
+
129
+ **Run `voice.py pack` every time `i18n.py pack` runs** (text first, then voice), also when no clip could be made
130
+ yet. Only lines in state `ok` or `behind` go into a set; `voice.py pack` prints which lines are behind and which are
131
+ silent, and refuses to run if the text was edited after the last text pack.
132
+
133
+ `todo.<lang>.json` holds, per line: `id`, `set`, `text` (shown), `speak` (sent to the voice: no digits), `numbers`
134
+ (for the check), `speakHash`, `textHash`, `voice`. The answer for `add` maps ids to clips and repeats the hash, so a
135
+ clip made from an old text is refused:
136
+
137
+ ```json
138
+ { "chapter01:dlg.elder.0": { "file": "out/c01_dlg_elder_0.mp3", "speakHash": "79fc6ec7d1f8d17e", "checked": "whisper-large-v3: words ok, numbers ok" } }
139
+ ```
140
+
141
+ Order of work when the owner asks for voice in a new language or set:
142
+ 1. Text for those lines translated and reviewed (`i18n.py status`).
143
+ 2. `voice.py plan`: clear every `blocked` line.
144
+ 3. **A listening sample first**: about 30 lines per language, chosen to include numbers, questions, names and the
145
+ longest line. Give the owner the clips to listen to. Bulk generation starts only after the owner says the sample
146
+ is good.
147
+ 4. Bulk run in small jobs with the guards of section 6, resumable, every take checked (section 7).
148
+ 5. `add`, `pack`, upload (the owner approves publishing), then the app-side work if it is a new language.
149
+
150
+ **When the sample is needed.** A new voice language, a new set, a new or changed voice, or any run of more than
151
+ about 50 clips: sample first, then the owner's word. A few new or reworded lines in a language and set the owner has
152
+ already approved go straight through the per-clip checks; tell the owner which lines were made so they can listen.
153
+
154
+ ## 5. Text version and voice version: when the text changes first
155
+
156
+ Text is cheap to change and voice is not, so text regularly moves ahead of voice. The two are versioned separately
157
+ and the link between them is recorded:
158
+
159
+ | What | Where | Meaning |
160
+ |---|---|---|
161
+ | text `version` of a language | `i18n/manifest.json` | bumps when that language's texts change (`i18n.py pack`) |
162
+ | voice `version` of a set | `i18n/voice/manifest.json` | bumps when that set's clips or their accepted texts change (`voice.py pack`) |
163
+ | `textVersion` of a voice language | `i18n/voice/manifest.json` | the text version the voice sets were packed for |
164
+ | per set: `clips`, `lines`, `behind`, `silent` | `i18n/voice/manifest.json` | how far the set is from complete and current |
165
+ | per clip: `textHash`, `textVersion`, `keptFor` | `i18n/voice/<lang>/manifest.json` | the text a clip was recorded for, and the later text it was kept for |
166
+
167
+ ```
168
+ $ python <skill>/scripts/i18n.py versions
169
+ mygame: compat 1, text revision 14 (…), voice revision 6 (…)
170
+ lang text state voice set voice for text clips behind silent
171
+ vi v12 ready common v4 v12 140/141 1 1
172
+ chapter01 v3 v12 135/135 0 0
173
+ en v12 ready common v4 v11 ! …
174
+ ko v9 ready -
175
+ ```
176
+
177
+ `*` after a text version: the files were edited since the last text pack. `!`: the voice sets were packed for an
178
+ older text version (run `voice.py pack`).
179
+
180
+ **What happens to a voiced line when its text changes** (in that language), before anyone remakes the clip:
181
+
182
+ | The change | State | In the app | Do |
183
+ |---|---|---|---|
184
+ | Only punctuation, case or spacing: the same words | `ok` | the clip plays | nothing |
185
+ | A small rewording the old audio still fits: nobody listening would be misled ("Xin chào các bạn nhỏ!" → "Xin chào các bạn!") | `stale` until decided, then `behind` | the old clip keeps playing | `voice.py keep --lang L --id ns:key --why "…"`; remake it with the next voice update |
186
+ | The audio would now be wrong: another instruction, name, answer or direction; a sentence added or removed | `stale` | silent | leave it; synthesise again |
187
+ | A number changed | `stale` | silent | synthesise again. `keep` refuses: a clip that says another number is never kept |
188
+
189
+ The agent that changes the text makes this decision in the same piece of work, by reading "clip says / text now" in
190
+ `voice.py plan`, and reports both lists (kept, silent) to the owner. When unsure, do not keep: a silent line is a
191
+ smaller fault than a voice that says something the screen does not. `keep --undo` takes a decision back. A new clip
192
+ (`add`) ends the lag, and a further change to the text ends an earlier `keep`.
193
+
194
+ Publishing: text and voice are uploaded together (voice files first, then the text manifest). If lines would go
195
+ out silent, the owner chooses between waiting for the clips and publishing now; say which lines.
196
+
197
+ ## 6. Rules on a voice server
198
+
199
+ A self-hosted voice server is usually shared: the same GPU serves other things, and the server keeps the owner's
200
+ saved takes and voice profiles. A careless bulk run can wipe saved work or get the voice process killed for lack of
201
+ memory. The backend's own rules (section 2) come first; where they are silent, these hold:
202
+
203
+ - **Use only the stateless synthesis endpoint** the backend's rules name (on an OpenAI-compatible server:
204
+ `POST <voice-host>/v1/audio/speech` with `model`, `voice`, `input`, `response_format`). Stay away from endpoints
205
+ that write history, profiles or presets, and from reference uploads: on some servers every history row pushes out
206
+ an older take and its audio.
207
+ - **One request at a time**, with a lock, in small jobs with pauses. Before each job check free RAM and GPU memory;
208
+ stop on an out-of-memory answer, on repeated 5xx answers or timeouts, or if something the run must not change has
209
+ changed. Fail closed: if a guard cannot be read, do not generate.
210
+ - Never restart, reconfigure, `docker exec` into or install anything on the voice server. If it needs a restart,
211
+ tell the owner.
212
+ - The API key stays where the backend's description says it lives: read it into memory there, never print, copy or
213
+ commit it.
214
+ - Recognition and scoring (section 7) run on the agent's own machine, on CPU, not on the voice server's GPU.
215
+ - Bulk runs happen in the time window the owner gives.
216
+ - A hosted, paid TTS service: count the characters first (a dry run) and get the owner's word on the spend.
217
+
218
+ A project that already has a voice tool with these guards uses it. A new project copies the guards before it writes
219
+ its first request loop: they are the part that incidents taught.
220
+
221
+ ## 7. Checking every clip
222
+
223
+ A clip is registered with `add` only after it passed, per take:
224
+
225
+ 1. **Words**: a recogniser (Whisper large-v3 on CPU; plus a language-specific one where available) hears the line.
226
+ Names and invented words are compared loosely, everything else strictly.
227
+ 2. **Numbers**: `numwords.heard(numbers, transcript, lang)` is true ([numbers.md](numbers.md)). No exceptions.
228
+ 3. **Language**: the recogniser's language-ID probability for the target language is at least 0.8 (catches an accent
229
+ from the wrong voice).
230
+ 4. **Shape**: no silence longer than about 1 s inside the line; duration plausible for its length; numbers and
231
+ questions not rushed.
232
+ 5. **Loudness**: normalised to the product's level so languages and sets match.
233
+
234
+ Take the best of up to three seeds; a line that still fails is rewritten or reported, never shipped. Record in the
235
+ `add` map what was checked (`"checked": "whisper-large-v3 wer 0, numbers ok"`): it is stored with the clip.
236
+
237
+ After a set is complete, listen to a few assembled sequences as the user will hear them (a question followed by its
238
+ answer, two dialogue lines in a row): single clips can each pass and still not fit together.
239
+
240
+ ## 8. Files, formats, storage
241
+
242
+ - One encoded format per product (`voice.format`): `mp3` mono, about 48–64 kbit/s plays everywhere (Unity, web, iOS,
243
+ Android). `ogg` is an option for a Unity-only product.
244
+ - `i18n/voice/<lang>/manifest.json` (git): for every clip its spoken text, `speakHash`, voice, SHA-256, size, date.
245
+ - Audio itself is **not in git**: `i18n/voice/_audio/` is a local cache; the durable copy is the CDN bucket, where
246
+ clips are named by their content (`voice/clips/<lang>/<sha16>.mp3`) and so never overwritten. Lossless WAV takes may
247
+ be kept under a private prefix such as `voice-master/`.
248
+ - `voice.py pack` writes, per language and set, an index `voice/c<compat>/<lang>/<set>.<hash12>.json`
249
+ (`{"clips": {"ns:key": {"file": "<sha16>.mp3", "bytes": 12345, "text": ["<hash of a shown text>", …]}}}`), copies
250
+ the clips it has locally to `dist/voice/clips/`, writes `voice/c<compat>/manifest.json` (per language
251
+ `textVersion`; per set `version`, `hash`, `file`, `lines`, `clips`, `behind`, `silent`, `bytes`, `complete`) and
252
+ `dist/upload-plan.voice.json`. Upload order: clips, indexes, the manifest last
253
+ ([layout-and-versioning.md](layout-and-versioning.md), sections 7 and 8).
254
+ - Voice clips that already ship inside an app may stay there; new languages go to the CDN only.
255
+
256
+ ## 9. In the app
257
+
258
+ - Voice language is its own setting: the text language if it has voice, else `fallback`.
259
+ - **Lazy download**: when a set is first needed (the user opens chapter 1 in Spanish), fetch the voice manifest, then
260
+ the set's index, then its clips (a few in parallel), verifying sizes; show progress and the size before a large
261
+ download. Play from the local copy. A set counts as ready when all its clips are present.
262
+ - **A clip is played only with a text it was made or kept for.** Each index entry carries `text`: a list of
263
+ hashes, each the first 12 hex characters of the SHA-256 of a shown text (UTF-8, NFC). The list holds the text the
264
+ clip was recorded for and, after `keep` or a punctuation-only change, the current text. Before playing, the app
265
+ hashes the text it is showing for that key and plays the clip only if the hash is in the list. Text packs and
266
+ voice sets update separately, so without this an app could show one wording and speak another. Test vector:
267
+ `"Xin chào các bạn nhỏ!"` → `7fedecb3477a`.
268
+ - A line without a matching clip is shown without sound; the app never plays another language's clip for a single
269
+ line in the middle of a set.
270
+ - A newer set version re-downloads only the clips whose file name changed. Remove clips no index refers to any more.
271
+ - Keep text and voice in step: the index is keyed by `ns:key`, the same id the text uses.