diff --git a/NOTICE.md b/NOTICE.md index 996daa2..07a003c 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -77,7 +77,7 @@ voices, belong to their owners: voice is TruVoice Adult Male #2 at the pitch and speed BonziBUDDY used. The live voices (`live-*`) hold no recordings: each sentence is spoken when it is needed, by DECtalk or SAM on the Asterisk machine. -- **Microsoft Sam, Mike and Mary, live** (`live-mssam-*`): no recordings. +- **Microsoft Sam, Mike and Mary (and for telephone), live** (`live-mssam-*`): no recordings. Each sentence is spoken on the Asterisk machine by `synth/mssam`, our own synthesiser (GPL-2.0-or-later, like the rest of this repository), which reads the voice data of Microsoft's Speech API 4 voices. That data is diff --git a/README.md b/README.md index 188cfb7..4d7ab27 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ tts_program_sam=/usr/local/bin/sam tts_program_macintalk=/usr/local/bin/macintalk ``` -The `live-mssam-*` voices (Microsoft Sam, Mike and Mary) run +The `live-mssam-*` voices (Microsoft Sam, Mike and Mary, and Mike and Mary +for telephone) run [synth/mssam](synth/mssam), our own synthesiser, which reads Microsoft's voice data (`cd synth/mssam && make && make voices && sudo make install` builds it and fetches the data). Its setting is `tts_program_mssam`. diff --git a/docs/mssam-format.md b/docs/mssam-format.md index aa145aa..03281ce 100644 --- a/docs/mssam-format.md +++ b/docs/mssam-format.md @@ -3,7 +3,8 @@ What synth/mssam reads, as we decoded it from the data alone. The voices come in Microsoft's Speech API 4 TTS package `msttsl.exe` (SHA-1 d988cbb3e99bc9dd850defda939c06b81d9d4544), a cabinet holding `sam.vce`, -`male.vce` (Mike) and `female.vce` (Mary). Each `.vce` is an OLE compound +`male.vce` (Mike) and `female.vce` (Mary), and `male8.vce` and `female8.vce`, Mike and Mary for +telephone (`mike-tel`, `mary-tel`). Each `.vce` is an OLE compound file with these streams: `Inventory`, `TreeImage`, `PhoneFile`, `Senone`, `Cdb`, `VcHeader` (and `AltUnits` in Sam's). `tools/fetch-mssam.py` writes `Inventory` as `.inv`, `Cdb` as `.tones`, and @@ -22,6 +23,12 @@ frame (in cycles per sample). The excitation codebooks have 128 entries; family A's 11 dims and family B's 13 dims each add up to 510, the points of one pitch period scaled to a fixed length. +The telephone voices are the same at 8000 Hz with order 12: 4 line-spectrum +codebooks of 3 values, and 10 excitation codebooks in each family (dims 12, +12, 16, 16, 16, 18, 24, 38, 46, 56, adding up to 254). Their unvoiced frame bytes +(147-238) do not fit as lengths at 8 kHz; mssam plays those frames as 5 ms, +which matches the units' recorded lengths (Senone) best. + A unit: u32 n frames @@ -30,7 +37,7 @@ A unit: period in samples; unvoiced: 0x80 bytes then a byte > 0x80, the length is 128*(number of 0x80 - 1) + that byte - n x 6 bytes line-spectrum codebook indices + n x 6 bytes (4 for telephone) line-spectrum codebook indices n float32 gains (the RMS of the frame's excitation) for each voiced frame the first frame of a voiced run: 11 family A indices, the whole period; diff --git a/synth/mssam/Makefile b/synth/mssam/Makefile index d7cbb50..8cb8521 100644 --- a/synth/mssam/Makefile +++ b/synth/mssam/Makefile @@ -24,7 +24,7 @@ install: mssam voices if [ -f $(SOURCES)/cmudict.dict ]; then install -m 644 $(SOURCES)/cmudict.dict $(DESTDIR)$(VOICEDIR)/; fi test: mssam voices - @for v in sam mike mary; do \ + @for v in sam mike mary mike-tel mary-tel; do \ ./mssam -d $(SOURCES) -v $$v -o /tmp/mssam-$$v.wav \ "At the third stroke, it will be ten oh five and twenty seconds." && \ echo "/tmp/mssam-$$v.wav"; \ diff --git a/synth/mssam/README.md b/synth/mssam/README.md index 103061c..b2be8c6 100644 --- a/synth/mssam/README.md +++ b/synth/mssam/README.md @@ -14,12 +14,13 @@ sudo make install # /usr/local/bin/mssam and /usr/local/share/mssam ``` ``` -mssam [-d DIR] [-v sam|mike|mary] [-r RATE] [-p PITCH] [-o OUT.wav] TEXT... +mssam [-d DIR] [-v sam|mike|mary|mike-tel|mary-tel] [-r RATE] [-p PITCH] [-o OUT.wav] TEXT... ``` -`-d` is the folder with the voice data (default `/usr/local/share/mssam`, +`mike-tel` and `mary-tel` are Microsoft's 8 kHz voices made for phone +lines. `-d` is the folder with the voice data (default `/usr/local/share/mssam`, or `$MSSAM_DIR`). `-r` and `-p` multiply the speed and pitch. Without `-o` -the WAV (22050 Hz, 16-bit mono) goes to standard output. +the WAV (22050 Hz, or 8000 Hz for the telephone voices, 16-bit mono) goes to standard output. ## How it speaks diff --git a/synth/mssam/mssam.c b/synth/mssam/mssam.c index 8c5cc79..69e6628 100644 --- a/synth/mssam/mssam.c +++ b/synth/mssam/mssam.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later * - * mssam: our own synthesiser for the Microsoft Sam, Mike and Mary voices. + * mssam: our own synthesiser for the Microsoft Sam, Mike and Mary voices + * (and Mike and Mary for telephone). * * It reads the voice data (fetched by tools/fetch-mssam.py) and speaks with * it: each sound of the text is given a recorded unit of the voice, picked @@ -8,7 +9,7 @@ * and timing. No Microsoft code is used or run. docs/mssam-format.md * describes the data. * - * mssam [-d DIR] [-v sam|mike|mary] [-r RATE] [-p PITCH] [-o OUT.wav] TEXT... + * mssam [-d DIR] [-v sam|mike|mary|mike-tel|mary-tel] [-r RATE] [-p PITCH] [-o OUT.wav] TEXT... * * RATE and PITCH are multipliers (1 is the voice's own). Without -o the * WAV goes to standard output. @@ -27,7 +28,8 @@ #define VOICEDIR "/usr/local/share/mssam" #endif -#define ORDER 20 /* LPC order of all three voices */ +#define MAXORDER 24 /* LPC order: 20, or 12 for the telephone voices */ +#define ORDER V.order #define MAXCB 16 #define MAXPH 64 @@ -93,7 +95,7 @@ struct node { int32_t yes, no; uint32_t q0, nq; }; struct phone { char name[9]; uint32_t first, nnodes, node0; }; static struct { - int rate, period; /* sample rate, points in a stored pitch period */ + int rate, order, period; /* sample rate, LPC order, points in a stored pitch period */ int nlsf, na, nb; struct table lsf[MAXCB], cba[MAXCB], cbb[MAXCB]; uint32_t nunits; @@ -126,8 +128,9 @@ static void load_inventory(const char *path) int i, s; V.rate = le32(d); - if (le32(d + 4) != ORDER) - die("%s: not a voice with 20 LPC coefficients", path); + V.order = le32(d + 4); + if (V.order < 2 || V.order > MAXORDER || V.order % 2) + die("%s: not a voice this program knows", path); V.nlsf = le32(d + 8); V.na = le32(d + 12); V.nb = le32(d + 16); @@ -247,7 +250,7 @@ static int pick_unit(int p, int pos, int l, int r) struct frame { int voiced, len, orig; - float gain, lsf[ORDER]; + float gain, lsf[MAXORDER]; float *period; /* V.period points, for voiced frames */ }; @@ -286,21 +289,25 @@ static int decode_unit(uint32_t k, struct frame **out) for (c = 0; *u == 0x80; u++) c++; f[i].len = 128 * (c ? c - 1 : 0) + *u++; + /* in the 8 kHz voices this byte does not fit as a length; + * 5 ms frames match the units' recorded lengths best */ + if (V.rate < 16000) + f[i].len = V.rate / 200; } } - /* then six line spectrum codebook indices per frame */ - if (u + 10 * n > end) + /* then a line spectrum codebook index per codebook per frame */ + if (u + (V.nlsf + 4) * n > end) goto bad; for (i = 0; i < n; i++) { int o = 0; for (j = 0; j < (uint32_t)V.nlsf; j++) { const struct table *t = &V.lsf[j]; - int idx = u[6 * i + j] % t->cnt, d; + int idx = u[V.nlsf * i + j] % t->cnt, d; for (d = 0; d < t->dim; d++) f[i].lsf[o++] = lef(t->v + 4 * (idx * t->dim + d)); } } - u += 6 * n; + u += V.nlsf * n; for (i = 0; i < n; i++) f[i].gain = lef(u + 4 * i); u += 4 * n; @@ -609,7 +616,7 @@ static void parse_text(const char *text) static void lsf_to_lpc(const float *lsf, double *a) { - double p[ORDER + 2] = { 1 }, q[ORDER + 2] = { 1 }; + double p[MAXORDER + 2] = { 1 }, q[MAXORDER + 2] = { 1 }; int np = 1, nq = 1, i, j; for (i = 0; i < ORDER; i++) { @@ -657,8 +664,10 @@ static void emit(double v) static void render(double rate, double pitch) { - static double mem[ORDER]; - double a[ORDER + 1], *e = NULL; + static double mem[MAXORDER], prev_y; + static float last[MAXORDER]; + static int have_last; + double a[MAXORDER + 1], *e = NULL; int i, j, k, ne = 0; for (i = 0; i < nsnd; i++) { @@ -670,6 +679,8 @@ static void render(double rate, double pitch) for (k = 0; k < snd[i].pause * V.rate / 1000; k++) emit(0); memset(mem, 0, sizeof(mem)); + prev_y = 0; + have_last = 0; continue; } /* the sounds either side; a pause counts as silence */ @@ -739,15 +750,32 @@ static void render(double rate, double pitch) } g = s->gain / (sqrt(sum / len) + 1e-9); } - lsf_to_lpc(s->lsf, a); + /* the spectrum glides from the last frame's to this one's, + * in steps of 32 samples, so frames do not click */ + if (!have_last) + memcpy(last, s->lsf, sizeof(last)); for (k = 0; k < len; k++) { double y = e[k] * g; + if (k % 32 == 0) { + float l[MAXORDER]; + double w = (k + 16.0) / len; + if (w > 1) + w = 1; + for (j = 0; j < ORDER; j++) + l[j] = (1 - w) * last[j] + w * s->lsf[j]; + lsf_to_lpc(l, a); + } for (j = 0; j < ORDER; j++) y -= a[j + 1] * mem[j]; memmove(mem + 1, mem, (ORDER - 1) * sizeof(double)); mem[0] = y; - emit(y); + /* the voices' spectra lack the treble of the recordings + * (about 10 dB above 3 kHz); this lift matches it */ + emit(y - 0.65 * prev_y); + prev_y = y; } + memcpy(last, s->lsf, sizeof(last)); + have_last = 1; t += len; } free(src); @@ -796,7 +824,7 @@ static void write_wav(FILE *f) static void usage(void) { - fprintf(stderr, "usage: mssam [-d DIR] [-v sam|mike|mary] [-r RATE] [-p PITCH] [-o OUT.wav] TEXT...\n" + fprintf(stderr, "usage: mssam [-d DIR] [-v VOICE] [-r RATE] [-p PITCH] [-o OUT.wav] TEXT...\n" " DIR holds the voice data from tools/fetch-mssam.py (default %s)\n", VOICEDIR); exit(2); } @@ -833,8 +861,9 @@ int main(int argc, char **argv) strncat(text, argv[i], sizeof(text) - strlen(text) - 2); strcat(text, " "); } - if (strcmp(voice, "sam") && strcmp(voice, "mike") && strcmp(voice, "mary")) - die("unknown voice %s (sam, mike or mary)", voice); + if (strcmp(voice, "sam") && strcmp(voice, "mike") && strcmp(voice, "mary") && + strcmp(voice, "mike-tel") && strcmp(voice, "mary-tel")) + die("unknown voice %s (sam, mike, mary, mike-tel or mary-tel)", voice); if (strcmp(voice, "sam")) rate /= 0.82, pitch /= 0.93; diff --git a/tools/fetch-mssam.py b/tools/fetch-mssam.py index b4d49f8..3577e7f 100644 --- a/tools/fetch-mssam.py +++ b/tools/fetch-mssam.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """SPDX-License-Identifier: GPL-2.0-or-later -Fetch the Microsoft Sam, Mike and Mary voice data for synth/mssam at build -time. +Fetch the Microsoft Sam, Mike and Mary voice data (and Mike and Mary for +telephone) for synth/mssam at build time. Microsoft's files are not in this repository. This script downloads the Microsoft Speech API 4 text-to-speech package (msttsl.exe) from the @@ -18,8 +18,9 @@ synth/mssam uses as plain files: clock does not usually say can be spoken too (optional: synth/mssam knows the clock's words) -The voices are sam, mike and mary (the files sam.vce, male.vce and -female.vce). The layouts are described in docs/mssam-format.md. +The voices are sam, mike, mary, mike-tel and mary-tel (the files sam.vce, +male.vce, female.vce, and the 8 kHz telephone voices male8.vce and +female8.vce). The layouts are described in docs/mssam-format.md. Only data is read. Nothing from the package is run, and Microsoft's programs in it (msttssyn.dll and the rest) are not kept. @@ -41,7 +42,8 @@ import urllib.request URL = "https://archive.org/download/msttsl/msttsl.exe" SHA1 = "d988cbb3e99bc9dd850defda939c06b81d9d4544" CMUDICT = "https://raw.githubusercontent.com/cmusphinx/cmudict/master/cmudict.dict" -VOICES = {"sam": "sam.vce", "mike": "male.vce", "mary": "female.vce"} +VOICES = {"sam": "sam.vce", "mike": "male.vce", "mary": "female.vce", + "mike-tel": "male8.vce", "mary-tel": "female8.vce"} POSITIONS = 4 # word positions: begins, ends, single, inside diff --git a/tools/synth_voices.py b/tools/synth_voices.py index 05de579..9fa4af5 100755 --- a/tools/synth_voices.py +++ b/tools/synth_voices.py @@ -227,6 +227,8 @@ MSSAM = { "sam": ("Microsoft Sam", "Microsoft Speech API 4 voice Sam"), "mike": ("Microsoft Mike", "Microsoft Speech API 4 voice Mike"), "mary": ("Microsoft Mary", "Microsoft Speech API 4 voice Mary"), + "mike-tel": ("Microsoft Mike for Telephone", "Microsoft Speech API 4 voice Mike, made for phone lines"), + "mary-tel": ("Microsoft Mary for Telephone", "Microsoft Speech API 4 voice Mary, made for phone lines"), } diff --git a/voices/INDEX.md b/voices/INDEX.md index 9ae127b..7298dce 100644 --- a/voices/INDEX.md +++ b/voices/INDEX.md @@ -70,7 +70,9 @@ Written by tools/voice_index.py. Every recording belongs to its original owner ( | `live-macintalk-whisper` | MacInTalk Whisper, live | tts | macintalk synthesiser | | `live-macintalk-zarvox` | MacInTalk Zarvox, live | tts | macintalk synthesiser | | `live-mssam-mary` | Microsoft Mary, live | tts | mssam synthesiser | +| `live-mssam-mary-tel` | Microsoft Mary for Telephone, live | tts | mssam synthesiser | | `live-mssam-mike` | Microsoft Mike, live | tts | mssam synthesiser | +| `live-mssam-mike-tel` | Microsoft Mike for Telephone, live | tts | mssam synthesiser | | `live-mssam-sam` | Microsoft Sam, live | tts | mssam synthesiser | | `live-plaintalk-agnes` | PlainTalk Agnes, live | tts | plaintalk synthesiser | | `live-plaintalk-bruce` | PlainTalk Bruce, live | tts | plaintalk synthesiser | diff --git a/voices/live-mssam-mary-tel/voice.conf b/voices/live-mssam-mary-tel/voice.conf new file mode 100644 index 0000000..4dcf003 --- /dev/null +++ b/voices/live-mssam-mary-tel/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live mssam:mary-tel. Each sentence is spoken when +; it is needed, by synth/mssam, run here (tts_program_mssam). +; The synthesiser is ours; the voice data it reads is Microsoft's and is +; not in this repository (tools/fetch-mssam.py downloads it); see NOTICE.md. + +[voice] +name=Microsoft Mary for Telephone, live +description=Microsoft Speech API 4 voice Mary, made for phone lines, by our own synthesiser, spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:mssam} -v mary-tel -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=mssam +voice=mary-tel +synthesiser=synth/mssam (this repository, clean-room) reading Microsoft's Speech API 4 voice data (msttsl.exe), fetched by tools/fetch-mssam.py diff --git a/voices/live-mssam-mike-tel/voice.conf b/voices/live-mssam-mike-tel/voice.conf new file mode 100644 index 0000000..d9e2c5e --- /dev/null +++ b/voices/live-mssam-mike-tel/voice.conf @@ -0,0 +1,21 @@ +; Live voice for app_speakingclock (docs/voice-format.md), made by +; tools/synth_voices.py --live mssam:mike-tel. Each sentence is spoken when +; it is needed, by synth/mssam, run here (tts_program_mssam). +; The synthesiser is ours; the voice data it reads is Microsoft's and is +; not in this repository (tools/fetch-mssam.py downloads it); see NOTICE.md. + +[voice] +name=Microsoft Mike for Telephone, live +description=Microsoft Speech API 4 voice Mike, made for phone lines, by our own synthesiser, spoken live +mode=tts +sequence=speech+pips +period=10 + +[tts] +command={program:mssam} -v mike-tel -o {out} "{text}" +text=At the third stroke, it will be {hour} {minute} {seconds}. + +[source] +engine=mssam +voice=mike-tel +synthesiser=synth/mssam (this repository, clean-room) reading Microsoft's Speech API 4 voice data (msttsl.exe), fetched by tools/fetch-mssam.py