Skip to content

Commit e3a3efe

Browse files
Fix pronouncation
1 parent 0fe1495 commit e3a3efe

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

scripts/generate-tts/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ cd scripts/generate-tts
1515
npm run voices # list available macOS voices
1616
npm run generate # generate WAV files into sd-card/
1717
npm run generate -- --voice Alex --rate 170
18-
npm run generate -- --force # regenerate existing files
18+
npm run generate -- --force # regenerate existing files (needed after voice/TTS fixes)
1919
```
2020

21+
Single letters and digits use macOS `[[char U+....]]` notation so `say` pronounces "A" instead of "Capital A". Optional per-entry `"speak"` in the manifest overrides that text.
22+
2123
Copy the generated `sd-card/` folder contents to the root of a FAT32 microSD card, then insert the card into the CoreS3.

scripts/generate-tts/generate.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,29 @@ function usageToFilename(usageHex) {
4343
return `u${value.toString(16).padStart(3, "0")}.wav`;
4444
}
4545

46-
function runSay(label, voice, rate, aiffPath) {
46+
/** Text passed to macOS `say` (avoids e.g. "Capital A" for label "A"). */
47+
function speakTextForEntry(entry) {
48+
if (entry.speak) {
49+
return entry.speak;
50+
}
51+
const { label } = entry;
52+
if (label.length === 1) {
53+
const code = label.toUpperCase().charCodeAt(0);
54+
if (
55+
(code >= 0x41 && code <= 0x5a) ||
56+
(code >= 0x30 && code <= 0x39)
57+
) {
58+
return `[[char U+${code.toString(16).padStart(4, "0").toUpperCase()}]]`;
59+
}
60+
}
61+
return label;
62+
}
63+
64+
function runSay(entry, voice, rate, aiffPath) {
65+
const text = speakTextForEntry(entry);
4766
spawnSync(
4867
"say",
49-
["-v", voice, "-r", String(rate), "-o", aiffPath, label],
68+
["-v", voice, "-r", String(rate), "-o", aiffPath, text],
5069
{ stdio: "inherit" }
5170
);
5271
}
@@ -95,7 +114,7 @@ function main() {
95114

96115
const aiffPath = path.join(tmpDir, `${filename}.aiff`);
97116
console.log(`Generating ${entry.label} -> ${filename}`);
98-
runSay(entry.label, args.voice, args.rate, aiffPath);
117+
runSay(entry, args.voice, args.rate, aiffPath);
99118
convertToWav(aiffPath, wavPath);
100119
fs.unlinkSync(aiffPath);
101120
created += 1;

0 commit comments

Comments
 (0)