diff --git a/.gitignore b/.gitignore index bb2eb1c..3f4f947 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ asterisk/app_speakingclock.so /sources/ __pycache__/ +synth/macintalk/macintalk diff --git a/NOTICE.md b/NOTICE.md index dcd6596..397e493 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -85,3 +85,12 @@ voices, belong to their owners: - **MacInTalk and PlainTalk** (`mac-*`): Apple's voices (MacinTalk 3, and the PlainTalk MacinTalk Pro voices Victoria, Agnes, Bruce and Vicki), spoken by macOS's `say`. +- **MacInTalk 3, live** (`live-macintalk-*`): no recordings. Each sentence + is spoken on the Asterisk machine by `synth/macintalk`, our own + synthesiser (GPL-2.0-or-later, like the rest of this repository), which + reads the voice data of Apple's MacInTalk 3 voices. That data is Apple's + (© Apple Computer, Inc. 1992-1995) and is not in this repository: + `tools/fetch-macintalk.py` downloads it from a Mac OS 8.1 disk image on + 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. diff --git a/README.md b/README.md index 56f401b..40afb97 100644 --- a/README.md +++ b/README.md @@ -74,12 +74,17 @@ A voice with `mode=tts` has no clips. The module runs a synthesiser on the 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`. Set where they are in +`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 +[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 speakingclock.conf: ``` tts_program_dectalk=/opt/dectalk/say tts_program_sam=/usr/local/bin/sam +tts_program_macintalk=/usr/local/bin/macintalk ``` See [docs/voice-format.md](docs/voice-format.md#live-voices-modetts). @@ -112,6 +117,8 @@ DECTALK_SAY=~/dectalk/dist/say tools/synth_voices.py voices dectalk:paul SAM=~/SAM/sam tools/synth_voices.py voices sam:sam 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 ``` ## Licence diff --git a/asterisk/speakingclock.conf.sample b/asterisk/speakingclock.conf.sample index 1808c13..8dd5e7c 100644 --- a/asterisk/speakingclock.conf.sample +++ b/asterisk/speakingclock.conf.sample @@ -23,10 +23,12 @@ ; Hang up after this many seconds (0: never). The d() option overrides it. ;maxduration=180 -; The live DECtalk and SAM voices run the synthesiser on this machine, with -; no server. Default: dectalk and sam, found on the PATH. +; 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. ;tts_program_dectalk=/opt/dectalk/say ;tts_program_sam=/usr/local/bin/sam +;tts_program_macintalk=/usr/local/bin/macintalk ; Seconds a synthesiser program may take before it is stopped. ;tts_timeout=15 diff --git a/docs/macintalk-format.md b/docs/macintalk-format.md new file mode 100644 index 0000000..e3a0896 --- /dev/null +++ b/docs/macintalk-format.md @@ -0,0 +1,161 @@ +# MacInTalk 3 voice files + +What `synth/macintalk` knows about Apple's MacInTalk 3 voices. It was +worked out by comparing the data of the 19 voices that come with Mac OS 8.1 +(MacInTalk 3 version 1.4, 1992-1995) with each other and with how the +voices are known to sound. 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.1 hard disk image (for the +Basilisk II emulator) from the Internet Archive: +, file +`macos-8.1-basilisk-ii-2026.10.1.zip` (SHA-256 +`ce6ee4ba5294182535d20bf6639f64415376e4420b3473167803315e615c97fa`). The +zip holds one 1 GB HFS volume. The voices are in `System Folder:Extensions: +Voices`. Each is a file of type `ttvf`, creator `mtk3`, with an empty data +fork and these resources: + +| Resource | What it is | +|---|---| +| `ttvd` | the voice description: the Speech Manager's `VoiceDescription`, then MacInTalk 3's parameter block | +| `ttvw` | a sampled sound, in 9 of the 19 voices | +| `vers` 1, 2 | "1.4, © Apple Computer, Inc 1992-1995", "Mac OS 8.0" | + +The script writes each voice's `ttvd` and `ttvw` to `.ttvd` and +`.ttvw` (the voice's name in lower case, spaces as `-`), which is +what `synth/macintalk` reads. It doesn't extract the MacInTalk 3 extension +(the synthesiser itself, 68k and PowerPC code); nothing here needs it. + +Other files on the disk that are not used: `Speech Manager` (the system +extension), `MacinTalk 3` (its resources are code, `ttvi` 8 to 10 and the +PowerPC fragment in `ttvi` 11, and data: going by the text in them, +`ttvi` 3 to 7 hold the phoneme names, suffix lists, letter-to-sound rules +and probably the pronunciation dictionary; `ttss` 0 is the Speech Manager +phoneme table). + +## `ttvd` + +All big-endian. The first 362 bytes are the Speech Manager's +`VoiceDescription` (Inside Macintosh: Sound): + +| Offset | Size | Field | +|---|---|---| +| 0 | 4 | length (362) | +| 4 | 4 | creator, `mtk3` | +| 8 | 4 | voice id (Fred 1, Kathy 2, Princess 3, Junior 4, Ralph 5, Whisper 6, Zarvox 8, Trinoids 9 ...) | +| 12 | 4 | version (0x104) | +| 16 | 64 | name (Pascal string) | +| 80 | 256 | comment: the sample sentence the Speech control panel speaks | +| 336 | 2 × 5 | gender, age, script, language, region (all 0) | +| 346 | 16 | reserved | + +Then the parameter block, signed 16-bit words, numbered from 0 at offset +362. Most voices have 176 words. The singing voices add a tune at the end. +"Used" says whether `synth/macintalk` uses the word, and how. + +| Word | Values (Fred, Ralph, Kathy, Zarvox, Whisper) | What it is | Used | +|---|---|---|---| +| 0 | 97, 65, 200, 90, 110 | base pitch, Hz | yes | +| 1 | 100, 100, 80, 0, 100 | pitch modulation, % (0 for the monotone and singing voices) | yes | +| 2 | 60, 50, 40, 70, 70 | 0 for the singing voices; 100 for Albert and Bahh. Perhaps pitch wobble | no | +| 3 | 160, 150, 150, 160, 140 | speaking rate, words per minute | yes | +| 4 | 0, 0, 1, 0, 0 | a flag: set for Kathy, Princess, Boing, Trinoids | no | +| 5 | 100, 125, 55, 40, 0 | unknown (0 for the sampled voices) | no | +| 6 | 0, 60, 30, 0, 400 | breathiness (aspiration mixed with the voice) | yes | +| 7 | 192, 192, 200, 192, 16 | voicing amplitude (Whisper 16, Bubbles 32) | yes | +| 8, 9 | 3000/200, 2800/350, 3000/300, 3500/50, 3500/50 | fourth formant: frequency, bandwidth (Hz) | yes | +| 10, 11 | 3600/150, 3500/150, 3600/150, 4500/150, 4500/150 | fifth formant: frequency, bandwidth | yes | +| 12 to 15 | 3750, 100, 4500, 150 in every voice | probably two fixed higher resonances | no | +| 16, 17 | 330, 400 in every voice | nasal pole and zero, Hz | yes | +| 18 | 60 (Kathy 250, Princess 260) | unknown | no | +| 19 | 100 (0 for Kathy, Junior, Princess, Good News) | unknown | no | +| 20 to 22 | 150/100/100, 100/100/50, 200/100/100, 100/50/50, 100/100/50 | bandwidths of formants 1 to 3, % | yes | +| 23 to 25 | 0/0/0, −80/−40/−70, −40/−10/−10, 0/0/0, 0/0/0 | shifts of formants 1 to 3, Hz (Junior +50/+70/+70) | yes | +| 26 | 0 (Zarvox 3, Trinoids −32) | a second voice, at this % of the pitch above or below | yes (as a guess) | +| 27 | 100, 100, 140, 250, 200 | output gain, % | yes | +| 28, 29 | 0, 0 (sampled voices: 47 to 54, 70 to 250) | settings for the sampled sound | no | +| 30 | 2 for Fred and Whisper, else 0 | unknown | no | +| 31 to 45 | the same in every voice (260, 29, −29, 29, −29, 1, 0, 51, 7200 ...) | engine constants | no | +| 46 | 0, 1 or 2 | how the sampled sound is used: 0 none, 1 looped as the voice source, 2 one segment per syllable (Bells, Hysterical) | yes | +| 47 | 0 | | | +| 48 to 94 | 47 values | glottal source spectrum A: the amplitude of harmonics 1 to 47 | yes | +| 95 | 0 | | | +| 96 to 142 | 47 values | glottal source spectrum B | yes | +| 143 | 1, or the `ttvw` resource id | which sampled sound the voice uses | no (there is one) | +| 144 to 173 | mostly constant | unknown | no | +| 174 | 1, or the number of notes | the tune's length | yes | +| 175 ... | one word per note | high byte: length (in about eighths), low byte: semitones from the base pitch, signed | yes | + +The two source spectra are the clearest part of the format. Fred's falls +smoothly from 14636 to about 100 by the 36th harmonic. Kathy's falls much +faster and stops at the 16th (a softer voice). Zarvox has only the odd +harmonics, which is what gives it its hollow, buzzing sound. `synth/ +macintalk` builds the voice source from them, harmonic by harmonic, using +spectrum B on stressed vowels and A elsewhere. Which of the two Apple used +for what isn't known. + +The tunes are recognisable from their intervals. Cellos is In the Hall of +the Mountain King (0, 2, 3, 5, 7, 3, 7, 6, 2, 6, 5, 1, 5 semitones). Bad +News is Chopin's funeral march (four notes on one pitch, then +3, +2, +2, +0, 0, −1, 0). Good News is Pomp and Circumstance. Pipe Organ has a tune +too. + +## `ttvw` + +A sampled sound, 8-bit unsigned (128 is silence), apparently at 11127 Hz. +Either a 4-byte length and then the samples, or a 4-byte length, a 4-byte +count *n*, *n* 4-byte offsets that cut the samples into *n* − 1 segments, +and the samples. + +| Voice | Name | Length | Segments | +|---|---|---|---| +| Albert | Crow | 4407 | 1 | +| Bahh | Lamb | 4900 | 1 | +| Bells | Clock | 33820 | 4 | +| Boing | Boing | 6528 | 1 | +| Bubbles | Bubbles | 7222 | 1 | +| Cellos | BowedStr | 11854 | 1 | +| Deranged | Insane | 17244 | 1 | +| Hysterical | Male Laugh | 40194 | 5 | +| Pipe Organ | PipeOrgan | 9908 | 1 | + +## The voices + +| Voice | Sample sentence | +|---|---| +| Albert | I have a frog in my throat. No, I mean a real frog! | +| Bad News | The light you see at the end of the tunnel is the headlamp of a fast approaching train. | +| Bahh | Do not pull the wool over my eyes. | +| Bells | Time flies when you are having fun. | +| Boing | Spring has sprung, fall has fell, winter's here and it's colder than usual. | +| Bubbles | Pull the plug! I'm drowning! | +| Cellos | Doo da doo da dum dee dee doodly doo dum dum dum doo da doo da doo da doo da doo da doo da doo | +| Deranged | I need to go on a really long vacation. | +| Fred | I sure like being inside this fancy computer | +| Good News | Congratulations you just won the sweepstakes and you don't have to pay income tax again. | +| Hysterical | Please stop tickling me! | +| Junior | My favorite food is pizza. | +| Kathy | Isn't it nice to have a computer that will talk to you? | +| Pipe Organ | We must rejoice in this morbid voice. | +| Princess | When I grow up I'm going to be a scientist. | +| Ralph | The sum of the squares of the legs of a right triangle is equal to the square of the hypotenuse. | +| Trinoids | We cannot communicate with these carbon units. | +| Whisper | Pssssst, hey you, Yeah you, Who do ya think I'm talking to, the mouse? | +| Zarvox | That looks like a peaceful planet. | + +## What isn't Apple's + +The voice data sets how a voice sounds. How text becomes speech is ours: +the pronunciation comes from the NRL letter-to-sound rules (a 1976 US +Navy report, public domain) and a small word list, the phoneme targets and +durations are textbook values (Klatt 1979 and 1980), and the synthesiser is +a cascade formant synthesiser written for this repository. So the voices +are in the style of MacInTalk 3 rather than copies of it: the pitch, speed, +timbre, tunes and samples are Apple's, the pronunciation and rhythm are +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. diff --git a/synth/macintalk/Makefile b/synth/macintalk/Makefile new file mode 100644 index 0000000..56bad3c --- /dev/null +++ b/synth/macintalk/Makefile @@ -0,0 +1,35 @@ +# 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 install install the program and the voices +# make test speak a sentence with every voice +PREFIX ?= /usr/local +VOICEDIR ?= $(PREFIX)/share/macintalk +CC ?= cc +CFLAGS ?= -O2 -Wall -Wextra -Wno-missing-field-initializers +SOURCES ?= ../../sources/macintalk + +macintalk: macintalk.c rules.h + $(CC) $(CFLAGS) -o $@ macintalk.c -lm + +voices: $(SOURCES)/fred.ttvd + +$(SOURCES)/fred.ttvd: + python3 ../../tools/fetch-macintalk.py $(SOURCES) + +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)/ + +test: macintalk voices + @for v in $$(./macintalk -d $(SOURCES) -l | cut -d' ' -f1); do \ + ./macintalk -d $(SOURCES) -v $$v -o /tmp/macintalk-$$v.wav \ + "At the third stroke, it will be ten oh five and twenty seconds." && \ + echo "/tmp/macintalk-$$v.wav"; \ + done + +clean: + rm -f macintalk + +.PHONY: voices install test clean diff --git a/synth/macintalk/README.md b/synth/macintalk/README.md new file mode 100644 index 0000000..cae47bd --- /dev/null +++ b/synth/macintalk/README.md @@ -0,0 +1,70 @@ +# macintalk + +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). + +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 +voice data holds and what is ours. + +``` +make # build ./macintalk (C99, no dependencies but libm) +make voices # download the voice data to ../../sources/macintalk +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 fred "At the third stroke, it will be ten oh five." | aplay +``` + +Options: `-v voice` (default fred), `-d dir` (the voice folder; default +`$MACINTALK_VOICES`, then `/usr/local/share/macintalk`, +`/usr/share/macintalk`, `./sources/macintalk`), `-o file` (default: the +WAV goes to standard output), `-r wpm` and `-p hz` (override the voice's +rate and pitch), `-x` (print the phonemes instead). The WAV is 22050 Hz, +16-bit mono. + +The text can carry Speech Manager commands: `[[inpt PHON]]` switches to +Apple's phoneme symbols (`1EHkspIHrIHmEHnt`), `[[inpt TEXT]]` back, +`[[rate 200]]`, `[[pbas 50]]` (base pitch, as a MIDI note), `[[slnc 500]]` +(silence, ms). + +## 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: + +``` +tts_program_macintalk=/usr/local/bin/macintalk +``` + +The voice data must be in one of the default folders (or set +`MACINTALK_VOICES` in Asterisk's environment). + +## How it works + +1. Text to phonemes: numbers and times ("10:05") to words, a short word + list for the clock's words and common ones, and the NRL letter-to-sound + rules (Elovitz et al. 1976, public domain) for everything else. +2. Timing: each phoneme's length from Klatt's rules (shorter when + unstressed, longer at the end of a phrase), scaled to the voice's rate. + Stops get a closure, a burst and, before a vowel, aspiration. +3. Pitch: a falling line per phrase with a rise on each stressed syllable + and a fall (or a question's rise) at the end, scaled by the voice's pitch + and modulation. The singing voices put each vowel on the next note of + their tune. +4. Sound: the voice source is built harmonic by harmonic from the voice's + own glottal spectra (or from its sampled sound), mixed with breath noise, + and shaped by a cascade of five formant resonators and a nasal pole and + zero, with the voice's formant shifts and bandwidths; fricatives and + bursts are noise through their own band. + +Pronunciation and rhythm are ours, so the voices sound like MacInTalk 3's +voices rather than exactly like them. diff --git a/synth/macintalk/macintalk.c b/synth/macintalk/macintalk.c new file mode 100644 index 0000000..aface17 --- /dev/null +++ b/synth/macintalk/macintalk.c @@ -0,0 +1,1316 @@ +/* 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. + * + * 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' + * (and 'ttvw') resources of Apple's voice files, which + * tools/fetch-macintalk.py takes from a Mac OS 8.1 disk image at build + * time. What each field of a voice means was worked out by comparing the + * 19 voices (docs/macintalk-format.md). The rest is our own: the NRL + * letter-to-sound rules (rules.h, public domain), the prosody, and a + * formant synthesiser in the style of D. H. Klatt's 1980 design. The voice + * gives the synthesiser its pitch, speed, glottal source spectrum, formant + * and bandwidth settings, breathiness, chorus, melody and sampled sound. + * + * 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 + * + * The text may hold Speech Manager commands: [[inpt PHON]] (Apple's + * phoneme symbols follow) and [[inpt TEXT]], [[rate N]], [[pbas N]], + * [[slnc N]]. Without -o the WAV (22050 Hz, 16-bit, mono) goes to standard + * output. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rules.h" + +#define FS 22050 +#define NHARM 47 +#define MAXSEG 4096 +#define BLOCK 32 /* samples between parameter updates */ + +static double frand(void) +{ + static uint32_t s = 22222; + s = s * 1103515245u + 12345u; + return ((s >> 9) & 0xffff) / 32768.0 - 1.0; +} + +/* ---- phonemes ------------------------------------------------------------ */ + +enum { V = 1, DIPH = 2, SON = 4, NAS = 8, FRIC = 16, STOP = 32, AFFR = 64, VOI = 128, ASP = 256 }; + +struct phon { + const char *name; + int flags; + double f1, f2, f3, e1, e2, e3; /* formants, and where a diphthong ends */ + double b1, b2, b3; + double dur; /* ms at 170 wpm */ + double av, af; /* voicing and frication, dB */ + double fc, fbw; /* frication (or burst) noise band */ +}; + +static const struct phon ph[] = { + { "_", 0, 500, 1500, 2500, 0, 0, 0, 100, 100, 100, 100, 0, 0, 0, 0 }, + { "IY", V | VOI, 310, 2020, 2960, 0, 0, 0, 45, 200, 400, 155, 60, 0, 0, 0 }, + { "IH", V | VOI, 400, 1800, 2570, 0, 0, 0, 50, 100, 140, 125, 60, 0, 0, 0 }, + { "EY", V | DIPH | VOI, 480, 1720, 2520, 330, 2200, 2600, 70, 100, 200, 185, 60, 0, 0, 0 }, + { "EH", V | VOI, 530, 1680, 2500, 0, 0, 0, 60, 90, 200, 140, 60, 0, 0, 0 }, + { "AE", V | VOI, 620, 1660, 2430, 0, 0, 0, 70, 150, 320, 210, 60, 0, 0, 0 }, + { "AA", V | VOI, 700, 1220, 2600, 0, 0, 0, 130, 70, 160, 210, 60, 0, 0, 0 }, + { "AO", V | VOI, 600, 990, 2570, 0, 0, 0, 90, 100, 80, 210, 60, 0, 0, 0 }, + { "OW", V | DIPH | VOI, 540, 1100, 2300, 450, 900, 2300, 80, 70, 70, 200, 60, 0, 0, 0 }, + { "UH", V | VOI, 450, 1100, 2350, 0, 0, 0, 80, 100, 80, 140, 60, 0, 0, 0 }, + { "UW", V | DIPH | VOI, 350, 1250, 2200, 320, 900, 2200, 65, 110, 140, 190, 60, 0, 0, 0 }, + { "AX", V | VOI, 500, 1400, 2300, 0, 0, 0, 100, 100, 200, 90, 58, 0, 0, 0 }, + { "IX", V | VOI, 420, 1650, 2500, 0, 0, 0, 70, 100, 200, 90, 58, 0, 0, 0 }, + { "AH", V | VOI, 620, 1220, 2550, 0, 0, 0, 80, 50, 140, 140, 60, 0, 0, 0 }, + { "ER", V | VOI, 470, 1270, 1540, 0, 0, 0, 100, 60, 110, 170, 60, 0, 0, 0 }, + { "AY", V | DIPH | VOI, 660, 1200, 2550, 400, 1880, 2500, 100, 70, 200, 240, 60, 0, 0, 0 }, + { "AW", V | DIPH | VOI, 640, 1230, 2550, 420, 940, 2350, 80, 70, 140, 250, 60, 0, 0, 0 }, + { "OY", V | DIPH | VOI, 550, 960, 2400, 360, 1820, 2450, 80, 50, 130, 260, 60, 0, 0, 0 }, + { "l", SON | VOI, 330, 1050, 2400, 0, 0, 0, 50, 100, 280, 70, 54, 0, 0, 0 }, + { "r", SON | VOI, 310, 1060, 1380, 0, 0, 0, 70, 100, 120, 70, 54, 0, 0, 0 }, + { "w", SON | VOI, 290, 610, 2150, 0, 0, 0, 50, 80, 60, 70, 54, 0, 0, 0 }, + { "y", SON | VOI, 260, 2070, 3020, 0, 0, 0, 40, 250, 500, 60, 54, 0, 0, 0 }, + { "m", NAS | VOI, 480, 1270, 2130, 0, 0, 0, 40, 200, 200, 70, 52, 0, 0, 0 }, + { "n", NAS | VOI, 480, 1340, 2470, 0, 0, 0, 40, 300, 300, 60, 52, 0, 0, 0 }, + { "N", NAS | VOI, 480, 2000, 2700, 0, 0, 0, 160, 150, 100, 90, 52, 0, 0, 0 }, + { "h", ASP, 500, 1500, 2500, 0, 0, 0, 200, 150, 200, 70, 0, 0, 0, 0 }, + { "f", FRIC, 340, 1100, 2080, 0, 0, 0, 200, 120, 150, 100, 0, 44, 6000, 6000 }, + { "v", FRIC | VOI, 220, 1100, 2080, 0, 0, 0, 60, 90, 120, 65, 48, 38, 6000, 6000 }, + { "T", FRIC, 320, 1290, 2540, 0, 0, 0, 200, 90, 200, 90, 0, 42, 5500, 5000 }, + { "D", FRIC | VOI, 270, 1290, 2540, 0, 0, 0, 60, 80, 170, 50, 50, 36, 5500, 5000 }, + { "s", FRIC, 320, 1390, 2530, 0, 0, 0, 200, 80, 200, 110, 0, 50, 5200, 2000 }, + { "z", FRIC | VOI, 240, 1390, 2530, 0, 0, 0, 70, 60, 180, 80, 48, 45, 5200, 2000 }, + { "S", FRIC, 300, 1840, 2750, 0, 0, 0, 200, 100, 300, 110, 0, 57, 2900, 1800 }, + { "Z", FRIC | VOI, 280, 1840, 2750, 0, 0, 0, 70, 100, 300, 80, 48, 50, 2900, 1800 }, + { "p", STOP, 400, 1100, 2150, 0, 0, 0, 300, 150, 220, 80, 0, 50, 1200, 2500 }, + { "b", STOP | VOI, 200, 1100, 2150, 0, 0, 0, 60, 110, 130, 65, 0, 45, 1200, 2500 }, + { "t", STOP, 400, 1600, 2600, 0, 0, 0, 300, 120, 250, 70, 0, 56, 4200, 3000 }, + { "d", STOP | VOI, 200, 1600, 2600, 0, 0, 0, 60, 100, 170, 60, 0, 50, 4200, 3000 }, + { "k", STOP, 300, 1990, 2850, 0, 0, 0, 250, 160, 330, 80, 0, 54, 2300, 1500 }, + { "g", STOP | VOI, 200, 1990, 2850, 0, 0, 0, 60, 150, 280, 65, 0, 50, 2300, 1500 }, + { "C", AFFR, 350, 1800, 2820, 0, 0, 0, 200, 90, 300, 70, 0, 56, 2900, 1800 }, + { "J", AFFR | VOI, 260, 1800, 2820, 0, 0, 0, 60, 80, 270, 60, 0, 50, 2900, 1800 }, +}; +#define NPH ((int)(sizeof(ph) / sizeof(ph[0]))) + +static int ph_find(const char *s, size_t n) +{ + int i; + for (i = 1; i < NPH; i++) + if (strlen(ph[i].name) == n && !strncmp(ph[i].name, s, n)) + return i; + return -1; +} + +/* Apple's phoneme symbols (Speech Manager, [[inpt PHON]]) */ +static const struct { const char *apple, *ours; } apple_ph[] = { + { "AE", "AE" }, { "EY", "EY" }, { "AO", "AO" }, { "AX", "AX" }, { "IY", "IY" }, + { "EH", "EH" }, { "IH", "IH" }, { "AY", "AY" }, { "IX", "IX" }, { "AA", "AA" }, + { "UW", "UW" }, { "UH", "UH" }, { "UX", "AH" }, { "OW", "OW" }, { "AW", "AW" }, + { "OY", "OY" }, { "b", "b" }, { "C", "C" }, { "d", "d" }, { "D", "D" }, + { "f", "f" }, { "g", "g" }, { "h", "h" }, { "J", "J" }, { "k", "k" }, + { "l", "l" }, { "m", "m" }, { "n", "n" }, { "N", "N" }, { "p", "p" }, + { "r", "r" }, { "s", "s" }, { "S", "S" }, { "t", "t" }, { "T", "T" }, + { "v", "v" }, { "w", "w" }, { "y", "y" }, { "z", "z" }, { "Z", "Z" }, +}; + +/* ---- voices ---------------------------------------------------------------- */ + +struct voice { + char name[64], comment[256]; + int16_t w[200]; /* the MacinTalk 3 parameter block, see below */ + int nw; + double tab[2][NHARM]; /* two glottal source spectra */ + int nnotes; + int note_dur[64], note_semi[64]; + float *wave; /* the voice's sampled sound (ttvw), or NULL */ + int nwave, nseg, seg[16]; +}; + +/* Fields of the parameter block (16-bit words after the Speech Manager + * VoiceDescription) that this synthesiser uses. docs/macintalk-format.md + * lists all of them. */ +enum { + W_PITCH = 0, W_PMOD = 1, W_RATE = 3, W_BREATH = 6, W_VOICING = 7, + W_F4 = 8, W_B4 = 9, W_F5 = 10, W_B5 = 11, W_FNP = 16, W_FNZ = 17, + W_B1PCT = 20, W_B2PCT = 21, W_B3PCT = 22, W_DF1 = 23, W_DF2 = 24, W_DF3 = 25, + W_CHORUS = 26, W_GAIN = 27, W_WAVEMODE = 46, W_TAB_A = 48, W_TAB_B = 96, + W_NOTES = 174, +}; + +static int voice_load(struct voice *v, const char *dir, const char *id) +{ + char path[1024]; + unsigned char buf[4096]; + FILE *f; + size_t n, i; + + memset(v, 0, sizeof(*v)); + snprintf(path, sizeof(path), "%s/%s.ttvd", dir, id); + if (!(f = fopen(path, "rb"))) + return -1; + n = fread(buf, 1, sizeof(buf), f); + fclose(f); + if (n < 362 + 2 * 176 || memcmp(buf + 4, "mtk3", 4)) { + fprintf(stderr, "macintalk: %s: not a MacinTalk 3 voice\n", path); + return -1; + } + /* VoiceDescription: length, VoiceSpec, version, Str63 name, Str255 comment ... */ + memcpy(v->name, buf + 17, buf[16] < 63 ? buf[16] : 63); + memcpy(v->comment, buf + 81, buf[80]); + v->nw = (int)((n - 362) / 2); + if (v->nw > 200) + v->nw = 200; + for (i = 0; i < (size_t)v->nw; i++) + v->w[i] = (int16_t)(buf[362 + 2 * i] << 8 | buf[363 + 2 * i]); + for (i = 0; i < NHARM; i++) { + v->tab[0][i] = v->w[W_TAB_A + i] > 21 ? v->w[W_TAB_A + i] : 0; + v->tab[1][i] = v->w[W_TAB_B + i] > 21 ? v->w[W_TAB_B + i] : 0; + } + for (int t = 0; t < 2; t++) { + double e = 0; + for (i = 0; i < NHARM; i++) + e += v->tab[t][i] * v->tab[t][i]; + for (i = 0; i < NHARM; i++) + v->tab[t][i] = e > 0 ? v->tab[t][i] / sqrt(e) : (i == 0); + } + if (v->nw > W_NOTES && v->w[W_NOTES] > 1) { + v->nnotes = v->w[W_NOTES] < 64 ? v->w[W_NOTES] : 64; + if (v->nnotes > v->nw - W_NOTES - 1) + v->nnotes = v->nw - W_NOTES - 1; + for (i = 0; i < (size_t)v->nnotes; i++) { + uint16_t x = (uint16_t)v->w[W_NOTES + 1 + i]; + v->note_dur[i] = x >> 8; + v->note_semi[i] = (int8_t)(x & 0xff); + } + } + + /* the sampled sound: u32 length, [u32 count, count u32 offsets], 8-bit samples */ + snprintf(path, sizeof(path), "%s/%s.ttvw", dir, id); + if ((f = fopen(path, "rb"))) { + unsigned char *w; + long len; + fseek(f, 0, SEEK_END); + len = ftell(f); + fseek(f, 0, SEEK_SET); + w = malloc(len > 0 ? len : 1); + if (w && fread(w, 1, len, f) == (size_t)len && len > 8) { + uint32_t dl = (uint32_t)w[0] << 24 | w[1] << 16 | w[2] << 8 | w[3]; + long off = 4; + v->nseg = 1; + v->seg[0] = 0; + if ((long)dl + 4 != len) { + uint32_t c = (uint32_t)w[4] << 24 | w[5] << 16 | w[6] << 8 | w[7]; + if (c >= 2 && c <= 16 && 8 + 4 * (long)c + (long)dl == len) { + for (i = 0; i < c; i++) + v->seg[i] = w[8 + 4 * i] << 24 | w[9 + 4 * i] << 16 | + w[10 + 4 * i] << 8 | w[11 + 4 * i]; + v->nseg = (int)c - 1; + off = 8 + 4 * (long)c; + } + } + if (off + (long)dl > len) + dl = (uint32_t)(len - off); + v->nwave = (int)dl; + v->seg[v->nseg] = v->nwave; + v->wave = malloc(sizeof(float) * (dl ? dl : 1)); + double mean = 0, rms = 0; + for (i = 0; i < dl; i++) + mean += w[off + i]; + mean /= dl ? dl : 1; + for (i = 0; i < dl; i++) { + v->wave[i] = (float)((w[off + i] - mean) / 128.0); + rms += v->wave[i] * v->wave[i]; + } + rms = sqrt(rms / (dl ? dl : 1)); + for (i = 0; i < dl && rms > 0; i++) + v->wave[i] = (float)(v->wave[i] / rms * 0.707); + } + free(w); + fclose(f); + } + return 0; +} + +/* ---- text to phonemes --------------------------------------------------- */ + +struct tok { /* one phoneme of the input, before timing */ + int ph, stress, word, func, pause_ms, punct; +}; + +static struct tok toks[MAXSEG]; +static int ntok, nword; + +static void add_tok(int p, int stress, int func) +{ + if (ntok >= MAXSEG) + return; + toks[ntok].ph = p; + toks[ntok].stress = stress; + toks[ntok].word = nword; + toks[ntok].func = func; + toks[ntok].pause_ms = 0; + toks[ntok].punct = 0; + ntok++; +} + +static void add_pause(int ms, int punct) +{ + if (ntok > 0 && toks[ntok - 1].ph == 0) { + if (toks[ntok - 1].pause_ms < ms) + toks[ntok - 1].pause_ms = ms; + if (punct) + toks[ntok - 1].punct = punct; + return; + } + add_tok(0, 0, 0); + toks[ntok - 1].pause_ms = ms; + toks[ntok - 1].punct = punct; +} + +/* "1EY t" -> phonemes; returns whether any stress was marked */ +static int add_phstr(const char *s, int func, int stress_first) +{ + int marked = 0, first = ntok; + while (*s) { + int st = 0, p; + const char *e; + while (*s == ' ') + s++; + if (!*s) + break; + if (*s == '1' || *s == '2') { + st = *s == '1' ? 2 : 1; + marked = 1; + s++; + } + for (e = s; *e && *e != ' '; e++) + ; + if ((p = ph_find(s, e - s)) > 0) + add_tok(p, st, func); + s = e; + } + if (!marked && stress_first && !func) { + for (int i = first; i < ntok; i++) + if (ph[toks[i].ph].flags & V) { + toks[i].stress = 2; + break; + } + } + return marked; +} + +static int isvowel(int c) { return strchr("AEIOU", c) != NULL; } +static int iscons(int c) { return c >= 'A' && c <= 'Z' && !isvowel(c); } + +/* does context pattern pat fit word w around position [pos]? dir -1 is the + * left context (read right to left), +1 the right one */ +static int ctx(const char *w, int pos, const char *pat, int dir) +{ + int n = (int)strlen(pat), i; + int k = pos; + for (i = dir < 0 ? n - 1 : 0; dir < 0 ? i >= 0 : i < n; i += dir) { + char c = pat[i]; + char x = (k >= 0 && w[k]) ? w[k] : ' '; + if (k < 0) + x = ' '; + switch (c) { + case '#': + if (!isvowel(x)) + return 0; + while (k + dir >= 0 && w[k + dir] && isvowel(w[k + dir])) + k += dir; + break; + case ':': + while (k >= 0 && w[k] && iscons(w[k])) + k += dir; + k -= dir; + break; + case '^': + if (!iscons(x)) + return 0; + break; + case '.': + if (!strchr("BDVGJLMNRWZ", x) || x == ' ') + return 0; + break; + case '+': + if (!strchr("EIY", x) || x == ' ') + return 0; + break; + case '&': + if (k >= 1 && (w[k] == 'H') && (w[k - 1] == 'C' || w[k - 1] == 'S')) { + k--; + break; + } + if (!strchr("SCGZXJ", x) || x == ' ') + return 0; + break; + case '@': + if (k >= 1 && w[k] == 'H' && strchr("TCS", w[k - 1])) { + k--; + break; + } + if (!strchr("TSRDLZNJ", x) || x == ' ') + return 0; + break; + case '%': { + static const char *suf[] = { "ING", "ELY", "ER", "ES", "ED", "E", NULL }; + int j, ok = 0; + for (j = 0; suf[j]; j++) { + size_t l = strlen(suf[j]); + if (k >= 0 && !strncmp(w + k, suf[j], l)) { + k += (int)l - 1; + ok = 1; + break; + } + } + if (!ok) + return 0; + break; + } + case ' ': + if (x != ' ' && isalpha((unsigned char)x)) + return 0; + break; + default: + if (x != c) + return 0; + } + k += dir; + } + return 1; +} + +/* English word (upper case, framed by spaces in buf) -> phonemes */ +static void nrl_word(const char *word, int func) +{ + char w[128]; + int i, n = (int)strlen(word), start = ntok; + if (n > 120) + n = 120; + w[0] = ' '; + memcpy(w + 1, word, n); + w[n + 1] = ' '; + w[n + 2] = 0; + i = 1; + while (i <= n) { + const struct rule *r; + int c = w[i]; + if (c >= 'A' && c <= 'Z') + r = rules[c - 'A']; + else + r = rules_punct; + for (; r->match; r++) { + size_t ml = strlen(r->match); + if (strncmp(w + i, r->match, ml)) + continue; + if (!ctx(w, i - 1, r->left, -1)) + continue; + if (!ctx(w, i + (int)ml, r->right, 1)) + continue; + add_phstr(r->out, 1, 0); + i += (int)ml; + break; + } + if (!r->match) + i++; + } + for (i = start; i < ntok; i++) + toks[i].func = func; + if (!func) + for (i = start; i < ntok; i++) + if (ph[toks[i].ph].flags & V) { + toks[i].stress = 2; + break; + } +} + +static const char *ones[] = { "zero", "one", "two", "three", "four", "five", "six", + "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", + "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; +static const char *tens[] = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", + "seventy", "eighty", "ninety" }; + +static void say_word(const char *word); + +static void say_number(long n) +{ + if (n >= 1000000) { + say_number(n / 1000000); + say_word("million"); + n %= 1000000; + if (!n) + return; + } + if (n >= 1000) { + say_number(n / 1000); + say_word("thousand"); + n %= 1000; + if (!n) + return; + } + if (n >= 100) { + say_word(ones[n / 100]); + say_word("hundred"); + n %= 100; + if (!n) + return; + } + if (n >= 20) { + say_word(tens[n / 10]); + if (n % 10) + say_word(ones[n % 10]); + return; + } + say_word(ones[n]); +} + +static void say_word(const char *word) +{ + char lw[128], uw[128]; + size_t i, n = strlen(word); + int j; + if (n >= sizeof(lw)) + n = sizeof(lw) - 1; + for (i = 0; i < n; i++) { + lw[i] = (char)tolower((unsigned char)word[i]); + uw[i] = (char)toupper((unsigned char)word[i]); + } + lw[n] = uw[n] = 0; + nword++; + for (j = 0; lexicon[j].word; j++) + if (!strcmp(lexicon[j].word, lw)) { + int func = !strchr(lexicon[j].ph, '1'); + add_phstr(lexicon[j].ph, func, 0); + return; + } + /* a lone letter, or letters with dots (U.S.A.) */ + if (n == 1 && isalpha((unsigned char)uw[0]) && uw[0] != 'A' && uw[0] != 'I') { + static const char *names[26] = { "1EY", "b 1IY", "s 1IY", "d 1IY", "1IY", + "1EH f", "J 1IY", "1EY C", "1AY", "J 1EY", "k 1EY", "1EH l", "1EH m", + "1EH n", "1OW", "p 1IY", "k y 1UW", "1AA r", "1EH s", "t 1IY", "y 1UW", + "v 1IY", "d 1AH b AX l y UW", "1EH k s", "w 1AY", "z 1IY" }; + add_phstr(names[uw[0] - 'A'], 0, 0); + return; + } + nrl_word(uw, 0); +} + +/* Speech Manager embedded command [[...]] */ +static int phon_mode; +static double cmd_rate, cmd_pitch; + +static void command(const char *c) +{ + char name[8] = { 0 }; + double arg = 0; + if (sscanf(c, " %4s %lf", name, &arg) < 1) + return; + if (!strcasecmp(name, "inpt")) + phon_mode = strstr(c, "PHON") || strstr(c, "phon"); + else if (!strcasecmp(name, "rate") && arg > 0) + cmd_rate = arg; + else if (!strcasecmp(name, "pbas") && arg > 0) + cmd_pitch = 440.0 * pow(2, (arg - 69) / 12.0); + else if (!strcasecmp(name, "slnc") && arg > 0) + add_pause((int)arg, 0); +} + +static void apple_phonemes(const char *s, const char *end) +{ + int stress = 0; + nword++; + while (s < end) { + size_t i, best = 0; + int p = -1; + if (*s == '1' || *s == '2') { + stress = *s == '1' ? 2 : 1; + s++; + continue; + } + if (*s == ' ' || *s == '\t' || *s == '\n') { + nword++; + s++; + continue; + } + if (*s == '_' || *s == '%' || *s == '@') { + add_pause(*s == '_' ? 100 : 60, 0); + s++; + continue; + } + if (strchr(".!?;:,", *s)) { + add_pause(*s == ',' ? 220 : 400, *s); + s++; + continue; + } + for (i = 0; i < sizeof(apple_ph) / sizeof(apple_ph[0]); i++) { + size_t l = strlen(apple_ph[i].apple); + if (l > best && (size_t)(end - s) >= l && !strncmp(s, apple_ph[i].apple, l)) { + best = l; + p = ph_find(apple_ph[i].ours, strlen(apple_ph[i].ours)); + } + } + if (p > 0) { + add_tok(p, (ph[p].flags & V) ? stress : 0, 0); + if (ph[p].flags & V) + stress = 0; + s += best; + } else { + s++; /* = ~ and other marks */ + } + } +} + +static void parse(const char *text) +{ + const char *s = text; + ntok = nword = 0; + add_pause(60, 0); + while (*s) { + if (s[0] == '[' && s[1] == '[') { + const char *e = strstr(s, "]]"); + char c[64]; + size_t l; + if (!e) + break; + l = (size_t)(e - s - 2) < sizeof(c) - 1 ? (size_t)(e - s - 2) : sizeof(c) - 1; + memcpy(c, s + 2, l); + c[l] = 0; + command(c); + s = e + 2; + continue; + } + if (phon_mode) { + const char *e = strstr(s, "[["); + if (!e) + e = s + strlen(s); + apple_phonemes(s, e); + s = e; + continue; + } + if (isdigit((unsigned char)*s)) { + long n = 0; + while (isdigit((unsigned char)*s)) + n = n * 10 + (*s++ - '0'); + if (*s == ':' && isdigit((unsigned char)s[1])) { + /* 10:05 */ + long m = 0; + s++; + while (isdigit((unsigned char)*s)) + m = m * 10 + (*s++ - '0'); + say_number(n); + if (m == 0) + say_word("o'clock"); + else { + if (m < 10) + say_word("oh"); + say_number(m); + } + } else { + say_number(n); + } + continue; + } + if (isalpha((unsigned char)*s)) { + char w[128]; + size_t n = 0; + while ((isalpha((unsigned char)*s) || *s == '\'' || + (*s == '.' && isalpha((unsigned char)s[1]) && s[2] == '.')) && n < sizeof(w) - 3) { + w[n++] = *s++; + if (s[-1] == '.' && n < sizeof(w) - 1) + w[n++] = *s++; + } + if (*s == '.' && n >= 3 && w[n - 2] == '.') + w[n++] = *s++; /* the last dot of a.m. */ + w[n] = 0; + if (n && w[n - 1] == '\'') + w[--n] = 0; + if (!strchr(w, '.') || strlen(w) <= 4) { + say_word(w); + } else { + char *p = w, *q; + while ((q = strchr(p, '.'))) { + *q = 0; + if (*p) + say_word(p); + p = q + 1; + } + } + continue; + } + switch (*s) { + case ',': case ';': case ':': + add_pause(220, ','); + break; + case '.': case '!': + add_pause(420, '.'); + break; + case '?': + add_pause(420, '?'); + break; + case '-': + if (s[1] == ' ' || s[1] == '-') + add_pause(150, ','); + break; + } + s++; + } + add_pause(120, '.'); +} + +/* ---- timing and pitch ------------------------------------------------------ */ + +enum { K_NORM, K_CLOSE, K_BURST, K_ASP }; + +struct seg { + int ph, kind, stress, tok; + double t0, dur; + double f0; /* melody pitch for this vowel (0: intonation) */ +}; + +static struct seg segs[MAXSEG * 3]; +static int nseg; + +static void add_seg(int p, int kind, double dur, int stress, int tok) +{ + struct seg *s; + if (nseg >= MAXSEG * 3 || dur <= 0) + return; + s = &segs[nseg++]; + s->ph = p; + s->kind = kind; + s->dur = dur; + s->stress = stress; + s->tok = tok; + s->f0 = 0; +} + +static int is_vowelish(int p) { return p > 0 && (ph[p].flags & (V | SON | NAS)); } + +static void timing(const struct voice *v, double rate) +{ + double scale = 170.0 / rate; + int i, note = 0; + nseg = 0; + for (i = 0; i < ntok; i++) { + int p = toks[i].ph, fl = ph[p].flags; + int next = i + 1 < ntok ? toks[i + 1].ph : 0; + double d = ph[p].dur; + /* phrase-final: no vowel between here and the next pause */ + int final = 0, j; + for (j = i + 1; j < ntok && toks[j].ph; j++) + if (ph[toks[j].ph].flags & V) + break; + if (j >= ntok || toks[j].ph == 0) + final = toks[j < ntok ? j : ntok - 1].punct != 0; + + if (p == 0) { + add_seg(0, K_NORM, toks[i].pause_ms * (scale < 1.5 ? scale : 1.5), 0, i); + continue; + } + if (fl & V) { + if (toks[i].stress == 0) + d *= toks[i].func ? 0.55 : 0.65; + else if (toks[i].stress == 1) + d *= 0.85; + if (next && (ph[next].flags & (STOP | FRIC | AFFR)) && !(ph[next].flags & VOI)) + d *= 0.85; + if (final) + d *= 1.35; + } else { + if (i > 0 && toks[i - 1].ph && !(ph[toks[i - 1].ph].flags & V) && + next && !(ph[next].flags & V)) + d *= 0.8; + if (final) + d *= 1.15; + } + d *= scale; + if ((fl & V) && v->nnotes) { + /* a singing voice: each vowel takes the next note of its tune */ + double nd = v->note_dur[note % v->nnotes] * 75.0 * scale; + add_seg(p, K_NORM, nd > 60 ? nd : 60, toks[i].stress, i); + segs[nseg - 1].f0 = v->note_semi[note % v->nnotes]; + segs[nseg - 1].f0 = 1000 + segs[nseg - 1].f0; /* semitones, marked */ + note++; + continue; + } + if (fl & STOP) { + int before_v = next && is_vowelish(next); + add_seg(p, K_CLOSE, d * 0.75, 0, i); + add_seg(p, K_BURST, 12, 0, i); + if (!(fl & VOI) && before_v) + add_seg(p, K_ASP, 45 * (scale < 1.3 ? scale : 1.3), 0, i); + continue; + } + if (fl & AFFR) { + add_seg(p, K_CLOSE, d * 0.6, 0, i); + add_seg(p, K_NORM, d * 0.7, 0, i); + continue; + } + add_seg(p, K_NORM, d, toks[i].stress, i); + } + double t = 0; + for (i = 0; i < nseg; i++) { + segs[i].t0 = t; + t += segs[i].dur; + } +} + +/* pitch at time t (ms): a falling line per phrase, a rise on each stressed + * syllable, a fall (or a rise, for a question) at the end */ +struct pitchpt { double t, hz; }; +static struct pitchpt *pp; +static int npp; + +static void add_pp(double t, double hz) +{ + pp = realloc(pp, sizeof(*pp) * (npp + 1)); + pp[npp].t = t; + pp[npp].hz = hz; + npp++; +} + +static void intonation(const struct voice *v, double base) +{ + double mod = v->w[W_PMOD] / 100.0; + int i = 0; + npp = 0; + while (i < nseg) { + int j, k, last_stress = -1, punct; + double t0, t1, top, bot; + while (i < nseg && segs[i].ph == 0) + i++; + if (i >= nseg) + break; + for (j = i; j < nseg && segs[j].ph != 0; j++) + ; + punct = j < nseg ? toks[segs[j].tok].punct : '.'; + t0 = segs[i].t0; + t1 = segs[j - 1].t0 + segs[j - 1].dur; + top = base * (1 + 0.12 * mod); + bot = base * (1 - 0.08 * mod); + for (k = i; k < j; k++) + if ((ph[segs[k].ph].flags & V) && segs[k].stress == 2) + last_stress = k; + add_pp(t0, top); + for (k = i; k < j; k++) { + struct seg *s = &segs[k]; + double frac = (s->t0 - t0) / (t1 - t0 + 1); + double line = top + (bot - top) * frac; + if (s->f0 >= 900) { + double hz = base * pow(2, (s->f0 - 1000) / 12.0); + add_pp(s->t0 + 5, hz); + add_pp(s->t0 + s->dur - 5, hz); + continue; + } + if (!(ph[s->ph].flags & V) || s->stress < 2) + continue; + if (k == last_stress && punct != ',') { + if (punct == '?') { + add_pp(s->t0, line); + add_pp(t1, line * (1 + 0.45 * mod)); + } else { + add_pp(s->t0, line * (1 + 0.22 * mod)); + add_pp(s->t0 + s->dur, line * (1 - 0.18 * mod)); + add_pp(t1, line * (1 - 0.25 * mod)); + } + } else { + add_pp(s->t0, line * (1 + 0.14 * mod)); + add_pp(s->t0 + s->dur * 0.5, line * (1 + 0.20 * mod)); + add_pp(s->t0 + s->dur + 30, line); + } + } + if (punct == ',') + add_pp(t1, bot * (1 + 0.1 * mod)); + else if (last_stress < 0) + add_pp(t1, bot); + i = j; + } + if (!npp) + add_pp(0, base); +} + +static double pitch_at(double t) +{ + int i; + if (t <= pp[0].t) + return pp[0].hz; + for (i = 1; i < npp; i++) + if (pp[i].t >= t) { + double a = pp[i - 1].t, b = pp[i].t; + if (b - a < 1e-6) + return pp[i].hz; + return pp[i - 1].hz + (pp[i].hz - pp[i - 1].hz) * (t - a) / (b - a); + } + return pp[npp - 1].hz; +} + +/* ---- synthesis ------------------------------------------------------------- */ + +struct reso { double a, b, c, y1, y2; }; + +static void reso_set(struct reso *r, double f, double bw) +{ + double rr = exp(-M_PI * bw / FS); + r->c = -rr * rr; + r->b = 2 * rr * cos(2 * M_PI * f / FS); + r->a = 1 - r->b - r->c; +} + +static double reso_run(struct reso *r, double x) +{ + double y = r->a * x + r->b * r->y1 + r->c * r->y2; + r->y2 = r->y1; + r->y1 = y; + return y; +} + +struct anti { double a, b, c, x1, x2; }; + +static void anti_set(struct anti *r, double f, double bw) +{ + double rr = exp(-M_PI * bw / FS); + double c = -rr * rr, b = 2 * rr * cos(2 * M_PI * f / FS), a = 1 - b - c; + r->a = 1 / a; + r->b = -b / a; + r->c = -c / a; +} + +static double anti_run(struct anti *r, double x) +{ + double y = r->a * x + r->b * r->x1 + r->c * r->x2; + r->x2 = r->x1; + r->x1 = x; + return y; +} + +struct params { + double f[3], b[3]; + double av, ah, af, fc, fbw, nasal, emph; +}; + +static double db(double x) { return x <= 0 ? 0 : pow(10, (x - 60) / 20); } + +/* the target of segment i at fraction u (0..1) through it */ +static void target(int i, double u, struct params *p) +{ + const struct seg *s = &segs[i]; + const struct phon *q = &ph[s->ph]; + int src = s->ph; + int k; + if ((s->kind == K_ASP || s->ph == 25 /* h */ || s->ph == 0) && i + 1 < nseg) { + /* h, aspiration and pauses take the shape of what follows */ + for (k = i + 1; k < nseg && segs[k].ph == segs[i].ph && segs[k].kind != K_NORM; k++) + ; + if (k < nseg && segs[k].ph) + src = segs[k].ph; + else if (i > 0) + src = segs[i - 1].ph; + } + q = &ph[src]; + for (k = 0; k < 3; k++) { + double a = (&q->f1)[k], e = (&q->e1)[k]; + if ((q->flags & DIPH) && e > 0 && s->ph == src) { + double w = u < 0.35 ? 0 : (u - 0.35) / 0.65; + a += (e - a) * w; + } + p->f[k] = a; + p->b[k] = (&q->b1)[k]; + } + q = &ph[s->ph]; + p->av = p->ah = p->af = 0; + p->fc = q->fc ? q->fc : 3000; + p->fbw = q->fbw ? q->fbw : 2000; + p->nasal = (q->flags & NAS) ? 1 : 0; + p->emph = s->stress == 2 ? 1 : s->stress == 1 ? 0.5 : 0; + if (s->ph == 0) + return; + switch (s->kind) { + case K_CLOSE: + if (q->flags & VOI) { + p->av = db(40); + p->f[0] = 180; + } + break; + case K_BURST: + p->af = db(q->af - 1); + if (q->flags & VOI) + p->av = db(38); + break; + case K_ASP: + p->ah = db(52); + break; + default: + if (s->ph == 25) + p->ah = db(54); + p->av = db(q->av + (s->stress == 2 ? 2 : 0)); + if (q->flags & (FRIC | AFFR)) + p->af = db(q->af); + } +} + +static void lerp(struct params *a, const struct params *b, double w) +{ + double *x = (double *)a; + const double *y = (const double *)b; + size_t i; + for (i = 0; i < sizeof(*a) / sizeof(double); i++) + x[i] += (y[i] - x[i]) * w; +} + +/* parameters at time t (ms), with transitions into and out of each segment */ +static void params_at(double t, int *hint, struct params *p) +{ + int i = *hint; + struct seg *s; + double u, tin, tout; + struct params o; + while (i + 1 < nseg && t >= segs[i + 1].t0) + i++; + *hint = i; + s = &segs[i]; + u = s->dur > 0 ? (t - s->t0) / s->dur : 0; + target(i, u, p); + tin = tout = 35; + if (s->kind == K_BURST || s->kind == K_CLOSE) + tin = tout = 8; + if (tin > s->dur / 2) + tin = s->dur / 2; + if (tout > s->dur / 2) + tout = s->dur / 2; + if (i > 0 && t - s->t0 < tin) { + struct params m; + target(i - 1, 1, &o); + m = o; + lerp(&m, p, 0.5); + double keep[4] = { p->av, p->ah, p->af, p->nasal }; + lerp(&m, p, (t - s->t0) / tin); + *p = (struct params){ { m.f[0], m.f[1], m.f[2] }, { m.b[0], m.b[1], m.b[2] }, + keep[0], keep[1], keep[2], m.fc, m.fbw, keep[3], m.emph }; + /* amplitudes change quickly */ + if (t - s->t0 < 6) { + double w = (t - s->t0) / 6; + p->av = o.av + (p->av - o.av) * (0.5 + 0.5 * w); + } + } else if (i + 1 < nseg && s->t0 + s->dur - t < tout) { + struct params m; + double keep[4] = { p->av, p->ah, p->af, p->nasal }; + target(i + 1, 0, &o); + m = o; + lerp(&m, p, 0.5); + lerp(&m, p, (s->t0 + s->dur - t) / tout); + *p = (struct params){ { m.f[0], m.f[1], m.f[2] }, { m.b[0], m.b[1], m.b[2] }, + keep[0], keep[1], keep[2], m.fc, m.fbw, keep[3], m.emph }; + if (s->t0 + s->dur - t < 6) { + double w = (s->t0 + s->dur - t) / 6; + p->av = o.av + (p->av - o.av) * (0.5 + 0.5 * w); + } + } +} + +static float sintab[4096]; + +static float *synth(const struct voice *v, double base, int *nout) +{ + double total = nseg ? segs[nseg - 1].t0 + segs[nseg - 1].dur : 0; + int n = (int)(total * FS / 1000) + FS / 10, i, hint = 0, wseg = 0, lastv = -1; + float *out = calloc(n, sizeof(float)); + struct reso r[5], fr, fr2, np; + struct anti nz; + struct params p = { { 0 } }; + double phase[3] = { 0, 0.33, 0.66 }, wpos[3] = { 0, 0, 0 }, lp = 0, lp2 = 0, hp = 0, rad = 0; + double breath = v->w[W_BREATH] / 100.0, voicing = v->w[W_VOICING] / 192.0; + double gain = v->w[W_GAIN] > 0 ? v->w[W_GAIN] / 100.0 : 1; + double bpct[3], df[3]; + double chorus = v->w[W_CHORUS] ? 1 + v->w[W_CHORUS] / 100.0 : 0; + int wavemode = v->wave ? v->w[W_WAVEMODE] : 0; + double f0 = base, jit = 0; + + if (!out) + return NULL; + for (i = 0; i < 4096; i++) + sintab[i] = (float)sin(2 * M_PI * i / 4096); + for (i = 0; i < 3; i++) { + bpct[i] = v->w[W_B1PCT + i] > 0 ? v->w[W_B1PCT + i] / 100.0 : 1; + df[i] = v->w[W_DF1 + i]; + } + memset(r, 0, sizeof(r)); + memset(&fr, 0, sizeof(fr)); + memset(&fr2, 0, sizeof(fr2)); + memset(&np, 0, sizeof(np)); + memset(&nz, 0, sizeof(nz)); + reso_set(&r[3], v->w[W_F4] > 0 ? v->w[W_F4] : 3300, v->w[W_B4] > 0 ? v->w[W_B4] : 250); + reso_set(&r[4], v->w[W_F5] > 0 && v->w[W_F5] < FS / 2 - 500 ? v->w[W_F5] : 3750, + v->w[W_B5] > 0 ? v->w[W_B5] : 200); + + for (i = 0; i < n; i++) { + double t = i * 1000.0 / FS, x = 0, noise = frand(), asp, fric; + int k; + if (i % BLOCK == 0) { + double fn; + params_at(t, &hint, &p); + for (k = 0; k < 3; k++) { + double f = p.f[k] + df[k], bw = p.b[k] * bpct[k]; + if (f < 150 + 100 * k) + f = 150 + 100 * k; + reso_set(&r[k], f, bw); + } + fn = v->w[W_FNP] > 0 ? v->w[W_FNP] : 270; + reso_set(&np, fn, 100); + anti_set(&nz, p.nasal ? (v->w[W_FNZ] > 0 ? v->w[W_FNZ] + 80 : 450) : fn, 100); + reso_set(&fr, p.fc, p.fbw); + reso_set(&fr2, p.fc * 1.5 < FS / 2 - 1000 ? p.fc * 1.5 : FS / 2 - 1000, p.fbw); + f0 = pitch_at(t); + if (cmd_pitch > 0 && v->nnotes == 0) + f0 *= 1; /* already in base */ + jit = 1 + 0.004 * frand(); + /* one-shot sampled sounds restart on each new vowel */ + if (wavemode == 2 && segs[hint].ph && (ph[segs[hint].ph].flags & V) && hint != lastv) { + lastv = hint; + wseg = (wseg + 1) % v->nseg; + wpos[0] = wpos[1] = wpos[2] = v->seg[wseg]; + } + } + + /* the voice source */ + if (p.av > 0) { + int c, nc = chorus > 0 ? 2 : 1; + for (c = 0; c < nc; c++) { + double fc = f0 * jit * (c ? chorus : 1), s = 0; + if (wavemode) { + /* the voice's sampled sound, played at the speaking pitch */ + double step = fc / base; + int lo = wavemode == 2 ? v->seg[wseg] : 0; + int hi = wavemode == 2 ? v->seg[wseg + 1] : v->nwave; + int a; + if (hi - lo < 4) { + lo = 0; + hi = v->nwave; + } + if (wpos[c] >= hi || wpos[c] < lo) + wpos[c] = lo + fmod(wpos[c] - lo, hi - lo); + a = (int)wpos[c]; + double fr_ = wpos[c] - a; + s = v->wave[a] * (1 - fr_) + v->wave[a + 1 < hi ? a + 1 : lo] * fr_; + wpos[c] += step * 11127.0 / FS; + } else { + int h; + double e = p.emph; + for (h = 0; h < NHARM && (h + 1) * fc < FS * 0.45; h++) { + double amp = v->tab[0][h] * (1 - e) + v->tab[1][h] * e; + if (amp > 0) + s += amp * sintab[(int)(phase[c] * (h + 1) * 4096) & 4095]; + } + phase[c] += fc / FS; + if (phase[c] >= 1) + phase[c] -= 1; + } + x += s * (c ? 0.8 : 1); + } + x *= p.av * voicing * 3; + } + /* breath and aspiration go through the vocal tract */ + lp = lp * 0.5 + noise * 0.5; + asp = lp * (p.ah * 1.5 + p.av * breath * 0.6); + x += asp; + /* the vocal tract: nasal pole and zero, five formants */ + x = anti_run(&nz, reso_run(&np, x)); + for (k = 0; k < 5; k++) + x = reso_run(&r[k], x); + /* radiation from the lips: +6 dB per octave */ + { + double y = x - rad; + rad = x; + x = y * 4; + } + /* frication: noise through its own band */ + fric = 0; + if (p.af > 0) { + double nn = noise; + hp = nn - lp2; + lp2 = nn; + if (p.fc < 3500) + hp = nn; /* sh, k, p: no extra tilt */ + fric = (reso_run(&fr, hp) * 0.7 + reso_run(&fr2, hp) * 0.15) * p.af * 1.2; + if (p.fbw >= 4000) + fric = hp * p.af * 0.3; /* f and th: a flat hiss */ + } + out[i] = (float)((x + fric) * gain); + } + *nout = n; + return out; +} + +/* ---- output ---------------------------------------------------------------- */ + +static void put16(FILE *f, int v) { fputc(v & 0xff, f); fputc((v >> 8) & 0xff, f); } +static void put32(FILE *f, uint32_t v) { put16(f, v & 0xffff); put16(f, v >> 16); } + +static int write_wav(FILE *f, const float *x, int n) +{ + double peak = 1e-9; + int i; + for (i = 0; i < n; i++) + if (fabs(x[i]) > peak) + peak = fabs(x[i]); + fwrite("RIFF", 1, 4, f); + put32(f, 36 + 2 * (uint32_t)n); + fwrite("WAVEfmt ", 1, 8, f); + put32(f, 16); + put16(f, 1); + put16(f, 1); + put32(f, FS); + put32(f, FS * 2); + put16(f, 2); + put16(f, 16); + fwrite("data", 1, 4, f); + put32(f, 2 * (uint32_t)n); + for (i = 0; i < n; i++) + put16(f, (int)lrint(x[i] / peak * 29000)); + return ferror(f) ? -1 : 0; +} + +static const char *default_dir(void) +{ + static const char *dirs[] = { "/usr/local/share/macintalk", "/usr/share/macintalk", + "sources/macintalk", NULL }; + const char *e = getenv("MACINTALK_VOICES"); + int i; + if (e && *e) + return e; + for (i = 0; dirs[i]; i++) { + DIR *d = opendir(dirs[i]); + if (d) { + closedir(d); + return dirs[i]; + } + } + return dirs[0]; +} + +static void usage(void) +{ + fprintf(stderr, + "usage: macintalk [-v voice] [-d voicedir] [-o out.wav] [-r wpm] [-p hz] text...\n" + " macintalk -l [-d voicedir]\n" + " macintalk -x [-v voice] text... (print phonemes)\n"); + exit(2); +} + +int main(int argc, char **argv) +{ + const char *dir = NULL, *vname = "fred", *outname = NULL; + char text[8192] = "", id[64]; + double rate = 0, pitch = 0; + int list = 0, show = 0, i, n; + struct voice v; + float *pcm; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-v") && i + 1 < argc) + vname = argv[++i]; + else if (!strcmp(argv[i], "-d") && i + 1 < argc) + dir = argv[++i]; + else if (!strcmp(argv[i], "-o") && i + 1 < argc) + outname = argv[++i]; + else if (!strcmp(argv[i], "-r") && i + 1 < argc) + rate = atof(argv[++i]); + else if (!strcmp(argv[i], "-p") && i + 1 < argc) + pitch = atof(argv[++i]); + else if (!strcmp(argv[i], "-l")) + list = 1; + else if (!strcmp(argv[i], "-x")) + show = 1; + else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) + usage(); + else if (argv[i][0] == '-' && argv[i][1]) + usage(); + else { + if (*text) + strncat(text, " ", sizeof(text) - strlen(text) - 1); + strncat(text, argv[i], sizeof(text) - strlen(text) - 1); + } + } + if (!dir) + dir = default_dir(); + if (list) { + DIR *d = opendir(dir); + struct dirent *e; + if (!d) { + fprintf(stderr, "macintalk: %s: %s\n", dir, strerror(errno)); + return 1; + } + while ((e = readdir(d))) { + size_t l = strlen(e->d_name); + if (l > 5 && !strcmp(e->d_name + l - 5, ".ttvd") && l - 5 < sizeof(id)) { + memcpy(id, e->d_name, l - 5); + id[l - 5] = 0; + if (!voice_load(&v, dir, id)) + printf("%-12s %-12s %3d Hz %3d wpm %s\n", id, v.name, v.w[W_PITCH], + v.w[W_RATE], v.comment); + } + } + closedir(d); + return 0; + } + if (!*text) + usage(); + 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)) { + fprintf(stderr, "macintalk: no voice %s in %s (run tools/fetch-macintalk.py)\n", + vname, dir); + return 1; + } + parse(text); + if (show) { + for (i = 0; i < ntok; i++) { + if (toks[i].ph == 0) { + printf("_ "); + continue; + } + printf("%s%s ", toks[i].stress == 2 ? "1" : toks[i].stress == 1 ? "2" : "", + ph[toks[i].ph].name); + } + printf("\n"); + return 0; + } + if (!rate) + rate = cmd_rate > 0 ? cmd_rate : v.w[W_RATE] > 0 ? v.w[W_RATE] : 170; + if (!pitch) + pitch = cmd_pitch > 0 ? cmd_pitch : v.w[W_PITCH] > 0 ? v.w[W_PITCH] : 100; + timing(&v, rate); + intonation(&v, pitch); + if (getenv("MACINTALK_DEBUG")) + 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); + if (!pcm) + return 1; + if (outname) { + FILE *f = fopen(outname, "wb"); + if (!f || write_wav(f, pcm, n) || fclose(f)) { + fprintf(stderr, "macintalk: %s: %s\n", outname, strerror(errno)); + return 1; + } + } else if (write_wav(stdout, pcm, n) || fflush(stdout)) { + return 1; + } + return 0; +} diff --git a/synth/macintalk/rules.h b/synth/macintalk/rules.h new file mode 100644 index 0000000..559a7c2 --- /dev/null +++ b/synth/macintalk/rules.h @@ -0,0 +1,497 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * + * English letter-to-sound rules. These are the rules of H. S. Elovitz, + * R. Johnson, A. McHugh and J. E. Shore, "Letter-to-Sound Rules for + * Automatic Translation of English Text to Phonetics", NRL Report 7948 + * (US Naval Research Laboratory, 1976), a US government work in the public + * domain, written out again here. Nothing in this file comes from Apple. + * + * Each rule is { left context, letters, right context, phonemes }. Context + * symbols: ' ' a word boundary, '#' one or more vowels, ':' zero or more + * consonants, '^' one consonant, '.' a voiced consonant (B D G J L M N R V + * W Z), '+' a front vowel (E I Y), '%' a suffix (ER E ES ED ING ELY), '&' a + * sibilant (S C G Z X J CH SH), '@' T S R D L Z N J TH CH SH. The rules + * for a letter are tried in order and the first that fits is used. + */ + +struct rule { const char *left, *match, *right, *out; }; + +static const struct rule rules_punct[] = { + { "", "'", "", "" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_a[] = { + { "", "A", " ", "AX" }, + { " ", "ARE", " ", "AA r" }, + { " ", "AR", "O", "AX r" }, + { "", "AR", "#", "EH r" }, + { " ^", "AS", "#", "EY s" }, + { "", "A", "WA", "AX" }, + { "", "AW", "", "AO" }, + { " :", "ANY", "", "EH n IY" }, + { "", "A", "^+#", "EY" }, + { "#:", "ALLY", "", "AX l IY" }, + { " ", "AL", "#", "AX l" }, + { "", "AGAIN", "", "AX g EH n" }, + { "#:", "AG", "E", "IH J" }, + { "", "A", "^+:#", "AE" }, + { " :", "A", "^+ ", "EY" }, + { "", "A", "^%", "EY" }, + { " ", "ARR", "", "AX r" }, + { "", "ARR", "", "AE r" }, + { " :", "AR", " ", "AA r" }, + { "", "AR", " ", "ER" }, + { "", "AR", "", "AA r" }, + { "", "AIR", "", "EH r" }, + { "", "AI", "", "EY" }, + { "", "AY", "", "EY" }, + { "", "AU", "", "AO" }, + { "#:", "AL", " ", "AX l" }, + { "#:", "ALS", " ", "AX l z" }, + { "", "ALK", "", "AO k" }, + { "", "AL", "^", "AO l" }, + { " :", "ABLE", "", "EY b AX l" }, + { "", "ABLE", "", "AX b AX l" }, + { "", "ANG", "+", "EY n J" }, + { "", "A", "", "AE" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_b[] = { + { " ", "BE", "^#", "b IH" }, + { "", "BEING", "", "b IY IH N" }, + { " ", "BOTH", " ", "b OW T" }, + { " ", "BUS", "#", "b IH z" }, + { "", "BUIL", "", "b IH l" }, + { "", "B", "", "b" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_c[] = { + { " ", "CH", "^", "k" }, + { "^E", "CH", "", "k" }, + { "", "CH", "", "C" }, + { " S", "CI", "#", "s AY" }, + { "", "CI", "A", "S" }, + { "", "CI", "O", "S" }, + { "", "CI", "EN", "S" }, + { "", "C", "+", "s" }, + { "", "CK", "", "k" }, + { "", "COM", "%", "k AH m" }, + { "", "C", "", "k" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_d[] = { + { "#:", "DED", " ", "d IH d" }, + { ".E", "D", " ", "d" }, + { "#^:E", "D", " ", "t" }, + { " ", "DE", "^#", "d IH" }, + { " ", "DO", " ", "d UW" }, + { " ", "DOES", "", "d AH z" }, + { " ", "DOING", "", "d UW IH N" }, + { " ", "DOW", "", "d AW" }, + { "", "DU", "A", "J UW" }, + { "", "D", "", "d" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_e[] = { + { "#:", "E", " ", "" }, + { "'^:", "E", " ", "" }, + { " :", "E", " ", "IY" }, + { "#", "ED", " ", "d" }, + { "#:", "E", "D ", "" }, + { "", "EV", "ER", "EH v" }, + { "", "E", "^%", "IY" }, + { "", "ERI", "#", "IY r IY" }, + { "", "ERI", "", "EH r IH" }, + { "#:", "ER", "#", "ER" }, + { "", "ER", "#", "EH r" }, + { "", "ER", "", "ER" }, + { " ", "EVEN", "", "IY v EH n" }, + { "#:", "E", "W", "" }, + { "@", "EW", "", "UW" }, + { "", "EW", "", "y UW" }, + { "", "E", "O", "IY" }, + { "#:&", "ES", " ", "IH z" }, + { "#:", "E", "S ", "" }, + { "#:", "ELY", " ", "l IY" }, + { "#:", "EMENT", "", "m EH n t" }, + { "", "EFUL", "", "f UH l" }, + { "", "EE", "", "IY" }, + { "", "EARN", "", "ER n" }, + { " ", "EAR", "^", "ER" }, + { "", "EAD", "", "EH d" }, + { "#:", "EA", " ", "IY AX" }, + { "", "EA", "SU", "EH" }, + { "", "EA", "", "IY" }, + { "", "EIGH", "", "EY" }, + { "", "EI", "", "IY" }, + { " ", "EYE", "", "AY" }, + { "", "EY", "", "IY" }, + { "", "EU", "", "y UW" }, + { "", "E", "", "EH" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_f[] = { + { "", "FUL", "", "f UH l" }, + { "", "F", "", "f" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_g[] = { + { "", "GIV", "", "g IH v" }, + { " ", "G", "I^", "g" }, + { "", "GE", "T", "g EH" }, + { "SU", "GGES", "", "g J EH s" }, + { "", "GG", "", "g" }, + { " B#", "G", "", "g" }, + { "", "G", "+", "J" }, + { "", "GREAT", "", "g r EY t" }, + { "#", "GH", "", "" }, + { "", "G", "", "g" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_h[] = { + { " ", "HAV", "", "h AE v" }, + { " ", "HERE", "", "h IY r" }, + { " ", "HOUR", "", "AW ER" }, + { "", "HOW", "", "h AW" }, + { "", "H", "#", "h" }, + { "", "H", "", "" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_i[] = { + { " ", "IN", "", "IH n" }, + { " ", "I", " ", "AY" }, + { "", "IN", "D", "AY n" }, + { "", "IER", "", "IY ER" }, + { "#:R", "IED", "", "IY d" }, + { "", "IED", " ", "AY d" }, + { "", "IEN", "", "IY EH n" }, + { "", "IE", "T", "AY EH" }, + { " :", "I", "%", "AY" }, + { "", "I", "%", "IY" }, + { "", "IE", "", "IY" }, + { "", "I", "^+:#", "IH" }, + { "", "IR", "#", "AY r" }, + { "", "IZ", "%", "AY z" }, + { "", "IS", "%", "AY z" }, + { "", "I", "D%", "AY" }, + { "+^", "I", "^+", "IH" }, + { "", "I", "T%", "AY" }, + { "#:^", "I", "^+", "IH" }, + { "", "I", "^+", "AY" }, + { "", "IR", "", "ER" }, + { "", "IGH", "", "AY" }, + { "", "ILD", "", "AY l d" }, + { "", "IGN", " ", "AY n" }, + { "", "IGN", "^", "AY n" }, + { "", "IGN", "%", "AY n" }, + { "", "IQUE", "", "IY k" }, + { "", "I", "", "IH" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_j[] = { + { "", "J", "", "J" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_k[] = { + { " ", "K", "N", "" }, + { "", "K", "", "k" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_l[] = { + { "", "LO", "C#", "l OW" }, + { "L", "L", "", "" }, + { "#:^", "L", "%", "AX l" }, + { "", "LEAD", "", "l IY d" }, + { "", "L", "", "l" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_m[] = { + { "", "MOV", "", "m UW v" }, + { "", "M", "", "m" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_n[] = { + { "E", "NG", "+", "n J" }, + { "", "NG", "R", "N g" }, + { "", "NG", "#", "N g" }, + { "", "NGL", "%", "N g AX l" }, + { "", "NG", "", "N" }, + { "", "NK", "", "N k" }, + { " ", "NOW", " ", "n AW" }, + { "", "N", "", "n" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_o[] = { + { "", "OF", " ", "AX v" }, + { "", "OROUGH", "", "ER OW" }, + { "#:", "OR", " ", "ER" }, + { "#:", "ORS", " ", "ER z" }, + { "", "OR", "", "AO r" }, + { " ", "ONE", "", "w AH n" }, + { "", "OW", "", "OW" }, + { " ", "OVER", "", "OW v ER" }, + { "", "OV", "", "AH v" }, + { "", "O", "^%", "OW" }, + { "", "O", "^EN", "OW" }, + { "", "O", "^I#", "OW" }, + { "", "OL", "D", "OW l" }, + { "", "OUGHT", "", "AO t" }, + { "", "OUGH", "", "AH f" }, + { " ", "OU", "", "AW" }, + { "H", "OU", "S#", "AW" }, + { "", "OUS", "", "AX s" }, + { "", "OUR", "", "AO r" }, + { "", "OULD", "", "UH d" }, + { "^", "OU", "^L", "AH" }, + { "", "OUP", "", "UW p" }, + { "", "OU", "", "AW" }, + { "", "OY", "", "OY" }, + { "", "OING", "", "OW IH N" }, + { "", "OI", "", "OY" }, + { "", "OOR", "", "AO r" }, + { "", "OOK", "", "UH k" }, + { "", "OOD", "", "UH d" }, + { "", "OO", "", "UW" }, + { "", "O", "E", "OW" }, + { "", "O", " ", "OW" }, + { "", "OA", "", "OW" }, + { " ", "ONLY", "", "OW n l IY" }, + { " ", "ONCE", "", "w AH n s" }, + { "", "ON'T", "", "OW n t" }, + { "C", "O", "N", "AA" }, + { "", "O", "NG", "AO" }, + { " :^", "O", "N", "AH" }, + { "I", "ON", "", "AX n" }, + { "#:", "ON", " ", "AX n" }, + { "#^", "ON", "", "AX n" }, + { "", "O", "ST ", "OW" }, + { "", "OF", "^", "AO f" }, + { "", "OTHER", "", "AH D ER" }, + { "", "OSS", " ", "AO s" }, + { "#:^", "OM", "", "AH m" }, + { "", "O", "", "AA" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_p[] = { + { "", "PH", "", "f" }, + { "", "PEOP", "", "p IY p" }, + { "", "POW", "", "p AW" }, + { "", "PUT", " ", "p UH t" }, + { "", "P", "", "p" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_q[] = { + { "", "QUAR", "", "k w AO r" }, + { "", "QU", "", "k w" }, + { "", "Q", "", "k" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_r[] = { + { " ", "RE", "^#", "r IY" }, + { "", "R", "", "r" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_s[] = { + { "", "SH", "", "S" }, + { "#", "SION", "", "Z AX n" }, + { "", "SOME", "", "s AH m" }, + { "#", "SUR", "#", "Z ER" }, + { "", "SUR", "#", "S ER" }, + { "#", "SU", "#", "Z UW" }, + { "#", "SSU", "#", "S UW" }, + { "#", "SED", " ", "z d" }, + { "#", "S", "#", "z" }, + { "", "SAID", "", "s EH d" }, + { "^", "SION", "", "S AX n" }, + { "", "S", "S", "" }, + { ".", "S", " ", "z" }, + { "#:.E", "S", " ", "z" }, + { "#:^##", "S", " ", "z" }, + { "#:^#", "S", " ", "s" }, + { "U", "S", " ", "s" }, + { " :#", "S", " ", "z" }, + { " ", "SCH", "", "s k" }, + { "", "S", "C+", "" }, + { "#", "SM", "", "z m" }, + { "#", "SN", "'", "z AX n" }, + { "", "S", "", "s" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_t[] = { + { " ", "THE", " ", "D AX" }, + { "", "TO", " ", "t UW" }, + { "", "THAT", " ", "D AE t" }, + { " ", "THIS", " ", "D IH s" }, + { " ", "THEY", "", "D EY" }, + { " ", "THERE", "", "D EH r" }, + { "", "THER", "", "D ER" }, + { "", "THEIR", "", "D EH r" }, + { " ", "THAN", " ", "D AE n" }, + { " ", "THEM", " ", "D EH m" }, + { "", "THESE", " ", "D IY z" }, + { " ", "THEN", "", "D EH n" }, + { "", "THROUGH", "", "T r UW" }, + { "", "THOSE", "", "D OW z" }, + { "", "THOUGH", " ", "D OW" }, + { " ", "THUS", "", "D AH s" }, + { "", "TH", "", "T" }, + { "#:", "TED", " ", "t IH d" }, + { "S", "TI", "#N", "C" }, + { "", "TI", "O", "S" }, + { "", "TI", "A", "S" }, + { "", "TIEN", "", "S AX n" }, + { "", "TUR", "#", "C ER" }, + { "", "TU", "A", "C UW" }, + { " ", "TWO", "", "t UW" }, + { "", "T", "", "t" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_u[] = { + { " ", "UN", "I", "y UW n" }, + { " ", "UN", "", "AH n" }, + { " ", "UPON", "", "AX p AO n" }, + { "@", "UR", "#", "UH r" }, + { "", "UR", "#", "y UH r" }, + { "", "UR", "", "ER" }, + { "", "U", "^ ", "AH" }, + { "", "U", "^^", "AH" }, + { "", "UY", "", "AY" }, + { " G", "U", "#", "" }, + { "G", "U", "%", "" }, + { "G", "U", "#", "w" }, + { "#N", "U", "", "y UW" }, + { "@", "U", "", "UW" }, + { "", "U", "", "y UW" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_v[] = { + { "", "VIEW", "", "v y UW" }, + { "", "V", "", "v" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_w[] = { + { " ", "WERE", "", "w ER" }, + { "", "WA", "S", "w AA" }, + { "", "WA", "T", "w AA" }, + { "", "WHERE", "", "w EH r" }, + { "", "WHAT", "", "w AA t" }, + { "", "WHOL", "", "h OW l" }, + { "", "WHO", "", "h UW" }, + { "", "WH", "", "w" }, + { "", "WAR", "", "w AO r" }, + { "", "WOR", "^", "w ER" }, + { "", "WR", "", "r" }, + { "", "W", "", "w" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_x[] = { + { "", "X", "", "k s" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_y[] = { + { "", "YOUNG", "", "y AH N" }, + { " ", "YOU", "", "y UW" }, + { " ", "YES", "", "y EH s" }, + { " ", "Y", "", "y" }, + { "#:^", "Y", " ", "IY" }, + { "#:^", "Y", "I", "IY" }, + { " :", "Y", " ", "AY" }, + { " :", "Y", "#", "AY" }, + { " :", "Y", "^+:#", "IH" }, + { " :", "Y", "^#", "AY" }, + { "", "Y", "", "IH" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule rules_z[] = { + { "", "Z", "", "z" }, + { NULL, NULL, NULL, NULL }, +}; + +static const struct rule *const rules[26] = { + rules_a, rules_b, rules_c, rules_d, rules_e, rules_f, rules_g, + rules_h, rules_i, rules_j, rules_k, rules_l, rules_m, rules_n, + rules_o, rules_p, rules_q, rules_r, rules_s, rules_t, rules_u, + rules_v, rules_w, rules_x, rules_y, rules_z, +}; + +/* Words the rules get wrong, and the words a clock says, with their + * stress: a 1 before a vowel is the main stress. Function words have + * none. */ +static const struct { const char *word, *ph; } lexicon[] = { + { "a", "AX" }, { "an", "AX n" }, { "and", "AE n d" }, { "at", "AE t" }, + { "the", "D AX" }, { "of", "AX v" }, { "to", "t UW" }, { "it", "IH t" }, + { "is", "IH z" }, { "be", "b IY" }, { "will", "w IH l" }, { "in", "IH n" }, + { "i", "1AY" }, { "you", "y UW" }, { "are", "AA r" }, { "was", "w AH z" }, + { "it's", "IH t s" }, { "its", "IH t s" }, { "from", "f r AH m" }, + { "for", "f AO r" }, { "this", "D IH s" }, { "with", "w IH T" }, + { "have", "h AE v" }, { "has", "h AE z" }, { "do", "d UW" }, + { "hello", "h EH l 1OW" }, { "computer", "k AX m p y 1UW t ER" }, + { "zero", "z 1IY r OW" }, { "oh", "1OW" }, { "one", "w 1AH n" }, + { "two", "t 1UW" }, { "three", "T r 1IY" }, { "four", "f 1AO r" }, + { "five", "f 1AY v" }, { "six", "s 1IH k s" }, { "seven", "s 1EH v AX n" }, + { "eight", "1EY t" }, { "nine", "n 1AY n" }, { "ten", "t 1EH n" }, + { "eleven", "IH l 1EH v AX n" }, { "twelve", "t w 1EH l v" }, + { "thirteen", "T ER t 1IY n" }, { "fourteen", "f AO r t 1IY n" }, + { "fifteen", "f IH f t 1IY n" }, { "sixteen", "s IH k s t 1IY n" }, + { "seventeen", "s EH v AX n t 1IY n" }, { "eighteen", "EY t 1IY n" }, + { "nineteen", "n AY n t 1IY n" }, { "twenty", "t w 1EH n t IY" }, + { "thirty", "T 1ER t IY" }, { "forty", "f 1AO r t IY" }, + { "fifty", "f 1IH f t IY" }, { "sixty", "s 1IH k s t IY" }, + { "seventy", "s 1EH v AX n t IY" }, { "eighty", "1EY t IY" }, + { "ninety", "n 1AY n t IY" }, { "hundred", "h 1AH n d r IX d" }, + { "thousand", "T 1AW z AX n d" }, + { "third", "T 1ER d" }, { "stroke", "s t r 1OW k" }, + { "second", "s 1EH k AX n d" }, { "seconds", "s 1EH k AX n d z" }, + { "precisely", "p r IY s 1AY s l IY" }, { "exactly", "IH g z 1AE k t l IY" }, + { "o'clock", "AX k l 1AA k" }, { "oclock", "AX k l 1AA k" }, + { "noon", "n 1UW n" }, { "midnight", "m 1IH d n AY t" }, + { "good", "g 1UH d" }, { "morning", "m 1AO r n IH N" }, + { "afternoon", "AE f t ER n 1UW n" }, { "evening", "1IY v n IH N" }, + { "time", "t 1AY m" }, { "minute", "m 1IH n IX t" }, + { "minutes", "m 1IH n IX t s" }, { "hour", "1AW ER" }, { "hours", "1AW ER z" }, + { "a.m.", "1EY EH m" }, { "p.m.", "p 1IY EH m" }, { "am", "1EY EH m" }, + { "pm", "p 1IY EH m" }, { "tone", "t 1OW n" }, { "beep", "b 1IY p" }, + { "clock", "k l 1AA k" }, { "talking", "t 1AO k IH N" }, + { "speaking", "s p 1IY k IH N" }, { "macintalk", "m 1AE k IH n t AO k" }, + { "macintosh", "m 1AE k IH n t AA S" }, { "mac", "m 1AE k" }, + { "apple", "1AE p AX l" }, { "pizza", "p 1IY t s AX" }, + { "favorite", "f 1EY v r IX t" }, { "food", "f 1UW d" }, + { "voice", "v 1OY s" }, { "phone", "f 1OW n" }, { "modem", "m 1OW d EH m" }, + { "said", "s 1EH d" }, { "says", "s 1EH z" }, { "people", "p 1IY p AX l" }, + { "there", "D EH r" }, { "their", "D EH r" }, { "what", "w 1AH t" }, + { "where", "w 1EH r" }, { "who", "h 1UW" }, { "why", "w 1AY" }, + { "they", "D EY" }, { "we", "w IY" }, { "me", "m IY" }, { "my", "m AY" }, + { "he", "h IY" }, { "she", "S IY" }, { "or", "AO r" }, { "but", "b AH t" }, + { "not", "n 1AA t" }, { "no", "n 1OW" }, { "yes", "y 1EH s" }, + { "welcome", "w 1EH l k AX m" }, { "please", "p l 1IY z" }, + { "thank", "T 1AE N k" }, { "thanks", "T 1AE N k s" }, + { "sure", "S 1UH r" }, { "like", "l 1AY k" }, { "being", "b 1IY IH N" }, + { "inside", "IH n s 1AY d" }, { "fancy", "f 1AE n s IY" }, + { NULL, NULL }, +}; diff --git a/tools/fetch-macintalk.py b/tools/fetch-macintalk.py new file mode 100644 index 0000000..9f60c38 --- /dev/null +++ b/tools/fetch-macintalk.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python3 +"""SPDX-License-Identifier: GPL-2.0-or-later + +Fetch the MacInTalk 3 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: + + OUT/.ttvd the voice description (parameters, see + docs/macintalk-format.md) + OUT/.ttvw the voice's sampled sound, for the voices that + have one (Bells, Boing, Cellos ...) + +Only data is read. Nothing from the disk is run, and the MacinTalk 3 +extension itself (Apple's code) is not extracted. + +Usage: tools/fetch-macintalk.py [OUT] (default: sources/macintalk) + tools/fetch-macintalk.py --image FILE.hda|FILE.zip [OUT] + +Needs only Python 3 (and about 1.1 GB of free disk while it runs). +""" +import hashlib +import os +import struct +import sys +import tempfile +import urllib.request +import zipfile + +URL = ("https://archive.org/download/macos-8.1-basilisk-ii/" + "macos-8.1-basilisk-ii-2026.10.1.zip") +SHA256 = "ce6ee4ba5294182535d20bf6639f64415376e4420b3473167803315e615c97fa" +VOICE_DIR = ("System Folder", "Extensions", "Voices") + + +class HFS: + """Just enough of an HFS (Mac OS Standard) reader to get files out.""" + + def __init__(self, f, base=0): + self.f, self.base = f, base + mdb = self.read(base + 1024, 162) + if mdb[:2] != b"BD": + raise ValueError("not an HFS volume") + self.blk = struct.unpack(">I", mdb[20:24])[0] + self.start = struct.unpack(">H", mdb[28:30])[0] * 512 + size = struct.unpack(">I", mdb[146:150])[0] + self.catalog = self.fork(struct.unpack(">6H", mdb[150:162]), size) + + def read(self, off, n): + self.f.seek(off) + return self.f.read(n) + + def fork(self, ext, size): + out = b"" + for i in range(0, 6, 2): + first, count = ext[i], ext[i + 1] + if count: + out += self.read(self.base + self.start + first * self.blk, count * self.blk) + if len(out) < size: + raise ValueError("fragmented fork (extents overflow) is not supported") + return out[:size] + + def records(self): + """Every leaf record of the catalog B-tree: (parent, name, data).""" + cat = self.catalog + node_size = struct.unpack(">H", cat[32:34])[0] + node = struct.unpack(">I", cat[24:28])[0] # first leaf + while node: + n = cat[node * node_size:(node + 1) * node_size] + flink = struct.unpack(">I", n[0:4])[0] + nrec = struct.unpack(">H", n[10:12])[0] + offs = [struct.unpack(">H", n[node_size - 2 * (i + 1):node_size - 2 * i])[0] + for i in range(nrec)] + for o in offs: + klen = n[o] + if klen == 0: + continue + parent = struct.unpack(">I", n[o + 2:o + 6])[0] + name = n[o + 7:o + 7 + n[o + 6]].decode("mac_roman") + d = o + 1 + klen + d += d & 1 + yield parent, name, n[d:] + node = flink + + def find(self, path): + """{name: (type, creator, data fork, resource fork)} of a folder.""" + dirs, files = {}, {} + for parent, name, d in self.records(): + if d[0] == 1: + dirs[(parent, name)] = struct.unpack(">I", d[6:10])[0] + elif d[0] == 2: + files.setdefault(parent, {})[name] = d + cur = 2 # the root folder + for comp in path: + match = [k for k in dirs if k[0] == cur and k[1] == comp] + if not match: + raise KeyError(":".join(path)) + cur = dirs[match[0]] + out = {} + for name, d in files.get(cur, {}).items(): + ftype, creator = d[4:8], d[8:12] + dsize = struct.unpack(">I", d[26:30])[0] + rsize = struct.unpack(">I", d[36:40])[0] + dext = struct.unpack(">6H", d[74:86]) + rext = struct.unpack(">6H", d[86:98]) + out[name] = (ftype, creator, self.fork(dext, dsize), self.fork(rext, rsize)) + return out + + +def resources(fork): + """{(type, id): (name, data)} from a resource fork.""" + if len(fork) < 16: + return {} + doff, moff = struct.unpack(">II", fork[:8]) + m = fork[moff:] + tlo, nlo = struct.unpack(">HH", m[24:28]) + tl = m[tlo:] + out = {} + for i in range(struct.unpack(">H", tl[:2])[0] + 1): + rtype, cnt, rlo = struct.unpack(">4sHH", tl[2 + 8 * i:10 + 8 * i]) + for j in range(cnt + 1): + r = tl[rlo + 12 * j:rlo + 12 * j + 12] + rid, noff = struct.unpack(">hH", r[:4]) + off = struct.unpack(">I", b"\0" + r[5:8])[0] + size = struct.unpack(">I", fork[doff + off:doff + off + 4])[0] + name = None + if noff != 0xFFFF: + p = m[nlo + noff:] + name = p[1:1 + p[0]].decode("mac_roman") + out[(rtype.decode("mac_roman"), rid)] = (name, fork[doff + off + 4:doff + off + 4 + size]) + return out + + +def voice_id(name): + return name.lower().replace(" ", "-") + + +def extract(hda, out): + 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 + res = resources(rsrc) + for (rtype, _), (_, data) in res.items(): + if rtype in ("ttvd", "ttvw"): + with open(os.path.join(out, voice_id(name) + "." + rtype), "wb") as o: + o.write(data) + n += 1 + print("voice", name) + return n + + +def main(argv): + image = None + if argv[:1] == ["--image"]: + image, argv = argv[1], argv[2:] + 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") + print("voices in", out) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/tools/synth_voices.py b/tools/synth_voices.py index 7a2e027..16daebe 100755 --- a/tools/synth_voices.py +++ b/tools/synth_voices.py @@ -12,8 +12,9 @@ Usage: tools/synth_voices.py OUT VOICE... (OUT is normally ./voices) --live writes a live voice instead (mode=tts, live--): no clips, the module runs the synthesiser on the Asterisk machine for each -sentence as it is needed (dectalk and sam only; tts_program_dectalk and -tts_program_sam in speakingclock.conf say where they are). +sentence as it is needed (dectalk, sam and macintalk only; +tts_program_dectalk, tts_program_sam and tts_program_macintalk in +speakingclock.conf say where they are). Engines (a VOICE is engine:name, see --list): sapi4 Microsoft Speech API 4 voices (Microsoft Sam, Mike, Mary, @@ -26,6 +27,10 @@ Engines (a VOICE is engine:name, see --list): https://github.com/s-macke/SAM. $SAM is its `sam` program. mac MacInTalk / PlainTalk voices, with macOS's own `say` (run this on a Mac). + macintalk The MacInTalk 3 voices (Fred, Ralph, Kathy, Zarvox ...) spoken + 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. Needs ffmpeg and sox. """ @@ -133,6 +138,30 @@ MAC_FAMILY = { } MAC = {v: f for f, vs in MAC_FAMILY.items() for v in vs} +# The MacInTalk 3 voices of Mac OS 8.1, spoken by synth/macintalk. +# id: (name, what the voice is like) +MACINTALK = { + "fred": ("Fred", "the standard male voice"), + "ralph": ("Ralph", "a deep male voice"), + "kathy": ("Kathy", "the standard female voice"), + "junior": ("Junior", "a boy's voice"), + "princess": ("Princess", "a girl's voice"), + "zarvox": ("Zarvox", "a robot"), + "trinoids": ("Trinoids", "aliens speaking together"), + "whisper": ("Whisper", "a whisper"), + "albert": ("Albert", "a frog in the throat"), + "bahh": ("Bahh", "a bleating lamb"), + "bells": ("Bells", "spoken by bells"), + "boing": ("Boing", "spoken by a spring"), + "bubbles": ("Bubbles", "speaking under water"), + "cellos": ("Cellos", "sung by cellos, to In the Hall of the Mountain King"), + "pipe-organ": ("Pipe Organ", "sung by a pipe organ"), + "good-news": ("Good News", "sung to Pomp and Circumstance"), + "bad-news": ("Bad News", "sung to Chopin's funeral march"), + "deranged": ("Deranged", "an unhinged voice"), + "hysterical": ("Hysterical", "speaking through laughter"), +} + last_request = [0.0] @@ -194,6 +223,15 @@ def mac(vid, text, out): os.unlink(aiff) +def macintalk(vid, text, out): + prog = os.environ.get("MACINTALK", os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "synth", "macintalk", "macintalk")) + cmd = [prog, "-v", vid, "-o", out, text] + if os.environ.get("MACINTALK_VOICES"): + cmd[1:1] = ["-d", os.environ["MACINTALK_VOICES"]] + subprocess.run(cmd, check=True) + + ENGINES = { "sapi4": (sapi4, SAPI4, lambda v: (SAPI4[v][3], SAPI4[v][4]), "Microsoft Speech API 4 runtime and voices, spoken by https://www.tetyys.com/SAPI4/"), @@ -205,6 +243,11 @@ ENGINES = { "Apple PlainTalk (MacinTalk Pro) voice" if MAC[v] == "PlainTalk" else "Apple MacInTalk 3 voice"), "Apple MacInTalk / PlainTalk, spoken by macOS's say"), + "macintalk": (macintalk, MACINTALK, + lambda v: ("MacInTalk %s" % MACINTALK[v][0], + "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"), } @@ -245,11 +288,18 @@ def build_live(out_dir, engine, vid): if engine == "dectalk": how = 'command={program:dectalk} -fo {out} -a "[:%s] {text}"' % DECTALK[vid][0] by = "DECtalk's say, run here (tts_program_dectalk)" + elif engine == "macintalk": + how = 'command={program:macintalk} -v %s -o {out} "{text}"' % vid + by = "synth/macintalk, run here (tts_program_macintalk)" else: speed, pitch, mouth, throat = SAM[vid][:4] how = ("command={program:sam} -wav {out} -speed %d -pitch %d -mouth %d -throat %d \"{text}\"" % (speed, pitch, mouth, throat)) by = "SAM, run here (tts_program_sam)" + owners = "The synthesiser belongs to its owners" + if engine == "macintalk": + 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)") text = "At the third stroke, it will be {hour} {minute} {seconds}." d = os.path.join(out_dir, "live-%s-%s" % (engine, vid.lower().replace(" ", "-"))) os.makedirs(d, exist_ok=True) @@ -257,11 +307,11 @@ def build_live(out_dir, engine, vid): f.write("; Live voice for app_speakingclock (docs/voice-format.md), made by\n" "; tools/synth_voices.py --live %s:%s. Each sentence is spoken when\n" "; it is needed, by %s.\n" - "; The synthesiser belongs to its owners; see NOTICE.md.\n\n" + "; %s; see NOTICE.md.\n\n" "[voice]\nname=%s, live\ndescription=%s, spoken live\n" "mode=tts\nsequence=speech+pips\nperiod=10\n\n[tts]\n%s\ntext=%s\n" "\n[source]\nengine=%s\nvoice=%s\nsynthesiser=%s\n" - % (engine, vid, by, name, desc, how, text, engine, vid, ENGINES[engine][3])) + % (engine, vid, by, owners, name, desc, how, text, engine, vid, ENGINES[engine][3])) assert vid in table print(d) @@ -270,8 +320,8 @@ 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") or vid not in ENGINES[engine][1]: - sys.exit("--live takes dectalk and sam voices (see --list)") + if engine not in ("dectalk", "sam", "macintalk") or vid not in ENGINES[engine][1]: + sys.exit("--live takes dectalk, sam and macintalk 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 diff --git a/voices/INDEX.md b/voices/INDEX.md index 3d950ad..d2b6aac 100644 --- a/voices/INDEX.md +++ b/voices/INDEX.md @@ -50,6 +50,25 @@ Written by tools/voice_index.py. Every recording belongs to its original owner ( | `live-dectalk-rita` | DECtalk Rough Rita, live | tts | dectalk synthesiser | | `live-dectalk-ursula` | DECtalk Uppity Ursula, live | tts | dectalk synthesiser | | `live-dectalk-wendy` | DECtalk Whispering Wendy, live | tts | dectalk synthesiser | +| `live-macintalk-albert` | MacInTalk Albert, live | tts | macintalk synthesiser | +| `live-macintalk-bad-news` | MacInTalk Bad News, live | tts | macintalk synthesiser | +| `live-macintalk-bahh` | MacInTalk Bahh, live | tts | macintalk synthesiser | +| `live-macintalk-bells` | MacInTalk Bells, live | tts | macintalk synthesiser | +| `live-macintalk-boing` | MacInTalk Boing, live | tts | macintalk synthesiser | +| `live-macintalk-bubbles` | MacInTalk Bubbles, live | tts | macintalk synthesiser | +| `live-macintalk-cellos` | MacInTalk Cellos, live | tts | macintalk synthesiser | +| `live-macintalk-deranged` | MacInTalk Deranged, live | tts | macintalk synthesiser | +| `live-macintalk-fred` | MacInTalk Fred, live | tts | macintalk synthesiser | +| `live-macintalk-good-news` | MacInTalk Good News, live | tts | macintalk synthesiser | +| `live-macintalk-hysterical` | MacInTalk Hysterical, live | tts | macintalk synthesiser | +| `live-macintalk-junior` | MacInTalk Junior, live | tts | macintalk synthesiser | +| `live-macintalk-kathy` | MacInTalk Kathy, live | tts | macintalk synthesiser | +| `live-macintalk-pipe-organ` | MacInTalk Pipe Organ, live | tts | macintalk synthesiser | +| `live-macintalk-princess` | MacInTalk Princess, live | tts | macintalk synthesiser | +| `live-macintalk-ralph` | MacInTalk Ralph, live | tts | macintalk synthesiser | +| `live-macintalk-trinoids` | MacInTalk Trinoids, live | tts | macintalk synthesiser | +| `live-macintalk-whisper` | MacInTalk Whisper, live | tts | macintalk synthesiser | +| `live-macintalk-zarvox` | MacInTalk Zarvox, live | tts | macintalk 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 | diff --git a/voices/live-macintalk-albert/voice.conf b/voices/live-macintalk-albert/voice.conf new file mode 100644 index 0000000..de46d3f --- /dev/null +++ b/voices/live-macintalk-albert/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:albert. 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=MacInTalk Albert, live +description=MacInTalk 3 voice (a frog in the throat), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v albert -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=albert +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-bad-news/voice.conf b/voices/live-macintalk-bad-news/voice.conf new file mode 100644 index 0000000..03090a0 --- /dev/null +++ b/voices/live-macintalk-bad-news/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:bad-news. 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=MacInTalk Bad News, live +description=MacInTalk 3 voice (sung to Chopin's funeral march), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v bad-news -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=bad-news +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-bahh/voice.conf b/voices/live-macintalk-bahh/voice.conf new file mode 100644 index 0000000..fb1d7ab --- /dev/null +++ b/voices/live-macintalk-bahh/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:bahh. 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=MacInTalk Bahh, live +description=MacInTalk 3 voice (a bleating lamb), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v bahh -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=bahh +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-bells/voice.conf b/voices/live-macintalk-bells/voice.conf new file mode 100644 index 0000000..0fd4589 --- /dev/null +++ b/voices/live-macintalk-bells/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:bells. 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=MacInTalk Bells, live +description=MacInTalk 3 voice (spoken by bells), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v bells -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=bells +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-boing/voice.conf b/voices/live-macintalk-boing/voice.conf new file mode 100644 index 0000000..8d71c62 --- /dev/null +++ b/voices/live-macintalk-boing/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:boing. 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=MacInTalk Boing, live +description=MacInTalk 3 voice (spoken by a spring), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v boing -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=boing +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-bubbles/voice.conf b/voices/live-macintalk-bubbles/voice.conf new file mode 100644 index 0000000..a823928 --- /dev/null +++ b/voices/live-macintalk-bubbles/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:bubbles. 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=MacInTalk Bubbles, live +description=MacInTalk 3 voice (speaking under water), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v bubbles -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=bubbles +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-cellos/voice.conf b/voices/live-macintalk-cellos/voice.conf new file mode 100644 index 0000000..1ca6b83 --- /dev/null +++ b/voices/live-macintalk-cellos/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:cellos. 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=MacInTalk Cellos, live +description=MacInTalk 3 voice (sung by cellos, to In the Hall of the Mountain King), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v cellos -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=cellos +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-deranged/voice.conf b/voices/live-macintalk-deranged/voice.conf new file mode 100644 index 0000000..904d447 --- /dev/null +++ b/voices/live-macintalk-deranged/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:deranged. 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=MacInTalk Deranged, live +description=MacInTalk 3 voice (an unhinged voice), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v deranged -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=deranged +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-fred/voice.conf b/voices/live-macintalk-fred/voice.conf new file mode 100644 index 0000000..8ee5b6f --- /dev/null +++ b/voices/live-macintalk-fred/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:fred. 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=MacInTalk Fred, live +description=MacInTalk 3 voice (the standard male voice), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v fred -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=fred +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-good-news/voice.conf b/voices/live-macintalk-good-news/voice.conf new file mode 100644 index 0000000..b3f85c8 --- /dev/null +++ b/voices/live-macintalk-good-news/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:good-news. 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=MacInTalk Good News, live +description=MacInTalk 3 voice (sung to Pomp and Circumstance), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v good-news -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=good-news +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-hysterical/voice.conf b/voices/live-macintalk-hysterical/voice.conf new file mode 100644 index 0000000..4a83915 --- /dev/null +++ b/voices/live-macintalk-hysterical/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:hysterical. 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=MacInTalk Hysterical, live +description=MacInTalk 3 voice (speaking through laughter), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v hysterical -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=hysterical +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-junior/voice.conf b/voices/live-macintalk-junior/voice.conf new file mode 100644 index 0000000..5bb0ceb --- /dev/null +++ b/voices/live-macintalk-junior/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:junior. 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=MacInTalk Junior, live +description=MacInTalk 3 voice (a boy's voice), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v junior -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=junior +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-kathy/voice.conf b/voices/live-macintalk-kathy/voice.conf new file mode 100644 index 0000000..07b3a5f --- /dev/null +++ b/voices/live-macintalk-kathy/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:kathy. 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=MacInTalk Kathy, live +description=MacInTalk 3 voice (the standard female voice), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v kathy -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=kathy +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-pipe-organ/voice.conf b/voices/live-macintalk-pipe-organ/voice.conf new file mode 100644 index 0000000..793eff5 --- /dev/null +++ b/voices/live-macintalk-pipe-organ/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:pipe-organ. 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=MacInTalk Pipe Organ, live +description=MacInTalk 3 voice (sung by a pipe organ), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v pipe-organ -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=pipe-organ +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-princess/voice.conf b/voices/live-macintalk-princess/voice.conf new file mode 100644 index 0000000..06c81d9 --- /dev/null +++ b/voices/live-macintalk-princess/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:princess. 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=MacInTalk Princess, live +description=MacInTalk 3 voice (a girl's voice), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v princess -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=princess +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-ralph/voice.conf b/voices/live-macintalk-ralph/voice.conf new file mode 100644 index 0000000..63571cc --- /dev/null +++ b/voices/live-macintalk-ralph/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:ralph. 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=MacInTalk Ralph, live +description=MacInTalk 3 voice (a deep male voice), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v ralph -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=ralph +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-trinoids/voice.conf b/voices/live-macintalk-trinoids/voice.conf new file mode 100644 index 0000000..1ddef5d --- /dev/null +++ b/voices/live-macintalk-trinoids/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:trinoids. 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=MacInTalk Trinoids, live +description=MacInTalk 3 voice (aliens speaking together), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v trinoids -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=trinoids +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-whisper/voice.conf b/voices/live-macintalk-whisper/voice.conf new file mode 100644 index 0000000..55fafec --- /dev/null +++ b/voices/live-macintalk-whisper/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:whisper. 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=MacInTalk Whisper, live +description=MacInTalk 3 voice (a whisper), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v whisper -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=whisper +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py diff --git a/voices/live-macintalk-zarvox/voice.conf b/voices/live-macintalk-zarvox/voice.conf new file mode 100644 index 0000000..ac4573a --- /dev/null +++ b/voices/live-macintalk-zarvox/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live macintalk:zarvox. 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=MacInTalk Zarvox, live +description=MacInTalk 3 voice (a robot), spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:macintalk} -v zarvox -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=macintalk +voice=zarvox +synthesiser=synth/macintalk (this repository, clean-room) reading Apple's MacInTalk 3 voice data (Mac OS 8.1), fetched by tools/fetch-macintalk.py