mirror of
https://github.com/D-Modem/speaking-clock.git
synced 2026-11-28 12:38:05 -08:00
macintalk: speak the PlainTalk voices Agnes, Bruce and Victoria
The PlainTalk (MacinTalk Pro) voices are recorded diphones. plaintalk.c reads a voice's 'gtss' 3 data: the two 50 x 50 diphone tables, the period lengths, the codebook, and the coded periods, each the signal a period plus a lag back plus gain times codebook vectors. It joins the half-diphones with the text front end, timing and pitch macintalk already has. docs/plaintalk-format.md describes the data; no Apple code is used. tools/fetch-macintalk.py also fetches a Mac OS 8.6 disk image from the Internet Archive (pinned by SHA-256; it needs unar or unrar to unpack) and writes agnes.gtss, bruce.gtss and victoria.gtss. The high quality voices are coded differently and are left out for now. tools/synth_voices.py gets a plaintalk engine, and voices/ the three live-plaintalk-* voices. Whisper (base.en) gets the clock sentence word for word from all three; over ten test sentences about 30-40% of words are wrong. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRRAKCKq1gSHpownvFE
This commit is contained in:
15 files changed
+851
-59
No files matched your search
@@ -105,3 +105,11 @@ voices, belong to their owners:
|
||||
the Internet Archive. MacInTalk and Macintosh are trademarks of Apple
|
||||
Inc. The letter-to-sound rules in `synth/macintalk/rules.h` are from NRL
|
||||
Report 7948 (1976), a US government work in the public domain.
|
||||
- **PlainTalk, live** (`live-plaintalk-*`): no recordings in this
|
||||
repository. Each sentence is spoken on the Asterisk machine by the same
|
||||
`synth/macintalk`, which joins the recorded diphones of Apple's PlainTalk
|
||||
(MacinTalk Pro) voices Agnes, Bruce and Victoria. Those recordings are
|
||||
Apple's (© Apple Computer, Inc. 1992-1998) and are not in this
|
||||
repository: `tools/fetch-macintalk.py` downloads them from a Mac OS 8.6
|
||||
disk image on the Internet Archive. PlainTalk is a trademark of Apple
|
||||
Inc.
|
||||
@@ -75,10 +75,12 @@ Asterisk machine for each announcement's whole sentence ("At the third
|
||||
stroke, it will be four fifteen and twenty seconds."), a little ahead of
|
||||
when it is needed, so the call never waits on it. The `live-dectalk-*` and
|
||||
`live-sam-*` voices run DECtalk's `say` and `sam`. The `live-macintalk-*`
|
||||
voices (Fred, Ralph, Kathy, Zarvox and the other 15 MacInTalk 3 voices) run
|
||||
voices (Fred, Ralph, Kathy, Zarvox and the other 15 MacInTalk 3 voices) and
|
||||
the `live-plaintalk-*` voices (Agnes, Bruce and Victoria) run
|
||||
[synth/macintalk](synth/macintalk), our own synthesiser, which reads
|
||||
Apple's voice data (`cd synth/macintalk && make && make voices && sudo make
|
||||
install` builds it and fetches the data). Set where they are in
|
||||
install` builds it and fetches the data; the PlainTalk voices also need
|
||||
`unar` or `unrar` to unpack their disk image). Set where they are in
|
||||
speakingclock.conf:
|
||||
|
||||
```
|
||||
@@ -125,6 +127,7 @@ tools/synth_voices.py voices mac:Fred # MacInTalk, on a Mac
|
||||
tools/synth_voices.py voices mac:Victoria # PlainTalk, on a Mac
|
||||
tools/synth_voices.py voices macintalk:fred # MacInTalk 3, synth/macintalk
|
||||
tools/synth_voices.py --live voices macintalk:zarvox # live-macintalk-zarvox
|
||||
tools/synth_voices.py --live voices plaintalk:agnes # live-plaintalk-agnes
|
||||
```
|
||||
|
||||
## Licence
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
|
||||
; The live DECtalk, SAM and MacInTalk voices run the synthesiser on this
|
||||
; machine, with no server. Default: dectalk, sam and macintalk, found on
|
||||
; the PATH. macintalk is synth/macintalk in this repository.
|
||||
; the PATH. macintalk is synth/macintalk in this repository (it speaks the
|
||||
; MacInTalk 3 and the PlainTalk voices).
|
||||
;tts_program_dectalk=/opt/dectalk/say
|
||||
;tts_program_sam=/usr/local/bin/sam
|
||||
;tts_program_macintalk=/usr/local/bin/macintalk
|
||||
|
||||
@@ -158,4 +158,6 @@ not. Apple's own rules and dictionary (`ttvi` 3 to 7) could be decoded the
|
||||
same way later.
|
||||
|
||||
The PlainTalk voices (MacInTalk Pro: Victoria, Agnes, Bruce) are recorded
|
||||
diphones, a different kind of synthesiser, and are not on this disk.
|
||||
diphones, a different kind of synthesiser, and are not on this disk. They
|
||||
come from a Mac OS 8.6 disk image instead; see
|
||||
[plaintalk-format.md](plaintalk-format.md).
|
||||
@@ -0,0 +1,146 @@
|
||||
# PlainTalk voice files
|
||||
|
||||
What `synth/macintalk` knows about Apple's PlainTalk voices (MacinTalk Pro
|
||||
1.5: Agnes, Bruce and Victoria). It was worked out from the voices' data
|
||||
alone: by reading the tables, decoding the sound and checking the result
|
||||
by ear and with a speech recogniser. No Apple code was run, emulated,
|
||||
disassembled or read to find it.
|
||||
|
||||
## Where the files are
|
||||
|
||||
`tools/fetch-macintalk.py` downloads a Mac OS 8.6 hard disk image for the
|
||||
SheepShaver emulator from the Internet Archive:
|
||||
<https://archive.org/details/MacOS8.6Image-SheepShaverEmulator>, file
|
||||
`Mac OS 8.6 on disk image + SheepShaver.exe` (SHA-256
|
||||
`003910efa3fc95a9c0da3f064e0e9aafafd9c2b20b11fde2e01d2f8fd9472c92`). It is
|
||||
a self-extracting RAR archive (RAR 2.9 compression), which `unar` or
|
||||
`unrar` unpacks; the script takes only `SheepShaver/Mac_OS_HD.dsk` out of
|
||||
it, a 500 MB HFS volume. The voices are in `System Folder:Extensions:
|
||||
Voices`, files of type `ttvf` and creator `gala`, with an empty data fork
|
||||
and these resources:
|
||||
|
||||
| Resource | What it is |
|
||||
|---|---|
|
||||
| `gtss` 3 "Engl…Data" | the recorded sound and its tables (below) |
|
||||
| `gtss` 4 "Engl…Code" | 68k code: not extracted, not used |
|
||||
| `ttvd` | the Speech Manager's `VoiceDescription` (name, gender, age) |
|
||||
| `gtsv`, `gtsg`, `gtsm`, `gtsi` | small tables that tie the parts together |
|
||||
| `vers`, `STR `, `ftag` | version 1.4.2, "English Text-To-Speech 1.5.3", © 1992-98 |
|
||||
|
||||
The script writes each voice's `gtss` 3 to `<voice>.gtss` (`agnes.gtss`,
|
||||
`bruce.gtss`, `victoria.gtss`). The three "high quality" voices code their
|
||||
sound differently (see the end) and are left out for now.
|
||||
|
||||
The MacinTalk Pro extension itself holds the English text rules and
|
||||
dictionary (`gtst`), the phoneme and allophone lists (`gtsp`, `gtsa`) and
|
||||
the code (`gtse`). Only the allophone names in `gtsa` 2 were read, to name
|
||||
the sounds below.
|
||||
|
||||
## `gtss` 3
|
||||
|
||||
All big-endian. A 16-byte header, then twelve 32-bit offsets of sections
|
||||
0 to 11 (from the start of the resource).
|
||||
|
||||
| Header word | Agnes, Bruce, Victoria | What it is |
|
||||
|---|---|---|
|
||||
| 0 | 50 | the number of wave-phonemes (the tables are 50 × 50) |
|
||||
| 1, 2 | 100, 185, 125 | the speaker's typical pitch period, samples at 22050 Hz |
|
||||
| 4 | 5739, 3922, 7804 | unknown |
|
||||
| 7 | 0x0702 (high quality: 0x0403) | the coding |
|
||||
|
||||
| Section | Size (Agnes) | What it is |
|
||||
|---|---|---|
|
||||
| 0 | 20000 | first halves of the diphones: 2500 entries of 8 bytes, entry 50 × left + right |
|
||||
| 1 | 20000 | second halves, the same way |
|
||||
| 2 | 256668 | the voiced first halves (left sound 0 to 30) |
|
||||
| 3 | 280676 | the voiced second halves (right sound 0 to 30) |
|
||||
| 4 | 120688 | the consonant first halves (left sound 31 to 49) |
|
||||
| 5 | 114716 | the consonant second halves |
|
||||
| 6 | 19764 | period lengths of the units in section 2: 16-bit, each unit's list ends with 0xffff |
|
||||
| 7 | 21668 | period lengths of the units in section 3 |
|
||||
| 8 | 52 | a class for each wave-phoneme: 0, 1 (vowels and sonorants) or 2 (f, th, s, sh) |
|
||||
| 9 | 172 | for each of the 86 allophones, its wave-phoneme and a second one (for ch, j and syllabic consonants) |
|
||||
| 10 | 2048 | the codebook: 256 vectors of 4 signed 16-bit samples |
|
||||
| 11 | 352 | unknown (the same in every voice) |
|
||||
|
||||
### The wave-phonemes
|
||||
|
||||
Section 9 maps the allophone names of `gtsa` 2 to these:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 0, 1 | silence, breath |
|
||||
| 2 to 22 | IY IH IX EH AE UX AX AA AO UH UW OW ER IR AR OR UR AY EY OY AW |
|
||||
| 23 to 30 | syllabic l, l, m, n, N (ng), y, r, w |
|
||||
| 31 to 37 | b d g v D z Z |
|
||||
| 38 to 42 | f T s S h |
|
||||
| 43 to 49 | p, p after s, t, t after s, glottal stop, k, k after s |
|
||||
|
||||
IR, AR, OR and UR are the vowels before r. Syllabic m and n are UX or UH
|
||||
plus m or n, ch is t plus sh and j is d plus zh.
|
||||
|
||||
### The diphone tables
|
||||
|
||||
Entry *left* × 50 + *right* of section 0 says where the first half of the
|
||||
diphone *left*–*right* is (from the middle of *left* to the boundary), and
|
||||
the same entry of section 1 where its second half is (from the boundary to
|
||||
the middle of *right*). An entry is two 32-bit words:
|
||||
|
||||
- `0xffffffff, …`: no such diphone.
|
||||
- `0x0000ffff, (l << 16) | r`: use diphone *l*–*r* instead.
|
||||
- otherwise the unit's offset in its section divided by 4, then a second
|
||||
word: for a voiced unit a running count of the frames before it in its
|
||||
section, for a consonant unit the number of whole frames (high half)
|
||||
and a value up to about 120 (low half, unknown).
|
||||
|
||||
A half whose sound (the left one in section 0, the right one in section 1)
|
||||
is a consonant, wave-phoneme 31 or more, is in section 4 or 5; the others
|
||||
are in 2 or 3. Silence has no halves of its own.
|
||||
|
||||
### A unit
|
||||
|
||||
Each unit starts on a 4-byte boundary with one byte (unknown, mostly 100 to
|
||||
170), then frames. A frame codes one pitch period, resampled to *N*
|
||||
samples, where *N* is 96 for Agnes and Victoria and 160 for Bruce (it is not
|
||||
in the header; it is the frame size that makes all the units parse):
|
||||
|
||||
| Bytes | |
|
||||
|---|---|
|
||||
| 1 | the gain *A*: a 4-bit exponent and 4-bit mantissa, gain = (16 + (*A* & 15)) × 2^(*A* >> 4) / 256. Its top bit is clear. |
|
||||
| 1 | the lag *B* |
|
||||
| *N* / 4 | codebook indices |
|
||||
|
||||
The period is the unit's signal one period plus *B* − 1 samples back
|
||||
(predicted from what came before in the same unit, period by period) plus
|
||||
the gain times the codebook vectors, one vector for each 4 samples. The
|
||||
first frame of a unit has nothing before it, low nibble 0 in *A* and *B* = 1.
|
||||
Lags of 50 and more turn up in noisy and changing frames; what they mean
|
||||
exactly is not certain, and taking them as plain lags works.
|
||||
|
||||
The last frame is shorter: its first byte has the top bit set and the low
|
||||
7 bits are its number of indices, then the lag and the indices, then one
|
||||
more byte (it looks like a gain), then padding to the next 4-byte
|
||||
boundary. It is probably the part of a period up to the diphone's
|
||||
boundary; `synth/macintalk` leaves it out.
|
||||
|
||||
A voiced unit's whole frames are its periods, and section 6 or 7 gives
|
||||
each one's length as recorded. Consonant units have no such list; their
|
||||
frames are taken as one typical period (header word 1) long.
|
||||
|
||||
## How `synth/macintalk` uses it
|
||||
|
||||
The text front end, timing and pitch are the same as for the MacInTalk 3
|
||||
voices. Each phoneme becomes a wave-phoneme (with the r-coloured vowels,
|
||||
and p, t, k after s), and is made of the second half of the diphone from
|
||||
the phoneme before it and the first half of the diphone into the phoneme
|
||||
after it. Frames are repeated or dropped to give the phoneme its length,
|
||||
and each voiced period is resampled from *N* samples to the period the
|
||||
pitch wants (the coding makes this the natural way to change the pitch;
|
||||
it also moves the formants a little). The rest of the voice, Apple's
|
||||
rules for the timing and the pitch, is not used.
|
||||
|
||||
## Not done
|
||||
|
||||
- The "high quality" voices code 2 samples per codebook vector (a 1024-byte
|
||||
codebook) and their last frames are not marked the same way.
|
||||
- The unit's first byte, the end byte, header word 4 and section 11.
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# make build macintalk
|
||||
# make voices fetch Apple's MacInTalk 3 voice data (about 50 MB download)
|
||||
# make voices fetch Apple's voice data (MacInTalk 3 and PlainTalk, about 180 MB download)
|
||||
# make install install the program and the voices
|
||||
# make test speak a sentence with every voice
|
||||
PREFIX ?= /usr/local
|
||||
@@ -9,7 +9,7 @@ CC ?= cc
|
||||
CFLAGS ?= -O2 -Wall -Wextra -Wno-missing-field-initializers
|
||||
SOURCES ?= ../../sources/macintalk
|
||||
|
||||
macintalk: macintalk.c rules.h
|
||||
macintalk: macintalk.c plaintalk.c rules.h
|
||||
$(CC) $(CFLAGS) -o $@ macintalk.c -lm
|
||||
|
||||
voices: $(SOURCES)/fred.ttvd
|
||||
@@ -21,6 +21,7 @@ install: macintalk voices
|
||||
install -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(VOICEDIR)
|
||||
install -m 755 macintalk $(DESTDIR)$(PREFIX)/bin/macintalk
|
||||
install -m 644 $(SOURCES)/*.ttvd $(SOURCES)/*.ttvw $(DESTDIR)$(VOICEDIR)/
|
||||
for f in $(SOURCES)/*.gtss; do [ ! -f "$$f" ] || install -m 644 "$$f" $(DESTDIR)$(VOICEDIR)/; done
|
||||
|
||||
test: macintalk voices
|
||||
@for v in $$(./macintalk -d $(SOURCES) -l | cut -d' ' -f1); do \
|
||||
|
||||
@@ -4,13 +4,16 @@ A speech synthesiser for Linux that speaks with the MacInTalk 3 voices of
|
||||
classic Mac OS: Fred, Ralph, Kathy, Junior, Princess, Zarvox, Trinoids,
|
||||
Whisper, the singing voices (Cellos, Pipe Organ, Good News, Bad News) and
|
||||
the novelty ones (Bells, Boing, Bubbles, Albert, Bahh, Deranged,
|
||||
Hysterical).
|
||||
Hysterical). It also speaks with the PlainTalk voices Agnes, Bruce and
|
||||
Victoria, by joining their recorded diphones.
|
||||
|
||||
It is a clean-room program. It has no Apple code and doesn't run, emulate or
|
||||
load any. It reads only the voices' data, which `tools/fetch-macintalk.py`
|
||||
takes from a Mac OS 8.1 disk image on the Internet Archive when you build
|
||||
it. Apple's files are not in this repository. See
|
||||
[docs/macintalk-format.md](../../docs/macintalk-format.md) for what the
|
||||
takes from Mac OS 8.1 and 8.6 disk images on the Internet Archive when you
|
||||
build it (the 8.6 one is a RAR archive: install `unar` or `unrar`, or the
|
||||
PlainTalk voices are skipped). Apple's files are not in this repository.
|
||||
See [docs/macintalk-format.md](../../docs/macintalk-format.md) and
|
||||
[docs/plaintalk-format.md](../../docs/plaintalk-format.md) for what the
|
||||
voice data holds and what is ours.
|
||||
|
||||
```
|
||||
@@ -20,6 +23,7 @@ sudo make install # /usr/local/bin/macintalk, /usr/local/share/macintalk
|
||||
|
||||
macintalk -l
|
||||
macintalk -v zarvox -o zarvox.wav "That looks like a peaceful planet."
|
||||
macintalk -v victoria -o victoria.wav "Hello, my name is Victoria."
|
||||
macintalk -v fred "At the third stroke, it will be ten oh five." | aplay
|
||||
```
|
||||
|
||||
@@ -37,9 +41,9 @@ Apple's phoneme symbols (`1EHkspIHrIHmEHnt`), `[[inpt TEXT]]` back,
|
||||
|
||||
## For the speaking clock
|
||||
|
||||
The `live-macintalk-*` voices in `voices/` run this program for each
|
||||
sentence (docs/voice-format.md, mode=tts). Install it, then, if it isn't on
|
||||
Asterisk's PATH, tell speakingclock.conf where it is:
|
||||
The `live-macintalk-*` and `live-plaintalk-*` voices in `voices/` run this
|
||||
program for each sentence (docs/voice-format.md, mode=tts). Install it,
|
||||
then, if it isn't on Asterisk's PATH, tell speakingclock.conf where it is:
|
||||
|
||||
```
|
||||
tts_program_macintalk=/usr/local/bin/macintalk
|
||||
@@ -68,3 +72,9 @@ The voice data must be in one of the default folders (or set
|
||||
|
||||
Pronunciation and rhythm are ours, so the voices sound like MacInTalk 3's
|
||||
voices rather than exactly like them.
|
||||
|
||||
The PlainTalk voices (plaintalk.c) share steps 1 to 3. Then each phoneme is
|
||||
the second half of a recorded diphone into it and the first half of one out
|
||||
of it, decoded from the voice's codebook, stretched to its length by
|
||||
repeating or dropping periods, and each voiced period is resampled to the
|
||||
pitch. Their high quality versions aren't supported yet.
|
||||
@@ -1,7 +1,8 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*
|
||||
* macintalk: a speech synthesiser that speaks with the MacInTalk 3 voices
|
||||
* (Fred, Ralph, Kathy, Zarvox ...) of classic Mac OS.
|
||||
* (Fred, Ralph, Kathy, Zarvox ...) and the PlainTalk voices (Agnes, Bruce,
|
||||
* Victoria) of classic Mac OS.
|
||||
*
|
||||
* This is a clean-room program. It contains no Apple code and does not
|
||||
* run, emulate or load any. It reads only the voices' data, the 'ttvd'
|
||||
@@ -14,6 +15,11 @@
|
||||
* gives the synthesiser its pitch, speed, glottal source spectrum, formant
|
||||
* and bandwidth settings, breathiness, chorus, melody and sampled sound.
|
||||
*
|
||||
* The PlainTalk voices are recorded diphones instead (plaintalk.c,
|
||||
* docs/plaintalk-format.md): for them the same text front end, timing and
|
||||
* pitch drive a diphone joiner that reads the voice's 'gtss' 3 data, taken
|
||||
* from a Mac OS 8.6 disk image.
|
||||
*
|
||||
* macintalk [-v voice] [-d voicedir] [-o out.wav] [-r wpm] [-p hz] text...
|
||||
* macintalk -l [-d voicedir] list the voices
|
||||
* macintalk -x [-v voice] text... print the phonemes, make no sound
|
||||
@@ -37,6 +43,7 @@
|
||||
#define FS 22050
|
||||
#define NHARM 47
|
||||
#define MAXSEG 4096
|
||||
#define PT_RATE 175 /* words per minute for the PlainTalk voices */
|
||||
#define BLOCK 32 /* samples between parameter updates */
|
||||
|
||||
static double frand(void)
|
||||
@@ -1162,6 +1169,8 @@ static float *synth(const struct voice *v, double base, int *nout)
|
||||
return out;
|
||||
}
|
||||
|
||||
#include "plaintalk.c"
|
||||
|
||||
/* ---- output ---------------------------------------------------------------- */
|
||||
|
||||
static void put16(FILE *f, int v) { fputc(v & 0xff, f); fputc((v >> 8) & 0xff, f); }
|
||||
@@ -1225,6 +1234,8 @@ int main(int argc, char **argv)
|
||||
double rate = 0, pitch = 0;
|
||||
int list = 0, show = 0, i, n;
|
||||
struct voice v;
|
||||
struct ptvoice ptv;
|
||||
int pt = 0;
|
||||
float *pcm;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
@@ -1270,6 +1281,13 @@ int main(int argc, char **argv)
|
||||
printf("%-12s %-12s %3d Hz %3d wpm %s\n", id, v.name, v.w[W_PITCH],
|
||||
v.w[W_RATE], v.comment);
|
||||
}
|
||||
if (l > 5 && !strcmp(e->d_name + l - 5, ".gtss") && l - 5 < sizeof(id)) {
|
||||
memcpy(id, e->d_name, l - 5);
|
||||
id[l - 5] = 0;
|
||||
if (!pt_load(&ptv, dir, id))
|
||||
printf("%-12s %-12s %3d Hz %3d wpm PlainTalk%s\n", id, id,
|
||||
FS / ptv.nom, PT_RATE, ptv.dim == 2 ? ", high quality" : "");
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
return 0;
|
||||
@@ -1279,7 +1297,15 @@ int main(int argc, char **argv)
|
||||
for (i = 0; vname[i] && i < (int)sizeof(id) - 1; i++)
|
||||
id[i] = vname[i] == ' ' ? '-' : (char)tolower((unsigned char)vname[i]);
|
||||
id[i] = 0;
|
||||
if (voice_load(&v, dir, id)) {
|
||||
if (!pt_load(&ptv, dir, id)) {
|
||||
/* a PlainTalk voice: our prosody, its recorded diphones */
|
||||
pt = 1;
|
||||
memset(&v, 0, sizeof(v));
|
||||
snprintf(v.name, sizeof(v.name), "%s", id);
|
||||
v.w[W_PITCH] = FS / ptv.nom;
|
||||
v.w[W_PMOD] = 100;
|
||||
v.w[W_RATE] = PT_RATE;
|
||||
} else if (voice_load(&v, dir, id)) {
|
||||
fprintf(stderr, "macintalk: no voice %s in %s (run tools/fetch-macintalk.py)\n",
|
||||
vname, dir);
|
||||
return 1;
|
||||
@@ -1307,7 +1333,7 @@ int main(int argc, char **argv)
|
||||
for (i = 0; i < nseg; i++)
|
||||
fprintf(stderr, "%7.1f %6.1f %-3s k%d s%d\n", segs[i].t0, segs[i].dur,
|
||||
ph[segs[i].ph].name, segs[i].kind, segs[i].stress);
|
||||
pcm = synth(&v, pitch, &n);
|
||||
pcm = pt ? pt_synth(&ptv, &n) : synth(&v, pitch, &n);
|
||||
if (!pcm)
|
||||
return 1;
|
||||
if (outname) {
|
||||
|
||||
@@ -0,0 +1,440 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*
|
||||
* The PlainTalk (MacinTalk Pro) voices: Victoria, Bruce and Agnes.
|
||||
*
|
||||
* Included by macintalk.c. It reads only the voice's recorded-sound data
|
||||
* (the 'gtss' 3 resource, saved as <voice>.gtss by tools/fetch-macintalk.py)
|
||||
* and joins the recorded half-diphones itself, with the pitch and timing
|
||||
* that macintalk.c works out. docs/plaintalk-format.md describes the data.
|
||||
* None of Apple's code is used.
|
||||
*/
|
||||
|
||||
#define PT_NW 50 /* wave-phonemes: the diphone tables are 50 x 50 */
|
||||
#define PT_MAXN 256 /* most samples in a coded period */
|
||||
|
||||
struct ptunit { /* one coded half-diphone */
|
||||
uint32_t off, end; /* in the file */
|
||||
int per0, nper; /* its period lengths (voiced streams only) */
|
||||
};
|
||||
|
||||
struct ptvoice {
|
||||
unsigned char *d;
|
||||
size_t n;
|
||||
uint32_t sec[13];
|
||||
int nom; /* the voice's own period, samples at 22050 Hz */
|
||||
int dim; /* samples per codebook vector */
|
||||
int N; /* samples in a coded period */
|
||||
int16_t cb[256][4];
|
||||
uint32_t tab[2][PT_NW * PT_NW][2];
|
||||
struct ptunit *unit[4]; /* streams 2..5 */
|
||||
int nunit[4];
|
||||
uint16_t *per[2]; /* period lengths for streams 2 and 3 */
|
||||
int nper[2];
|
||||
};
|
||||
|
||||
static uint32_t be32(const unsigned char *p)
|
||||
{
|
||||
return (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | p[3];
|
||||
}
|
||||
static int be16(const unsigned char *p) { return p[0] << 8 | p[1]; }
|
||||
|
||||
static int u32cmp(const void *a, const void *b)
|
||||
{
|
||||
uint32_t x = *(const uint32_t *)a, y = *(const uint32_t *)b;
|
||||
return x < y ? -1 : x > y;
|
||||
}
|
||||
|
||||
/* How many of the units parse cleanly as frames of N samples: whole
|
||||
* frames, then a last frame whose first byte has the top bit set and holds
|
||||
* its index count, then one byte and up to 3 bytes of padding. */
|
||||
static int pt_fit(struct ptvoice *v, int N)
|
||||
{
|
||||
int s, i, ok = 0, F = 2 + N / v->dim;
|
||||
for (s = 0; s < 4; s++)
|
||||
for (i = 0; i < v->nunit[s]; i++) {
|
||||
uint32_t p = v->unit[s][i].off + 1, e = v->unit[s][i].end;
|
||||
while (p < e && v->d[p] < 0x80)
|
||||
p += F;
|
||||
if (p < e) {
|
||||
uint32_t end = p + 2 + (v->d[p] & 0x7f) + 1;
|
||||
ok += end <= e && e <= end + 3;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int pt_load(struct ptvoice *v, const char *dir, const char *id)
|
||||
{
|
||||
char path[1024];
|
||||
FILE *f;
|
||||
long len;
|
||||
int i, s, t, best = -1;
|
||||
|
||||
memset(v, 0, sizeof(*v));
|
||||
snprintf(path, sizeof(path), "%s/%s.gtss", dir, id);
|
||||
if (!(f = fopen(path, "rb")))
|
||||
return -1;
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
v->d = malloc(len > 0 ? len : 1);
|
||||
if (!v->d || len < 64 || fread(v->d, 1, len, f) != (size_t)len) {
|
||||
fclose(f);
|
||||
goto bad;
|
||||
}
|
||||
fclose(f);
|
||||
v->n = len;
|
||||
if (be16(v->d) != PT_NW)
|
||||
goto bad;
|
||||
v->nom = be16(v->d + 2);
|
||||
for (i = 0; i < 12; i++)
|
||||
v->sec[i] = be32(v->d + 16 + 4 * i);
|
||||
v->sec[12] = len;
|
||||
for (i = 0; i < 12; i++)
|
||||
if (v->sec[i] > v->sec[i + 1])
|
||||
goto bad;
|
||||
if (v->nom < 40 || v->nom > 400)
|
||||
goto bad;
|
||||
/* section 10: the codebook, 256 vectors */
|
||||
v->dim = (int)(v->sec[11] - v->sec[10]) / 512;
|
||||
if (v->dim != 4) /* the high quality voices code differently; not done yet */
|
||||
goto bad;
|
||||
for (i = 0; i < 256 * v->dim; i++)
|
||||
v->cb[i / v->dim][i % v->dim] = (int16_t)be16(v->d + v->sec[10] + 2 * i);
|
||||
/* sections 0 and 1: where the two halves of each diphone are */
|
||||
for (t = 0; t < 2; t++) {
|
||||
if (v->sec[t + 1] - v->sec[t] < PT_NW * PT_NW * 8)
|
||||
goto bad;
|
||||
for (i = 0; i < PT_NW * PT_NW; i++) {
|
||||
v->tab[t][i][0] = be32(v->d + v->sec[t] + 8 * i);
|
||||
v->tab[t][i][1] = be32(v->d + v->sec[t] + 8 * i + 4);
|
||||
}
|
||||
}
|
||||
/* sections 6 and 7: the period lengths of each unit of streams 2 and 3 */
|
||||
for (t = 0; t < 2; t++) {
|
||||
const unsigned char *p = v->d + v->sec[6 + t];
|
||||
int n = (int)(v->sec[7 + t] - v->sec[6 + t]) / 2;
|
||||
v->per[t] = malloc(sizeof(uint16_t) * (n ? n : 1));
|
||||
for (i = 0; i < n; i++)
|
||||
v->per[t][i] = (uint16_t)be16(p + 2 * i);
|
||||
v->nper[t] = n;
|
||||
}
|
||||
/* The units of each stream in order. Streams 2 and 4 hold the first
|
||||
* halves (table 0), 3 and 5 the second halves (table 1); 4 and 5 the
|
||||
* halves that are consonants, wave-phoneme 31 and up. */
|
||||
for (s = 0; s < 4; s++) {
|
||||
int side = s & 1, cons = s >= 2, n = 0;
|
||||
uint32_t *o = malloc(sizeof(uint32_t) * (PT_NW * PT_NW + 1));
|
||||
for (i = 0; i < PT_NW * PT_NW; i++) {
|
||||
int ph = side ? i % PT_NW : i / PT_NW;
|
||||
uint32_t a = v->tab[side][i][0];
|
||||
if (a >= 0xffff || (ph >= 31) != cons)
|
||||
continue;
|
||||
if (v->sec[2 + s] + 4 * a < v->sec[3 + s])
|
||||
o[n++] = a * 4;
|
||||
}
|
||||
qsort(o, n, sizeof(*o), u32cmp);
|
||||
v->unit[s] = malloc(sizeof(struct ptunit) * (n + 1));
|
||||
v->nunit[s] = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
struct ptunit *u;
|
||||
if (i && o[i] == o[i - 1])
|
||||
continue;
|
||||
u = &v->unit[s][v->nunit[s]++];
|
||||
u->off = v->sec[2 + s] + o[i];
|
||||
u->per0 = u->nper = 0;
|
||||
}
|
||||
for (i = 0; i < v->nunit[s]; i++)
|
||||
v->unit[s][i].end = i + 1 < v->nunit[s] ? v->unit[s][i + 1].off : v->sec[3 + s];
|
||||
free(o);
|
||||
if (!cons) { /* one period list per unit, each ended by 0xffff */
|
||||
int k = 0;
|
||||
for (i = 0; i < v->nunit[s]; i++) {
|
||||
v->unit[s][i].per0 = k;
|
||||
while (k < v->nper[side] && v->per[side][k] != 0xffff)
|
||||
k++;
|
||||
v->unit[s][i].nper = k - v->unit[s][i].per0;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* the coded period length isn't in the header: find the one that fits */
|
||||
for (i = 8; i <= PT_MAXN; i += 4) {
|
||||
int fit = pt_fit(v, i);
|
||||
if (fit > best) {
|
||||
best = fit;
|
||||
v->N = i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
bad:
|
||||
fprintf(stderr, "macintalk: %s: not a PlainTalk voice this program can read\n", path);
|
||||
free(v->d);
|
||||
v->d = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static struct ptunit *pt_find_unit(struct ptvoice *v, int s, uint32_t off)
|
||||
{
|
||||
int lo = 0, hi = v->nunit[s] - 1;
|
||||
while (lo <= hi) {
|
||||
int m = (lo + hi) / 2;
|
||||
if (v->unit[s][m].off == off)
|
||||
return &v->unit[s][m];
|
||||
if (v->unit[s][m].off < off)
|
||||
lo = m + 1;
|
||||
else
|
||||
hi = m - 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* the table entry for the diphone l-r, following the table's redirections */
|
||||
static int pt_entry(struct ptvoice *v, int side, int l, int r, uint32_t *off)
|
||||
{
|
||||
int k;
|
||||
for (k = 0; k < 6; k++) {
|
||||
uint32_t a, b;
|
||||
if (l < 0 || r < 0 || l >= PT_NW || r >= PT_NW)
|
||||
return -1;
|
||||
a = v->tab[side][l * PT_NW + r][0];
|
||||
b = v->tab[side][l * PT_NW + r][1];
|
||||
if (a == 0xffffffff)
|
||||
return -1;
|
||||
if (a != 0xffff) {
|
||||
*off = a * 4;
|
||||
return 0;
|
||||
}
|
||||
l = b >> 16;
|
||||
r = b & 0xffff;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* one decoded period (or, in the consonant streams, one frame) */
|
||||
struct ptframe {
|
||||
float x[PT_MAXN];
|
||||
int len; /* its length as recorded, samples */
|
||||
int voiced; /* follows the pitch */
|
||||
};
|
||||
|
||||
static struct ptframe *frames;
|
||||
static int nframes, aframes;
|
||||
|
||||
static struct ptframe *pt_new_frame(void)
|
||||
{
|
||||
if (nframes >= aframes) {
|
||||
aframes = aframes ? aframes * 2 : 1024;
|
||||
frames = realloc(frames, sizeof(*frames) * aframes);
|
||||
if (!frames) {
|
||||
fprintf(stderr, "macintalk: out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return &frames[nframes++];
|
||||
}
|
||||
|
||||
/* Decode the half-diphone at byte off of its stream. A unit is one byte,
|
||||
* then frames of: a gain byte (4-bit exponent, 4-bit mantissa), a lag byte
|
||||
* and N/dim codebook indices. Each period is the signal one period plus
|
||||
* (lag - 1) samples back, plus the gain times the codebook vectors. A gain
|
||||
* byte with the top bit set starts the last, partial frame, which we leave
|
||||
* out. */
|
||||
static int pt_unit(struct ptvoice *v, int side, int cons, uint32_t off, int voiced)
|
||||
{
|
||||
int s = side + 2 * cons, k = 0, i, N = v->N, nidx = v->N / v->dim, f0 = nframes;
|
||||
struct ptunit *u = pt_find_unit(v, s, v->sec[2 + s] + off);
|
||||
const unsigned char *p, *e;
|
||||
|
||||
if (!u)
|
||||
return -1;
|
||||
p = v->d + u->off + 1;
|
||||
e = v->d + u->end;
|
||||
while (p + 2 + nidx <= e && !(p[0] & 0x80)) {
|
||||
int A = p[0], lag = N + p[1] - 1;
|
||||
double g = (16 + (A & 15)) * pow(2, A >> 4) / 256.0 / 32768.0;
|
||||
int len = cons ? v->nom : k < u->nper ? v->per[side][u->per0 + k] : v->nom;
|
||||
struct ptframe *fr = pt_new_frame();
|
||||
for (i = 0; i < N; i++) {
|
||||
/* sample i of this frame is sample k*N + i of the unit */
|
||||
int back = k * N + i - lag;
|
||||
double x = 0;
|
||||
if (k > 0 && back >= 0) {
|
||||
int bf = back / N, bi = back % N;
|
||||
x = bf < k ? frames[f0 + bf].x[bi] : fr->x[bi];
|
||||
}
|
||||
fr->x[i] = (float)x;
|
||||
}
|
||||
for (i = 0; i < nidx; i++) {
|
||||
const int16_t *c = v->cb[p[2 + i]];
|
||||
int j;
|
||||
for (j = 0; j < v->dim; j++)
|
||||
fr->x[i * v->dim + j] += (float)(c[j] * g);
|
||||
}
|
||||
if (len < 20 || len > 400)
|
||||
len = v->nom;
|
||||
fr->len = len;
|
||||
fr->voiced = voiced;
|
||||
p += 2 + nidx;
|
||||
k++;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
/* ---- from our phonemes to the voice's wave-phonemes ---- */
|
||||
|
||||
static int pt_wave(int p, int next, int prev)
|
||||
{
|
||||
static const struct { const char *ph; int w; } map[] = {
|
||||
{ "IY", 2 }, { "IH", 3 }, { "IX", 4 }, { "EH", 5 }, { "AE", 6 }, { "AH", 7 },
|
||||
{ "AX", 8 }, { "AA", 9 }, { "AO", 10 }, { "UH", 11 }, { "UW", 12 }, { "OW", 13 },
|
||||
{ "ER", 14 }, { "AY", 19 }, { "EY", 20 }, { "OY", 21 }, { "AW", 22 },
|
||||
{ "l", 24 }, { "m", 25 }, { "n", 26 }, { "N", 27 }, { "y", 28 }, { "r", 29 },
|
||||
{ "w", 30 }, { "b", 31 }, { "d", 32 }, { "g", 33 }, { "v", 34 }, { "D", 35 },
|
||||
{ "z", 36 }, { "Z", 37 }, { "f", 38 }, { "T", 39 }, { "s", 40 }, { "S", 41 },
|
||||
{ "h", 42 }, { "p", 43 }, { "t", 45 }, { "k", 48 },
|
||||
};
|
||||
int i, w = -1;
|
||||
if (p <= 0)
|
||||
return 0;
|
||||
for (i = 0; i < (int)(sizeof(map) / sizeof(map[0])); i++)
|
||||
if (!strcmp(ph[p].name, map[i].ph))
|
||||
w = map[i].w;
|
||||
if (w < 0)
|
||||
return 0;
|
||||
/* vowels before r take their r-coloured form */
|
||||
if (next > 0 && !strcmp(ph[next].name, "r")) {
|
||||
if (w == 2 || w == 3)
|
||||
w = 15;
|
||||
else if (w == 9)
|
||||
w = 16;
|
||||
else if (w == 10 || w == 13)
|
||||
w = 17;
|
||||
else if (w == 11 || w == 12)
|
||||
w = 18;
|
||||
}
|
||||
/* p, t, k after s are unaspirated */
|
||||
if ((w == 43 || w == 45 || w == 48) && prev > 0 && !strcmp(ph[prev].name, "s"))
|
||||
w++;
|
||||
return w;
|
||||
}
|
||||
|
||||
/* a close relative to use when a diphone is missing */
|
||||
static int pt_similar(int w)
|
||||
{
|
||||
switch (w) {
|
||||
case 44: return 43;
|
||||
case 46: return 45;
|
||||
case 49: return 48;
|
||||
case 15: return 3;
|
||||
case 16: return 9;
|
||||
case 17: return 13;
|
||||
case 18: return 12;
|
||||
case 4: return 3;
|
||||
case 7: return 8;
|
||||
case 27: return 26;
|
||||
case 24: return 23;
|
||||
case 34: return 38;
|
||||
case 36: return 40;
|
||||
case 37: return 41;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int pt_half(struct ptvoice *v, int side, int l, int r, int voiced)
|
||||
{
|
||||
uint32_t off;
|
||||
int tries;
|
||||
for (tries = 0; tries < 4; tries++) {
|
||||
int ll = l, rr = r;
|
||||
if ((tries & 1) && pt_similar(l) >= 0)
|
||||
ll = pt_similar(l);
|
||||
if ((tries & 2) && pt_similar(r) >= 0)
|
||||
rr = pt_similar(r);
|
||||
if (tries && ll == l && rr == r)
|
||||
continue;
|
||||
if (pt_entry(v, side, ll, rr, &off))
|
||||
continue;
|
||||
return pt_unit(v, side, (side ? rr : ll) >= 31, off, voiced);
|
||||
}
|
||||
if (getenv("MACINTALK_DEBUG"))
|
||||
fprintf(stderr, "no diphone %d-%d (half %d)\n", l, r, side);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static float *pt_synth(struct ptvoice *v, int *nout)
|
||||
{
|
||||
double total = nseg ? segs[nseg - 1].t0 + segs[nseg - 1].dur : 0;
|
||||
int cap = (int)(total * 2.6 * FS / 1000) + FS, n = 0, i;
|
||||
float *out = calloc(cap, sizeof(float));
|
||||
int *w = malloc(sizeof(int) * (ntok + 2));
|
||||
double t_ms = 0;
|
||||
|
||||
if (!out || !w)
|
||||
return NULL;
|
||||
for (i = 0; i < ntok; i++)
|
||||
w[i] = pt_wave(toks[i].ph, i + 1 < ntok ? toks[i + 1].ph : 0, i ? toks[i - 1].ph : 0);
|
||||
|
||||
for (i = 0; i < ntok; i++) {
|
||||
double want = 0, have = 0, pos, step;
|
||||
int k, f0, f1, l = i ? w[i - 1] : 0, r = i + 1 < ntok ? w[i + 1] : 0, voiced;
|
||||
for (k = 0; k < nseg; k++)
|
||||
if (segs[k].tok == i)
|
||||
want += segs[k].dur;
|
||||
if (w[i] == 0) { /* a pause */
|
||||
int m = (int)(want * FS / 1000);
|
||||
for (k = 0; k < m && n < cap; k++)
|
||||
out[n++] = 0;
|
||||
t_ms += want;
|
||||
continue;
|
||||
}
|
||||
/* this phoneme is the second half of l-it and the first half of it-r */
|
||||
voiced = w[i] < 38;
|
||||
f0 = nframes;
|
||||
pt_half(v, 1, l, w[i], voiced);
|
||||
pt_half(v, 0, w[i], r, voiced);
|
||||
f1 = nframes;
|
||||
if (f1 == f0)
|
||||
continue;
|
||||
for (k = f0; k < f1; k++)
|
||||
have += frames[k].len;
|
||||
have = have * 1000.0 / FS;
|
||||
/* stretch or squeeze it to its length by repeating or dropping frames */
|
||||
step = want > 0 ? have / want : 1;
|
||||
if (step < 0.4)
|
||||
step = 0.4;
|
||||
if (step > 2.5)
|
||||
step = 2.5;
|
||||
pos = 0;
|
||||
while (pos < have) {
|
||||
int fi, j, L;
|
||||
double acc = 0, per;
|
||||
struct ptframe *fr;
|
||||
for (fi = f0; fi < f1 - 1; fi++) {
|
||||
acc += frames[fi].len * 1000.0 / FS;
|
||||
if (acc > pos)
|
||||
break;
|
||||
}
|
||||
fr = &frames[fi];
|
||||
/* a voiced period is resampled to the pitch wanted */
|
||||
per = fr->voiced ? FS / pitch_at(t_ms) : fr->len;
|
||||
L = (int)lrint(per < 20 ? 20 : per);
|
||||
if (n + L >= cap)
|
||||
break;
|
||||
for (j = 0; j < L; j++) {
|
||||
double t = (double)j * v->N / L, fr_;
|
||||
int a = (int)t;
|
||||
fr_ = t - a;
|
||||
out[n + j] = fr->x[a % v->N] * (float)(1 - fr_) +
|
||||
fr->x[(a + 1) % v->N] * (float)fr_;
|
||||
}
|
||||
n += L;
|
||||
t_ms += L * 1000.0 / FS;
|
||||
pos += L * 1000.0 / FS * step;
|
||||
}
|
||||
nframes = f0;
|
||||
}
|
||||
free(w);
|
||||
*nout = n;
|
||||
return out;
|
||||
}
|
||||
+109
-37
@@ -1,29 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
"""SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
Fetch the MacInTalk 3 voice files for synth/macintalk at build time.
|
||||
Fetch the MacInTalk voice files for synth/macintalk at build time.
|
||||
|
||||
Apple's files are not in this repository. This script downloads a Mac OS
|
||||
8.1 hard disk image from the Internet Archive, checks its SHA-256, finds
|
||||
the voice files in System Folder:Extensions:Voices on the disk's HFS
|
||||
volume, and writes each voice's two resources as plain files:
|
||||
Apple's files are not in this repository. This script downloads two hard
|
||||
disk images from the Internet Archive, checks their SHA-256, finds the voice
|
||||
files in System Folder:Extensions:Voices on each disk's HFS volume, and
|
||||
writes the voices' data resources as plain files:
|
||||
|
||||
from Mac OS 8.1, the MacInTalk 3 voices (Fred, Ralph, Kathy ...):
|
||||
OUT/<voice>.ttvd the voice description (parameters, see
|
||||
docs/macintalk-format.md)
|
||||
OUT/<voice>.ttvw the voice's sampled sound, for the voices that
|
||||
have one (Bells, Boing, Cellos ...)
|
||||
from Mac OS 8.6, the PlainTalk voices (Agnes, Bruce, Victoria):
|
||||
OUT/<voice>.gtss the recorded diphones (see docs/plaintalk-format.md)
|
||||
|
||||
Only data is read. Nothing from the disk is run, and the MacinTalk 3
|
||||
extension itself (Apple's code) is not extracted.
|
||||
Only data is read. Nothing from the disks is run, and Apple's code (the
|
||||
MacinTalk 3 and MacinTalk Pro extensions, and the code resources in the
|
||||
PlainTalk voice files) is not extracted.
|
||||
|
||||
Usage: tools/fetch-macintalk.py [OUT] (default: sources/macintalk)
|
||||
tools/fetch-macintalk.py --image FILE.hda|FILE.zip [OUT]
|
||||
tools/fetch-macintalk.py --image FILE.hda|FILE.zip|FILE.exe [OUT]
|
||||
tools/fetch-macintalk.py --no-plaintalk [OUT]
|
||||
|
||||
Needs only Python 3 (and about 1.1 GB of free disk while it runs).
|
||||
Needs Python 3 and about 1.2 GB of free disk while it runs. The Mac OS 8.6
|
||||
image comes as a self-extracting RAR archive, so the PlainTalk voices also
|
||||
need unar (Debian/Ubuntu package unar) or unrar; without either, they are
|
||||
skipped.
|
||||
"""
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib.request
|
||||
@@ -32,6 +42,10 @@ import zipfile
|
||||
URL = ("https://archive.org/download/macos-8.1-basilisk-ii/"
|
||||
"macos-8.1-basilisk-ii-2026.10.1.zip")
|
||||
SHA256 = "ce6ee4ba5294182535d20bf6639f64415376e4420b3473167803315e615c97fa"
|
||||
URL_86 = ("https://archive.org/download/MacOS8.6Image-SheepShaverEmulator/"
|
||||
"Mac%20OS%208.6%20on%20disk%20image%20%2B%20SheepShaver.exe")
|
||||
SHA256_86 = "003910efa3fc95a9c0da3f064e0e9aafafd9c2b20b11fde2e01d2f8fd9472c92"
|
||||
DSK_86 = "SheepShaver/Mac_OS_HD.dsk"
|
||||
VOICE_DIR = ("System Folder", "Extensions", "Voices")
|
||||
|
||||
|
||||
@@ -138,50 +152,108 @@ def voice_id(name):
|
||||
|
||||
|
||||
def extract(hda, out):
|
||||
"""Write the voices found on the HFS disk image hda; returns how many."""
|
||||
with open(hda, "rb") as f:
|
||||
vol = HFS(f)
|
||||
voices = vol.find(VOICE_DIR)
|
||||
os.makedirs(out, exist_ok=True)
|
||||
n = 0
|
||||
for name, (ftype, creator, _, rsrc) in sorted(voices.items()):
|
||||
if ftype != b"ttvf" or creator != b"mtk3":
|
||||
continue # only MacinTalk 3 voices
|
||||
if ftype != b"ttvf":
|
||||
continue
|
||||
res = resources(rsrc)
|
||||
if creator == b"mtk3": # MacinTalk 3
|
||||
want = {"ttvd": "ttvd", "ttvw": "ttvw"}
|
||||
elif creator == b"gala": # MacinTalk Pro (PlainTalk)
|
||||
if "high quality" in name:
|
||||
continue # coded differently; synth/macintalk can't read them yet
|
||||
# 'gtss' 3 is the voice's recorded sound; 'gtss' 4 is code: left out
|
||||
res = {k: v for k, v in res.items() if k == ("gtss", 3)}
|
||||
want = {"gtss": "gtss"}
|
||||
else:
|
||||
continue
|
||||
for (rtype, _), (_, data) in res.items():
|
||||
if rtype in ("ttvd", "ttvw"):
|
||||
with open(os.path.join(out, voice_id(name) + "." + rtype), "wb") as o:
|
||||
if rtype in want:
|
||||
with open(os.path.join(out, voice_id(name) + "." + want[rtype]), "wb") as o:
|
||||
o.write(data)
|
||||
n += 1
|
||||
print("voice", name)
|
||||
return n
|
||||
|
||||
|
||||
def fetch(url, sha, path):
|
||||
if not os.path.exists(path):
|
||||
print("fetch", url)
|
||||
urllib.request.urlretrieve(url, path + ".part")
|
||||
os.rename(path + ".part", path)
|
||||
h = hashlib.sha256()
|
||||
with open(path, "rb") as f:
|
||||
for b in iter(lambda: f.read(1 << 20), b""):
|
||||
h.update(b)
|
||||
if h.hexdigest() != sha:
|
||||
sys.exit("%s: SHA-256 mismatch" % path)
|
||||
|
||||
|
||||
def unrar(archive, member, tmp):
|
||||
"""Unpack one file of a (self-extracting) RAR archive with unar or
|
||||
unrar; None if neither is installed."""
|
||||
for cmd in (["unar", "-q", "-f", "-o", tmp, archive, member],
|
||||
["unrar", "x", "-y", "-idq", archive, member, tmp + os.sep]):
|
||||
if shutil.which(cmd[0]):
|
||||
subprocess.run(cmd, check=True)
|
||||
path = os.path.join(tmp, *member.split("/"))
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
return None
|
||||
|
||||
|
||||
def unpack(image, tmp):
|
||||
"""The disk image itself, from a zip or RAR archive if it's in one."""
|
||||
if zipfile.is_zipfile(image):
|
||||
with zipfile.ZipFile(image) as z:
|
||||
member = [i for i in z.namelist() if i.endswith((".hda", ".dsk", ".img"))][0]
|
||||
print("unpack", member)
|
||||
return z.extract(member, tmp)
|
||||
with open(image, "rb") as f:
|
||||
head = f.read(1 << 20)
|
||||
if head[:2] == b"MZ" and b"Rar!\x1a\x07" in head:
|
||||
print("unpack", DSK_86)
|
||||
return unrar(image, DSK_86, tmp)
|
||||
return image
|
||||
|
||||
|
||||
def main(argv):
|
||||
image = None
|
||||
if argv[:1] == ["--image"]:
|
||||
image, argv = argv[1], argv[2:]
|
||||
images, plaintalk = [], True
|
||||
while argv[:1] and argv[0].startswith("--"):
|
||||
if argv[0] == "--image" and len(argv) > 1:
|
||||
images.append(argv[1])
|
||||
argv = argv[2:]
|
||||
elif argv[0] == "--no-plaintalk":
|
||||
plaintalk = False
|
||||
argv = argv[1:]
|
||||
else:
|
||||
sys.exit(__doc__)
|
||||
out = argv[0] if argv else os.path.join("sources", "macintalk")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
if image is None:
|
||||
image = os.path.join(out, "macos-8.1.zip")
|
||||
os.makedirs(out, exist_ok=True)
|
||||
if not os.path.exists(image):
|
||||
print("fetch", URL)
|
||||
urllib.request.urlretrieve(URL, image + ".part")
|
||||
os.rename(image + ".part", image)
|
||||
h = hashlib.sha256()
|
||||
with open(image, "rb") as f:
|
||||
for b in iter(lambda: f.read(1 << 20), b""):
|
||||
h.update(b)
|
||||
if h.hexdigest() != SHA256:
|
||||
sys.exit("%s: SHA-256 mismatch" % image)
|
||||
if zipfile.is_zipfile(image):
|
||||
with zipfile.ZipFile(image) as z:
|
||||
member = [i for i in z.namelist() if i.endswith((".hda", ".dsk", ".img"))][0]
|
||||
print("unpack", member)
|
||||
image = z.extract(member, tmp)
|
||||
if not extract(image, out):
|
||||
sys.exit("no MacinTalk 3 voices found")
|
||||
os.makedirs(out, exist_ok=True)
|
||||
if not images:
|
||||
images.append(os.path.join(out, "macos-8.1.zip"))
|
||||
fetch(URL, SHA256, images[0])
|
||||
if plaintalk:
|
||||
if shutil.which("unar") or shutil.which("unrar"):
|
||||
images.append(os.path.join(out, "macos-8.6.exe"))
|
||||
fetch(URL_86, SHA256_86, images[1])
|
||||
else:
|
||||
print("unar or unrar not found: skipping the PlainTalk voices")
|
||||
found = 0
|
||||
for image in images:
|
||||
with tempfile.TemporaryDirectory(dir=out) as tmp:
|
||||
disk = unpack(image, tmp)
|
||||
if disk is None:
|
||||
print("%s: can't unpack it (install unar or unrar)" % image)
|
||||
continue
|
||||
found += extract(disk, out)
|
||||
if not found:
|
||||
sys.exit("no voices found")
|
||||
print("voices in", out)
|
||||
|
||||
|
||||
|
||||
+23
-6
@@ -12,8 +12,8 @@ Usage: tools/synth_voices.py OUT VOICE... (OUT is normally ./voices)
|
||||
|
||||
--live writes a live voice instead (mode=tts, live-<engine>-<voice>): no
|
||||
clips, the module runs the synthesiser on the Asterisk machine for each
|
||||
sentence as it is needed (dectalk, sam, mssam and macintalk only;
|
||||
tts_program_dectalk, tts_program_sam, tts_program_mssam and
|
||||
sentence as it is needed (dectalk, sam, mssam, macintalk and plaintalk
|
||||
only; tts_program_dectalk, tts_program_sam, tts_program_mssam and
|
||||
tts_program_macintalk in speakingclock.conf say where they are).
|
||||
|
||||
Engines (a VOICE is engine:name, see --list):
|
||||
@@ -34,6 +34,9 @@ Engines (a VOICE is engine:name, see --list):
|
||||
by our own synthesiser, synth/macintalk, from Apple's voice data
|
||||
(tools/fetch-macintalk.py gets it). $MACINTALK is its program,
|
||||
$MACINTALK_VOICES the voice folder. Works with --live.
|
||||
plaintalk The PlainTalk voices (Agnes, Bruce, Victoria), Apple's recorded
|
||||
diphones joined by the same program, synth/macintalk. Works
|
||||
with --live.
|
||||
|
||||
Needs ffmpeg and sox.
|
||||
"""
|
||||
@@ -165,6 +168,13 @@ MACINTALK = {
|
||||
"hysterical": ("Hysterical", "speaking through laughter"),
|
||||
}
|
||||
|
||||
# The PlainTalk (MacinTalk Pro) voices of Mac OS 8.6, spoken by synth/macintalk.
|
||||
PLAINTALK = {
|
||||
"agnes": ("Agnes", "female"),
|
||||
"bruce": ("Bruce", "male"),
|
||||
"victoria": ("Victoria", "female"),
|
||||
}
|
||||
|
||||
last_request = [0.0]
|
||||
|
||||
|
||||
@@ -266,6 +276,11 @@ ENGINES = {
|
||||
"MacInTalk 3 voice (%s)" % MACINTALK[v][1]),
|
||||
"synth/macintalk (this repository, clean-room) reading Apple's "
|
||||
"MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py"),
|
||||
"plaintalk": (macintalk, PLAINTALK,
|
||||
lambda v: ("PlainTalk %s" % PLAINTALK[v][0],
|
||||
"PlainTalk (MacinTalk Pro) voice, %s" % PLAINTALK[v][1]),
|
||||
"synth/macintalk (this repository, clean-room) joining Apple's recorded "
|
||||
"PlainTalk diphones (Mac OS 8.6), fetched by tools/fetch-macintalk.py"),
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +324,7 @@ def build_live(out_dir, engine, vid):
|
||||
elif engine == "mssam":
|
||||
how = 'command={program:mssam} -v %s -o {out} "{text}"' % vid
|
||||
by = "synth/mssam, run here (tts_program_mssam)"
|
||||
elif engine == "macintalk":
|
||||
elif engine in ("macintalk", "plaintalk"):
|
||||
how = 'command={program:macintalk} -v %s -o {out} "{text}"' % vid
|
||||
by = "synth/macintalk, run here (tts_program_macintalk)"
|
||||
else:
|
||||
@@ -321,7 +336,7 @@ def build_live(out_dir, engine, vid):
|
||||
if engine == "mssam":
|
||||
owners = ("; The synthesiser is ours; the voice data it reads is Microsoft's and is\n"
|
||||
"; not in this repository (tools/fetch-mssam.py downloads it); see NOTICE.md.")
|
||||
elif engine == "macintalk":
|
||||
elif engine in ("macintalk", "plaintalk"):
|
||||
owners = ("; The synthesiser is ours; the voice data it reads is Apple's and is\n"
|
||||
"; not in this repository (tools/fetch-macintalk.py downloads it); see NOTICE.md.")
|
||||
text = "At the third stroke, it will be {hour} {minute} {seconds}."
|
||||
@@ -344,8 +359,10 @@ def main():
|
||||
if len(sys.argv) > 2 and sys.argv[1] == "--live":
|
||||
for spec in sys.argv[3:]:
|
||||
engine, _, vid = spec.partition(":")
|
||||
if engine not in ("dectalk", "sam", "mssam", "macintalk") or vid not in ENGINES[engine][1]:
|
||||
sys.exit("--live takes dectalk, sam, mssam and macintalk voices (see --list)")
|
||||
if (engine not in ("dectalk", "sam", "mssam", "macintalk", "plaintalk")
|
||||
or vid not in ENGINES[engine][1]):
|
||||
sys.exit("--live takes dectalk, sam, mssam, macintalk and plaintalk voices "
|
||||
"(see --list)")
|
||||
build_live(sys.argv[2], engine, vid)
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from voice_index import write_index
|
||||
|
||||
@@ -72,6 +72,9 @@ Written by tools/voice_index.py. Every recording belongs to its original owner (
|
||||
| `live-mssam-mary` | Microsoft Mary, live | tts | mssam synthesiser |
|
||||
| `live-mssam-mike` | Microsoft Mike, live | tts | mssam synthesiser |
|
||||
| `live-mssam-sam` | Microsoft Sam, live | tts | mssam synthesiser |
|
||||
| `live-plaintalk-agnes` | PlainTalk Agnes, live | tts | plaintalk synthesiser |
|
||||
| `live-plaintalk-bruce` | PlainTalk Bruce, live | tts | plaintalk synthesiser |
|
||||
| `live-plaintalk-victoria` | PlainTalk Victoria, live | tts | plaintalk synthesiser |
|
||||
| `live-sam-elf` | SAM Elf, live | tts | sam synthesiser |
|
||||
| `live-sam-extra-terrestrial` | SAM Extra-Terrestrial, live | tts | sam synthesiser |
|
||||
| `live-sam-little-old-lady` | SAM Little Old Lady, live | tts | sam synthesiser |
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
; Live voice for app_speakingclock (docs/voice-format.md), made by
|
||||
; tools/synth_voices.py --live plaintalk:agnes. Each sentence is spoken when
|
||||
; it is needed, by synth/macintalk, run here (tts_program_macintalk).
|
||||
; The synthesiser is ours; the voice data it reads is Apple's and is
|
||||
; not in this repository (tools/fetch-macintalk.py downloads it); see NOTICE.md.
|
||||
|
||||
[voice]
|
||||
name=PlainTalk Agnes, live
|
||||
description=PlainTalk (MacinTalk Pro) voice, female, spoken live
|
||||
mode=tts
|
||||
sequence=speech+pips
|
||||
period=10
|
||||
|
||||
[tts]
|
||||
command={program:macintalk} -v agnes -o {out} "{text}"
|
||||
text=At the third stroke, it will be {hour} {minute} {seconds}.
|
||||
|
||||
[source]
|
||||
engine=plaintalk
|
||||
voice=agnes
|
||||
synthesiser=synth/macintalk (this repository, clean-room) joining Apple's recorded PlainTalk diphones (Mac OS 8.6), fetched by tools/fetch-macintalk.py
|
||||
@@ -0,0 +1,21 @@
|
||||
; Live voice for app_speakingclock (docs/voice-format.md), made by
|
||||
; tools/synth_voices.py --live plaintalk:bruce. Each sentence is spoken when
|
||||
; it is needed, by synth/macintalk, run here (tts_program_macintalk).
|
||||
; The synthesiser is ours; the voice data it reads is Apple's and is
|
||||
; not in this repository (tools/fetch-macintalk.py downloads it); see NOTICE.md.
|
||||
|
||||
[voice]
|
||||
name=PlainTalk Bruce, live
|
||||
description=PlainTalk (MacinTalk Pro) voice, male, spoken live
|
||||
mode=tts
|
||||
sequence=speech+pips
|
||||
period=10
|
||||
|
||||
[tts]
|
||||
command={program:macintalk} -v bruce -o {out} "{text}"
|
||||
text=At the third stroke, it will be {hour} {minute} {seconds}.
|
||||
|
||||
[source]
|
||||
engine=plaintalk
|
||||
voice=bruce
|
||||
synthesiser=synth/macintalk (this repository, clean-room) joining Apple's recorded PlainTalk diphones (Mac OS 8.6), fetched by tools/fetch-macintalk.py
|
||||
@@ -0,0 +1,21 @@
|
||||
; Live voice for app_speakingclock (docs/voice-format.md), made by
|
||||
; tools/synth_voices.py --live plaintalk:victoria. Each sentence is spoken when
|
||||
; it is needed, by synth/macintalk, run here (tts_program_macintalk).
|
||||
; The synthesiser is ours; the voice data it reads is Apple's and is
|
||||
; not in this repository (tools/fetch-macintalk.py downloads it); see NOTICE.md.
|
||||
|
||||
[voice]
|
||||
name=PlainTalk Victoria, live
|
||||
description=PlainTalk (MacinTalk Pro) voice, female, spoken live
|
||||
mode=tts
|
||||
sequence=speech+pips
|
||||
period=10
|
||||
|
||||
[tts]
|
||||
command={program:macintalk} -v victoria -o {out} "{text}"
|
||||
text=At the third stroke, it will be {hour} {minute} {seconds}.
|
||||
|
||||
[source]
|
||||
engine=plaintalk
|
||||
voice=victoria
|
||||
synthesiser=synth/macintalk (this repository, clean-room) joining Apple's recorded PlainTalk diphones (Mac OS 8.6), fetched by tools/fetch-macintalk.py
|
||||
Reference in new issue
Block a user