fix(tts): back to fast Piper controllers, classroom voice setting

Kokoro-82M generates several times slower than Piper — since the controller
pool moved onto it, every ATC reply arrived seconds late. Controllers return
to distinct Piper speakers with the standard US voice (ryan) as the product
default, so replies are fast again and the default sounds like before.

The classroom gets an instructor-voice setting: standard US voice by default,
'random per module' (stable instructor per module), or one of ten named
US/GB voices.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
itsrubberduck
2026-07-19 12:36:19 +02:00
parent f03355daff
commit 4f367a67aa
5 changed files with 139 additions and 28 deletions

View File

@@ -2,7 +2,6 @@ import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
ATIS_SPEACHES_VOICE,
KOKORO_MODEL,
resolveSpeachesVoice,
SPEACHES_VOICE_MAP,
} from '~~/server/utils/voiceRegistry'
@@ -10,20 +9,20 @@ import {
const fallback = { model: 'speaches-ai/piper-de_DE-thorsten-medium', voice: 'de_DE-thorsten-medium' }
describe('resolveSpeachesVoice', () => {
it('maps every pool voice to a consistent model/voice pair', () => {
it('maps every pool voice to a fast English Piper speaker', () => {
for (const [logical, mapped] of Object.entries(SPEACHES_VOICE_MAP)) {
const result = resolveSpeachesVoice(logical, fallback)
assert.deepEqual(result, mapped)
if (result.model === KOKORO_MODEL) {
// Kokoro voice ids look like af_heart / bm_george.
assert.match(result.voice, /^[abehijpz][fm]_[a-z_]+$/)
} else {
assert.equal(result.model, `speaches-ai/piper-${result.voice}`)
assert.match(result.voice, /^en_/)
}
// Piper only — Kokoro generation was slow enough to delay ATC replies.
assert.equal(result.model, `speaches-ai/piper-${result.voice}`)
assert.match(result.voice, /^en_/)
}
})
it('keeps the default controller voice on the standard US speaker', () => {
assert.equal(resolveSpeachesVoice('alloy', fallback).voice, 'en_US-ryan-medium')
})
it('is case-insensitive and trims', () => {
const result = resolveSpeachesVoice(' Alloy ', fallback)
assert.deepEqual(result, SPEACHES_VOICE_MAP.alloy)

View File

@@ -4,16 +4,20 @@
* names; only the Speaches branch of /api/atc/say resolves them here, so the
* same ids work unchanged on the OpenAI provider.
*
* Speaches auto-downloads missing `speaches-ai/piper-*` models on first use;
* the Kokoro voices all live in one multi-voice model. Controllers get the
* Kokoro speakers (heard most, best quality), pilots the distinct Piper
* speakers — the pools stay disjoint so traffic never sounds like the
* controller talking to itself. Selection follows the curated radio set
* (see docs/plans/2026-07-19-phraseology-taxi-finetune-design.md).
* Speaches auto-downloads missing `speaches-ai/piper-*` models on first use.
* Every pool voice is a distinct Piper speaker — Piper synthesizes fast
* enough for radio latency, and the pools stay disjoint so traffic never
* sounds like the controller talking to itself. Selection follows the
* curated radio set (docs/plans/2026-07-19-phraseology-taxi-finetune-design.md).
*/
export type SpeachesVoice = { model: string; voice: string }
/**
* Kokoro's shared multi-voice model. Not used for any pool voice: it
* generates several times slower than Piper, which showed up directly as
* multi-second ATC reply latency. Kept for explicit opt-in mappings only.
*/
export const KOKORO_MODEL = 'speaches-ai/Kokoro-82M-v1.0-ONNX'
const piper = (voice: string): SpeachesVoice => ({
@@ -21,14 +25,15 @@ const piper = (voice: string): SpeachesVoice => ({
voice,
})
const kokoro = (voice: string): SpeachesVoice => ({ model: KOKORO_MODEL, voice })
export const SPEACHES_VOICE_MAP: Record<string, SpeachesVoice> = {
// Controller pool (CONTROLLER_VOICES)
alloy: kokoro('bm_george'),
echo: kokoro('bf_emma'),
onyx: kokoro('am_michael'),
sage: kokoro('af_heart'),
// Controller pool (CONTROLLER_VOICES). Piper only: Kokoro-82M generates
// several times slower and made every ATC reply audibly late — controllers
// are the latency-critical voices. `alloy` is the product-wide default and
// stays the standard US speaker.
alloy: piper('en_US-ryan-medium'),
echo: piper('en_GB-jenny_dioco-medium'),
onyx: piper('en_US-john-medium'),
sage: piper('en_US-hfc_female-medium'),
// The user's own readback voice (speakPilotReadback)
verse: piper('en_US-lessac-medium'),
// Simulated pilot pool (PILOT_VOICES)