Integration guide · beta
Add FrightVoice to an app you already have.
There are three ways in. Each one has a short example you can run today, and you can start with the smallest and move up later. The API docs have every option; this page is the order to do things in.
Pick a path
| What you have today | Path | What changes | Example |
|---|---|---|---|
| ElevenLabs for speech, and a chat model you want to keep | Speech only | The base URL and the key | speak.py |
| A chat model plus a speech service, and you would drop both | Whole turns | One call replaces two | turn.py |
| A prop with its own microphone | Open microphone | One connection carries sound both ways | live.py |
Start with speech only. It is the smallest change, it cannot break your conversation logic, and it lets you hear our voices next to the ones you use now. Move to whole turns when you want the speed and one bill instead of two.
Before you start
- Your key and base URL arrive together by email. The examples read them from
FV_BASEandFV_KEY. - One key is one display. Props on the same key share memory and can banter. If your app has many users, each needs their own key.
- A beta key has limits: 5 props, 3 talking at once, 1,500 replies a day. An open microphone counts as one for as long as it is connected, so close it when the display is off. The details.
- English only for now. Keep other languages on the service you use today.
- Keep your current service wired in until you trust this one. Make it switchable shows how.
1. Speech only
Your code keeps writing the words. FrightVoice only speaks them. The addresses and the xi-api-key header are the ones ElevenLabs uses, so this is a two-line change:
// before const BASE = "https://api.elevenlabs.io/v1"; const KEY = ELEVENLABS_KEY; // after const BASE = FV_BASE + "/v1"; const KEY = FV_KEY; // unchanged const response = await fetch( `${BASE}/text-to-speech/${voiceId}/stream?output_format=mp3_44100_128`, { method: "POST", headers: { "xi-api-key": KEY, "Content-Type": "application/json" }, body: JSON.stringify({ text }) });
Your voice IDs
An ElevenLabs voice ID means nothing to us, so until you map it the reply comes back in the default voice with the header X-FV-Voice-Fallback: 1. List our voices with GET /v1/voices, then map each of your IDs once:
curl -X PUT "$FV_BASE/v1/voices/YOUR_OLD_VOICE_ID/alias" \ -H "xi-api-key: $FV_KEY" -H "Content-Type: application/json" \ -d '{"voice": "skelly"}'
After that, props and saved settings that still hold the old ID keep working with no update.
What carries over
| You use | Here |
|---|---|
/v1/text-to-speech/{voice_id} and /stream | Same. |
xi-api-key header, output_format | Same. |
model_id, voice_settings | Accepted and ignored. There is one model. |
The stream-input WebSocket | Not here. Send each sentence to /stream over HTTP instead. |
| Agents, phone calls, voice cloning | Not here. |
| Languages other than English | Not yet. |
Run it: speak.py lists the voices and saves a line as an MP3.
2. Whole turns
You send what the visitor said. FrightVoice writes the reply in character and speaks it, in one call. This is where the speed comes from: the first sentence is being spoken while the rest is still being written.
Step 1. Register each prop once
Create a prop for each character in your display and save the id it returns with that character’s settings. You do not create a prop per conversation.
curl -s "$FV_BASE/v1/props" \ -H "Authorization: Bearer $FV_KEY" -H "Content-Type: application/json" \ -d '{"name": "Bones", "persona": "skelly", "location": "by the front gate", "custom_prompt": "The candy bowl is on the porch. Tease people who take more than two."}'
Step 2. Move your prompt across
| In your app today | Where it goes |
|---|---|
| The character’s personality | The persona you pick. You do not write it. |
| How scary it is | scare_level on the prop: family or spooky. A third level, horror, is by arrangement. The details. |
| Things this prop should know or do | custom_prompt on the prop, up to 600 characters. |
| Things every prop should know about the display | Account notes, PUT /v1/account/memory, up to 1,000 characters. |
| The conversation so far | Nothing to send. The service keeps each prop’s recent turns, and props on the same key know what the others just heard. |
| Model, temperature, reply length | Nothing to set. Replies are up to three short sentences. |
| Your own safety rules | Built in, and always on. See what you get. |
Step 3. Send a turn and play the reply
The reply is a stream of JSON lines. Show each text as it arrives and play each audio piece in order. In a browser:
const audio = new AudioContext(); // create this inside a click or tap let playHead = 0, queue = Promise.resolve(); function play(b64) { // each piece is a small WAV file queue = queue.then(async () => { const bytes = Uint8Array.from(atob(b64), c => c.charCodeAt(0)); const buffer = await audio.decodeAudioData(bytes.buffer); const source = audio.createBufferSource(); source.buffer = buffer; source.connect(audio.destination); const at = Math.max(audio.currentTime + 0.03, playHead); source.start(at); // back to back, with no gaps playHead = at + buffer.duration; }); } async function turn(propId, text, onSentence) { const response = await fetch(`${FV_BASE}/v1/props/${propId}/turn`, { method: "POST", headers: { "Authorization": `Bearer ${FV_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ text }), }); if (!response.ok) throw new Error(`FrightVoice ${response.status}`); const reader = response.body.getReader(), decoder = new TextDecoder(); let pending = ""; for (;;) { const { value, done } = await reader.read(); if (done) break; pending += decoder.decode(value, { stream: true }); let end; while ((end = pending.indexOf("\n")) >= 0) { const line = pending.slice(0, end).trim(); pending = pending.slice(end + 1); if (!line) continue; const event = JSON.parse(line); if (event.type === "text") onSentence(event.text); if (event.type === "audio") play(event.b64); if (event.type === "error") throw new Error(event.message); } } }
- On a phone or a slow link, add
?audio=mp3. The audio events then carry slices of one MP3 stream, which is far less data. Feed them to one player in order; a single slice will not play alone. - On a small device, add
?stream=audio&output_format=pcm_24000and send the body of the reply straight to the speaker. No JSON to read. - If you already turn speech into text, send the text. If you do not, send the recording and we will.
Run it: turn.py prints the reply as it arrives, times the first sound and saves the speech.
Do not keep a browser key in a public page. The sample above is right for an app or a page only you can open. For a public page, send turns through your own server and add the key there.
3. Open microphone
For a prop that listens by itself. It opens one WebSocket, streams its microphone, and plays what comes back. The service decides when the visitor has finished, so there is no button and no silence detection for you to build.
- Connect to
/v1/props/{id}/live?sample_rate=16000and send your key, in theAuthorizationheader or as a first message{"type": "auth", "key": "…"}. - Send the microphone as 16-bit mono PCM in frames of about 20 ms. Keep sending while it is quiet. The quiet is how the service hears the pause.
- When
audio_startarrives, play the binary frames that follow at thesample_rateit names. - When your speaker has finished, send
{"type": "playback_done"}. The prop does not listen while it is talking, so this is what makes it listen again promptly.
Run it: live.py plays a WAV file in as the microphone and saves the reply. In our test, the reply started 0.77 seconds after the visitor stopped speaking.
- 16,000 Hz is plenty for speech and halves the upload of 48,000 Hz.
- The pause that counts as “finished” is 0.7 seconds. Change it with a
configmessage if your visitors are cut off or kept waiting. - A visitor cannot interrupt the prop yet, and a loud yard can confuse the pause detection. Both are on our list.
Make it switchable
FrightVoice is a beta on a small number of machines. Until that changes, treat it as the first choice and your current service as the net underneath it.
- One setting picks the provider, read when each reply starts. Make it something you can change without shipping an update, such as a remote setting.
- Give the first sound a deadline. If nothing has arrived in about 3 seconds, or the call fails, let your current service speak that reply.
- Record which service spoke. You will want the count when you compare them.
- Turn it on for yourself first, then a small share of users, then everyone.
async function speak(text, voiceId) {
if (settings.frightVoiceOn) {
try {
return await speakWith(FRIGHTVOICE, text, voiceId, { firstSoundWithinMs: 3000 });
} catch (error) {
log("frightvoice_fallback", error.message); // then fall through
}
}
return speakWith(CURRENT_SERVICE, text, voiceId);
}
Fall back for the whole reply, not part of one: switching voices mid-sentence is worse than a short wait.
How FrightMaps does it
FrightMaps is our own app. Its Ultra Skelly feature speaks through ElevenLabs, and this is how we built FrightVoice into it. It is the speech-only path with the switch from the section above, and nothing in it is special to us.
Two remote settings, both off by default
// Absent, a failed fetch and a fresh install all mean "off". final enabled = all['skelly_frightvoice_enabled']?.asBool() ?? false; final baseUrl = all['skelly_frightvoice_base_url']?.asString().trim() ?? '';
- FrightVoice is used only when the switch is on and the address is set and it is an
httpsaddress. Otherwise the app behaves exactly as it did before. - The settings are read again for every reply, so a change takes effect on the next thing the prop says. Nobody has to restart the app.
The same request as before
The app already called /text-to-speech/{voice_id}/stream for two of its voice modes. With the switch on it sends that same request to the FrightVoice address. Its fastest mode used the ElevenLabs stream-input WebSocket, which we do not have, so that mode takes the HTTP route too while the switch is on.
When it does not even ask
- The reply is not in English. Other languages stay on ElevenLabs.
- The chosen voice has no FrightVoice match. The owner picked a character, so the app keeps that voice on ElevenLabs sooner than answer in a default one. Map the voice ID once and it switches over.
- FrightVoice has just failed. The app skips it for about a minute, and for five minutes after three failures in a row, instead of making every reply wait.
- The key has hit a limit. After
too_many_at_onceit tries again in 30 seconds, afterdaily_limitin ten minutes, and afterquota_exceedednot until the app is restarted.
Deadlines
| Waiting for | Limit | Then |
|---|---|---|
| The user’s key | 2 seconds | ElevenLabs speaks this reply. |
| The first sound | 3 seconds | ElevenLabs speaks this reply. |
| More sound, mid-reply | 5 seconds of silence | The request is closed. What already played stands. |
The key never ships in the app
It is not compiled in and not kept in the remote settings. The app asks our own server for the signed-in user’s key and holds it in memory only. A user with no key is treated as if the switch were off.
Every reply is counted
For each reply the app records which service spoke, why it fell back if it did, and how long the first sound took. That is what tells us whether to turn it on for more people.
When something fails
| You see | It means | Do this |
|---|---|---|
401 invalid_api_key | The key is missing or wrong. | Do not retry. Fall back and tell the user to check their key. |
404 prop_not_found | That prop is not on this key. | Register it again and save the new id. |
403 prop_limit | The key has all the props it is allowed. | Reuse or delete a prop. Do not register one per conversation. |
422 nothing_heard | The recording had no speech. | Stay quiet. Do not play an error to the visitor. |
429 too_many_at_once | Too many of this key’s props are talking right now. | Fall back for this reply. The next one will probably go through. |
429 daily_limit or quota_exceeded | The key has used its allowance. | Fall back until it resets, and tell the user. GET /v1/account shows what is left. |
| 502, or no first sound in 3 seconds | A model behind the service is slow or down. | Fall back for this reply. Try FrightVoice again on the next one. |
An error event part-way through | The reply was cut short. | Let what has played stand. Do not restart the sentence in another voice. |
When the thinking part fails, the prop says a short stumble line in character, so most failures never reach your code.
Keys in apps
- Do not compile a key into an app. Anyone can pull it out of the download.
- Do not put a key in a remote setting that every copy of the app can read. That is the same thing with extra steps.
- Give each signed-in user their own key from your server, or have each user paste in their own, the way they do with an ElevenLabs key today.
- If a key leaks, tell us. We replace it; the props and their settings stay.
Before visitors hear it
- The visitor notice is posted where the prop listens, or shown in your app before the first conversation.
- An adult owns the key and is near the prop while it is on.
- No prop’s
custom_promptasks visitors for personal details. - Each prop’s scare level suits the people who will meet it. Anything a small child might walk up to stays at
family. - Your fallback works: switch FrightVoice off and check the prop still talks.
- Everyone using it through your app has agreed to the Beta Terms and the Acceptable Use Policy.