GitHub - SpeakJet C-Library and Go-Library releases

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

A C implementation of the SpeakJet emulation, along with various tools and examples, is now available on my GitHub acccount...

SpeakJet C-Library

Al_Nafuur

Honestly, the SpeakJet is a pretty lousy chip, especially considering its price. And its so-called "speech" output is (in my ears) unbearable.

It's time developers started looking at better alternatives. RetroVox is just one example, but unfortunately, alternatives like this never caught on because developers keep supporting only the AtariVox crap.

https://github.com/rossumur/retrovox
https://forums.atariage.com/topic/332849-retrovox-wip/

Andrew Davie


JetSetIlly

Quote from: Al_Nafuur on 21 Oct 2026, 08:14 PMIt's time developers started looking at better alternatives. RetroVox is just one example, but unfortunately, alternatives like this never caught on because developers keep supporting only the AtariVox crap.
That was my idea when I first implemented AtariVox for Gopher2600. We can think of "AtariVox" as a protocol for requesting speech. The original hardware with the SpeakJet chip is one implementation of the protocol but we could build other implementations that use a different synthesis method.

I tried to use Festival for Gopher2600 to prove the point. I did enough to demonstrate the idea but it doesn't currently support all the SpeakJet commands (a limitation in Festival).

I was going to remove the Festival code now that we have proper SpeakJet synthesis, but I think I'll keep it as an option.
https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

Andrew Davie

Quote from: JetSetIlly on 22 Oct 2026, 01:45 AMI tried to use Festival for Gopher2600 to prove the point. I did enough to demonstrate the idea but it doesn't currently support all the SpeakJet commands (a limitation in Festival).

I was going to remove the Festival code now that we have proper SpeakJet synthesis, but I think I'll keep it as an option.


I don't see the point of that. Festival is a now unsupported, and broken (on MacOS at least) partial implementation of SpeakJet. The product it emulates is now emulated at least as well by the native go emulation - as far as we are aware.  It's unlikely to be improved at any time in the near future and it adds complexity to gopher for practically nobody to use.

I'd deprecate it and remove it in short order, myself.

Al_Nafuur

I wonder if it would be possible to port Andrew's new SpeakJet C library to RetroVox?

This could make RetroVox a fully compatible AtariVox replacement for existing games, while retaining all its additional features like MIDI, MOD, MP3, OPL2/3, SAM, SP0256 and FM synthesis. It could be a very capable and potentially cheaper successor to the original AtariVox!

SaveKey compatibility would of course need to be handled separately.

What do you think?

Andrew Davie

Quote from: Al_Nafuur on 22 Oct 2026, 06:50 PMI wonder if it would be possible to port Andrew's new SpeakJet C library to RetroVox?
What do you think?


Well it's public domain, so why not?  I hope people use it.


Andrew Davie

#7
A brand new version (0.3.0) of the C-Library and the Go-Library is now available.
Released under MIT license.

It's a from-scratch re-implementation, approaching the generation of the speech in a different way. Now the waveforms are generated procedurally from very small tables (< 3K) which significantly reduces the code size, too.

C-Library
see https://github.com/andrew-davie/SpeakJet

Go-Library
see https://github.com/JetSetIlly/SpeakJet/


The C library and the Go package are line-for-line ports of each other and render the same samples. Here is what each costs in source, compiled size and memory. Measured on macOS arm64: C with cc -O2, Go 1.27.2.

                               C               Go
source: engine              1,120 lines     1,143 lines
source: tables                138 lines       143 lines
sound tables (data)         2,721 bytes     2,721 bytes
machine code               13,584 bytes    18,144 bytes
other read-only data        4,685 bytes     3,712 bytes
runtime metadata                -          12,391 bytes
total added to a program   ~18 KB          ~34 KB
memory per chip             3,832 bytes     4,280 bytes

Sound tables. All 72 allophones and 55 effects fit in 2,721 bytes: the allophones are 14-byte rows and the effects a byte stream that stores only the fields each part uses. Both libraries use exactly the same tables.

No dependencies. C needs only libm. Go needs only the standard library.
Memory. No global state, so each chip is one heap block of under 4.3 KB.


The attached graphs detail the accuracy of each sound/waveform.
Some work still remains to be done on delays, particularly inter-word delays.


JetSetIlly

Quote from: Andrew Davie on 02 Nov 2026, 07:24 AMA brand new version (0.3.0) of the C-Library and the Go-Library is now available.
Released under MIT license.

Nightly binary of Gopher2600 to hear it in action. https://github.com/JetSetIlly/Gopher2600/releases/tag/nightly
https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

Andrew Davie


**SpeakJet C library: update (drawn effects, cleaned-up measurement)**

