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 todayPathWhat changesExample
ElevenLabs for speech, and a chat model you want to keepSpeech onlyThe base URL and the keyspeak.py
A chat model plus a speech service, and you would drop bothWhole turnsOne call replaces twoturn.py
A prop with its own microphoneOpen microphoneOne connection carries sound both wayslive.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_BASE and FV_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 and after
// 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:

Map an old voice ID
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 useHere
/v1/text-to-speech/{voice_id} and /streamSame.
xi-api-key header, output_formatSame.
model_id, voice_settingsAccepted and ignored. There is one model.
The stream-input WebSocketNot here. Send each sentence to /stream over HTTP instead.
Agents, phone calls, voice cloningNot here.
Languages other than EnglishNot 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.

Once per character
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 todayWhere it goes
The character’s personalityThe persona you pick. You do not write it.
How scary it isscare_level on the prop: family or spooky. A third level, horror, is by arrangement. The details.
Things this prop should know or docustom_prompt on the prop, up to 600 characters.
Things every prop should know about the displayAccount notes, PUT /v1/account/memory, up to 1,000 characters.
The conversation so farNothing 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 lengthNothing to set. Replies are up to three short sentences.
Your own safety rulesBuilt 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:

A turn in the 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_24000 and 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.

  1. Connect to /v1/props/{id}/live?sample_rate=16000 and send your key, in the Authorization header or as a first message {"type": "auth", "key": "…"}.
  2. 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.
  3. When audio_start arrives, play the binary frames that follow at the sample_rate it names.
  4. 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 config message 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.

  1. 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.
  2. 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.
  3. Record which service spoke. You will want the count when you compare them.
  4. Turn it on for yourself first, then a small share of users, then everyone.
The shape of it
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

Reading the switch (Flutter)
// 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 https address. 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_once it tries again in 30 seconds, after daily_limit in ten minutes, and after quota_exceeded not until the app is restarted.

Deadlines

Waiting forLimitThen
The user’s key2 secondsElevenLabs speaks this reply.
The first sound3 secondsElevenLabs speaks this reply.
More sound, mid-reply5 seconds of silenceThe 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 seeIt meansDo this
401 invalid_api_keyThe key is missing or wrong.Do not retry. Fall back and tell the user to check their key.
404 prop_not_foundThat prop is not on this key.Register it again and save the new id.
403 prop_limitThe key has all the props it is allowed.Reuse or delete a prop. Do not register one per conversation.
422 nothing_heardThe recording had no speech.Stay quiet. Do not play an error to the visitor.
429 too_many_at_onceToo 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_exceededThe 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 secondsA 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 throughThe 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

  1. The visitor notice is posted where the prop listens, or shown in your app before the first conversation.
  2. An adult owns the key and is near the prop while it is on.
  3. No prop’s custom_prompt asks visitors for personal details.
  4. Each prop’s scare level suits the people who will meet it. Anything a small child might walk up to stays at family.
  5. Your fallback works: switch FrightVoice off and check the prop still talks.
  6. Everyone using it through your app has agreed to the Beta Terms and the Acceptable Use Policy.