Speech
Skill ferret-speech · download all skills · SKILL.md
When to use#
An NPC or narrator speaks a line from text; the player talks to the game (a command, an answer, a chat line); a recording is turned into text.
The model#
SpeechService (installSpeech(world, opts?)) gives primitives and binds no input: speak(entity | null, text, {voice, language, interrupt}) plays on the voice bus at the entity, lines of one speaker queue; synthesize(text) returns a clip (MP3) and caches it; listen() -> stop() (the text) or cancel() (nothing sent); recognize(clip | bytes | pcm). Requests go to Camerlengo (ai:tts, ai:stt) with the signed-in player's session from AccountService, so the player's wallet pays; client, session, key or a whole backend override it. Events at the fixed step: speech:start, speech:end, speech:heard, speech:listening, speech:error.
Steps#
- Register
AudioServiceandAccountService(with aCamerlengoClientonhttps://squirrelwisdom.com/and the public key that hasai:ttsandai:stt), theninstallSpeech(world). - Unlock sound on the first user action (
audio.unlock()). - Speak:
speech.speak(npc, text, { voice, language }); always givelanguage(otherwise the server pays a detection call per line). Pre-synthesise known lines withsynthesizeto hide the round trip. - Listen: bind the game's own action to
listen()andstop(); showlevelas a meter; handleSpeechErrorcodes. - Idle people: give the micromotion person the entity's id, and spoken lines give beats over their real length.
Check afterwards#
speech.status shows lines and the cache; packages/speech/test/speech.test.ts passes; in the ?speech viewer a signed-in player hears the figure from its side and a held talk button gives text. Headless: startServer({ headless: true, speech: true, fakeMic: 'x.wav' }).
What usually goes wrong#
signed-out: a guest; nobody signed in and no override. Nothing was sent.forbidden(997): the key lacksai:tts/ai:stt.no-funds(402): the player's wallet is too low.audio-locked: a line before the first user action.- Network errors: the client must point at
https://squirrelwisdom.com/, the proxy to the backend, never at the backend host itself. empty: the capture was silence (wrong microphone, muted) or nothing was recognised.
Files#
reference/speech.md— Text to speech and speech to text on the Camerlengo API (@ferret/speech): lines spoken at an entity on the voice bus, a cache of synthesised lines, microphone capture and recognition, by the signed-in player's session; events, speech.* commands and the ?speech viewer.reference/api-speech.md— every export of@ferret/speechwith signature and doc commentreference/commands.md— 8 commands of these packages with their arguments