The C library (github.com/andrew-davie/SpeakJet, branch `main`) has a new update. It's a from-scratch emulation of the SpeakJet speech chip in the AtariVox, rebuilt from recordings of two real AtariVoxes. The Go port (JetSetIlly/SpeakJet, used by Gopher2600 on update) gets the same changes and stays sample-identical.

**What changed**
- **Effects rebuilt from hand-drawn structures.** Several effects (215 A5, 216 A6, 218 A8, 222 B2, 230 C0, 233 C3, 236 C6) were redrawn by hand over the real chip's spectrograms, snapped to the chip's own lines, and tuned. Each was checked on every probe recording, at other Pitch, Bend and Speed settings, not just the take it was fitted to. Two others that looked better on that take but worse elsewhere were reverted.
- **Measurement cleaned up.** The recordings carried steady lines from the recording path (a 1 kHz comb, mains hum, the chip's clock leaking at 8 kHz). These are now subtracted, or left out of the comparisons, so scores reflect the chip and not the hardware around it.
- **Engine additions:**
  - smooth on/off ramps per effect;
  - "banded column" buzz sounds;
  - a small per-effect peaking-filter table (in place, not yet used).
- **Faithful to the hardware.** The output keeps the AtariVox's quirks, including the mirror images of every tone around the chip's ~8 kHz clock, which the AtariVox passes to the speaker unfiltered. It sounds like the box you own, not an idealised SpeakJet.
- **Tables:** 3826 bytes.

**For emulator authors**
The API is unchanged. Feed it the bytes your game sends to the AtariVox and pull samples at your output rate. Drop in the new `speakjet.c`, `speakjet.h` and `speakjet_tables.c`; no code changes are needed.

**Still open**
- 233 C3 and 236 C6 are a little off at very low Pitch.
- A handful of effects (237 C7, 227 B7, the robots) need mechanisms rather than drawings.
- The technical manual in the repo documents everything measured so far.

Feedback and recordings of anything that sounds wrong are very welcome.

Andrew Davie

**AtariVox / SpeakJet emulation: the serial control protocol now works**

The SpeakJet has two ways in. Most games send speech codes: allophones, effects, Pitch, Speed and so on, which go through the chip's 64-byte buffer and its speech engine. The other way is the serial control protocol (SCP): send "\0" and the chip stops treating bytes as speech and lets you write its synthesizer's registers directly. You get five oscillators, the envelope oscillator, noise on two of them, and the master volume. Until now the emulation ignored it, so anything written that way was silent.

It's now in both libraries (C and Go), so Gopher2600 plays it, and Stella will IF it's rebuilt with the new library. The VoxProbe ROMs from 7 onward use it for their reference tones and synthesizer tests, which is how I noticed: those sections were simply silent in the emulators.

**What's supported**

\0        enter control mode (node 0, the AtariVox's)
X         leave it (so does \ followed by any non-digit)
nJ        set the register address to n
nN        write n to that register
nH        memory type (0 = registers; 32 = EEPROM, ignored)
R         clear the buffers
S / T     hold / release the speech buffer
W         hard reset

register  what it is
0         envelope rate, Hz
1-5       oscillator frequencies, 0-3999 Hz
6         distortion (noise) on oscillators 4 and 5, 0-255
7         master volume, 0-127 (the same as the Volume command)
8         envelope control: bits 0-1 shape (saw, sine, triangle, square), bit 6 envelope oscillators 1-3,
          bit 7 half-envelope 4 and 5
11-15     oscillator volumes, 0-31

For example, `\0 8J0N 1J1000N 11J31N 7J96N` gives a steady 1 kHz tone, and `11J0N X` stops it and goes back to speech. As on the chip, any speech sound takes the synthesizer over and leaves the oscillator volumes at zero.

**Checked against the hardware.** The level of a register tone comes from VoxProbe 9's recordings on both units: the 1000 Hz tone at volume 31 sits 3.1-3.6 dB above the C5 and D1 effects. Two references give answers 2 dB apart, so I used the mean. A register tone also gets none of the faint noise "bed" the chip puts under its effect tones; VoxProbe 10 showed it's 57 dB down there. Ordinary speech is unchanged, bit for bit. A Pitch 92 command (92 is the "\" character) still works, because a data byte is never taken as an escape.

**Not there yet**, because nothing has measured them:

- "V", which makes the chip say "Ready"
- writing the EEPROM
- exactly how the distortion register turns a tone into noise (it's an approximation for now)
- what the envelope does at 0 Hz

VoxProbe 10 and 11 cover some of this, so it will firm up as recordings come in.

C library: andrew-davie/SpeakJet (main). Go library: pull request #16 on JetSetIlly/SpeakJet.

Andrew Davie

**SpeakJet emulation 0.4.0 is out**

Version 0.4.0 of the clean-room SpeakJet library is released. The C library is at https://github.com/andrew-davie/SpeakJet (tag v0.4.0), and the matching Go library has gone to JetSetIlly as a pull request. The two render every sound identically.

**How it was done this time**

For 0.3.0, every table and most of the rules were re-measured from the chip. For 0.4.0 I looked closely at *where* the library still differed. Every sound was compared with the real chip in fine detail: 24 frequency bands, 2.5 ms steps, both AtariVoxes. Each difference was weighed against how much the real chip differs from itself between takes. Anything bigger than the chip's own take-to-take spread is a genuine mistake, and those mistakes showed which sounds had the wrong *structure* (missing sweeps, wrong onsets, parts in the wrong place), not just slightly wrong numbers. Each sound was then rebuilt to its measured structure before any fine-tuning.

Overall, the perceptual score over all 2355 recordings (both units) improved from 0.895 to 0.844, about 5.6 %. Lower is better. The score is relative, so it's the change that matters, not the value itself.

**What's new**

- **Timing, from VoxProbe 12.**
  - Slow now plays a sound at 4/3 of its length and Fast at 2/3. They were ×1.22 and ×0.77.
  - Slow now also applies to the voiced stops.
  - A sound played straight after the same sound now behaves like the chip's Repeat. Those joins used to be about 31 ms too long.
- **The voice pitch** now comes from a 16-bit step, the way the chip appears to count it. The pitch after a reset is the manual's default of 88, which every VoxProbe 12 take confirmed.
- **Allophones:**
  - hissing consonants switch on in 3 ms
  - nasals (M, N) rise in 25 ms
  - voiced stops (B, D, G) start their low "voice bar" at once, with weak upper formants
  - every stop has its own closure, bar and release levels
  - louder onsets
  - the short burst of low noise at the start of sibilants (S, SH)
  - the floor under WH
  - all allophone noise high-passed at 400 Hz
  - each sound has its own attack and release
- **Effects:**
  - every effect has its own attack and release, and the short click the chip makes at the start of an effect
  - the effect release is now 25 ms
  - C8 and C9 sweep 650 Hz to 2.4 kHz, as the chip does
  - A9, B3 and B8 were rebuilt from the chip's own frequency tracks, and seven more were re-anchored
  - several effects had their shape drawn by hand on the spectrogram, snapped to the chip, then tuned
- **The serial control protocol (SCP)** is now in both libraries.
- **Size:** the tables grew to about 5 KB with all of the above.
- **Documentation:** the technical manual is now version 1.8 and matches the code.

**Still on the list**

Some sounds still differ from the chip, and the work continues. I've noticed that "Man Goes Down" can sound more like "Man Gone Down". The /z/ in "goes" comes out too short, and there's a small click where the vowel joins it. That's next.

Thanks to everyone who recorded the VoxProbes on real AtariVoxes. Every one of these changes came from those recordings.


JetSetIlly

https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

Andrew Davie

AtariVox / SpeakJet emulation 2.0.0: rebuilt against the recordings, and measured against 0.4.3

Version 2.0.0 of the C library (andrew-davie/SpeakJet) and the matching Go library is ready. This one is a rebuild, not a patch, so this post explains the approach, what I steered along the way, and how it measures against 0.4.3.

The approach

Every sound is judged by one measure, which I'll call X. A sound's render is compared with the chip's own recordings of that sound on both AtariVoxes (four takes), as a bank of spectrograms at six resolutions from 1.3 to 43 ms. The four takes are first scored against each other, leave-one-out, and the render's distance is divided by the takes' own spread. So X = 1.0 means "as far from the chip as another recording of the chip is", and that is the target, not zero. The same measure judges a candidate rule over all 72 allophones and 55 effects at once, and a rule goes in only when nothing gets worse. Phrases are checked separately, against VoxProbe 4, 7 and 8's pairs and Man Goes Down's four phrases on both units, by a spectrogram cost and by length.

Two rules I held to throughout. A sound is never tuned to hide a mechanism that is wrong: the mechanism goes into the engine, with the recording that shows it named in the source. And the C and Go libraries stay sample-identical (within 3e-5 over every sound and the phrases), so Stella and Gopher2600 play the same thing.

What is in 2.0.0

Every effect (200-254) re-described from the chip's measurements: 236 C6 went from 15 frames to 7, 222 B2 from 21 to 10. The effects' engine gained a flatter bed with a held term, a second-order output stage, a gated off-part of 31 %, and swept noise that climbs for half its cycle.
Allophones: each keeps whichever of its 0.4.3 entry and its new fit scores closer. Slow on a plain vowel is x1.29, not x4/3 (VoxProbe 8's slowed AW and IY on both units). Per-vowel attacks of 20-60 ms, a first voicing period 12 ticks longer, the plain vowels' pulse falling over 72 ticks, PE and PO's low pulse swelling in over 10 ms.
VoxProbe 14's rules, fitted on 2026-11-09 and merged into this release: the Speed step at 116, join terms on IH AW OW RR (+15, +6, -10, -16 ms), the KE locus (a vowel after KE starts with F2 near 2100 Hz), KE and KO after a nasal closing 15 ms longer, Slow on KO and PO growing the closure.
Joins, each from both units: a vowel or glide above Pitch 88 runs longer (an assumption from one Pitch: 16 % at 150, on VoxProbe 7's three vowels, both units); a vowel after a voiced stop opens at its own level; a voiced fricative after a pause opens with 40 ms of noise before its voicing; a voiced stop after a short pause opens its bar 12 ms into the pause; the longer closure after a sound belongs to DO and GO only, not DE and GE; a crossing cut longer than a glide's last segment now trims across it (AYWW into AW was 40 ms long); the attack is in pitch periods above Pitch 88.
Accuracy against 0.4.3 as shipped

Both versions scored by the same measure, on the same recordings. Lower is closer; 1.0 is another take of the chip.

                                  0.4.3    2.0.0
allophones (72), mean X            1.07     0.94   56 closer, 4 further, 12 same
effects (55), mean X               1.22     0.98   52 closer, 2 further
join items (88), mean cost         1437      522   52 closer, 14 further by 15 % or more
items 15 ms or more off in length    24       14

Man Goes Down, length in ms       unit A   unit B    0.4.3    2.0.0
  phrase 1                          1483     1490     1475     1491
  phrase 2                          1676     1671     1683     1690
  phrase 4                           782      787      779      771

tables, every table, bytes         5131     7160

Where it is still wrong, measured

Of the 14 join items further than 0.4.3, two are Man Goes Down's phrases on unit B (the Pitch timing below), one is a unit B take with a long noise tail, and most of the rest start with AW. The phrase judge at first read 29, and preferred a 12 ms attack on AW where the spectrogram measure wants 45; that was the judge aligning by correlation, which a slow onset pulls. Aligned at the lag where its own cost is least, as the spectrogram measure is, it prefers the 45 ms attack too, and the count is 14. AW's formants are the next suspect: 0.4.3's are closer on AW RR and AW LE and further on 33 other items, so they stay.
TH after a vowel is 4-5 dB quieter than the chip's, and TT's burst after a vowel looks lighter, while the measure prefers their level alone.
Phrase 2 is 25 ms long because of how the chip times a Pitch command. On both units, "22 100" before GO applies at once, "22 66" before DO reaches only the final NE two sounds later, and "22 40" before the slowed IYUW never arrives: that IYUW plays at 76. The library applies every Pitch at the next sound. A rule that applied it at the next pause fixed phrase 2 and broke phrase 1, so it is not in; VoxProbe 15 gets a test for it.
The four allophones further than 0.4.3 are IY IH OH UW, each by 0.02 to 0.16.
What I steered, for better and worse

Better: insisting that every render be looked at, not just scored. A long trailing section in the pictures turned out to be a framing fault; "DH looks shifted 10 ms" was the picture using two different onset rules; "PO is 20 ms off" was an onset fallback landing on different features in different takes. Each one was a fault in the measuring tools, and the third would have mis-scored every quiet sound.
Better: "be more thorough" after those. A full alignment audit followed and found 211 HO rendering 40 dB quiet, four sounds 4-12 dB loud, and TS ending 18 ms early. That audit also exposed a take re-alignment that had been putting nasals and voiced stops a pulse out, and the per-vowel attacks were re-derived once it was removed.
Better: keeping a 0.4.3 entry wherever it scored closer, rather than replacing for the sake of it. 211 A1 and twenty allophones kept theirs.
Worse, or at least costly: setting the version to 2.0.0 and writing its notes before the allophone pass, so two installed rules were reversed within the day and the notes rewritten twice. And I relaxed the table budget from 4 KB to 8 KB; the allophone table is 2.4 KB of mostly zeros, and the pressure to compact it is gone.
Mixed: "fix it, don't log it" as a standing rule. It cost hours on picture artefacts, but every one of them turned out to be a real fault in the tools.

Next. VoxProbe 15 needs three tests: when a Pitch command takes effect mid-phrase, with and without a pause and Slow; a vowel's attack after a short pause; and the level of TT and TH next to a vowel. The release is at andrew-davie/SpeakJet, branch main, tag v2.0.0, and the Go library as a pull request to JetSetIlly.

JetSetIlly

https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social