AI agents · Recipes

Voice a scene

Every call for a two-character scene: cast, write, read, check, and hand over in the studio.

A worked example: a two-line exchange between a guard and a thief, voiced, checked and handed to the user in the studio. The call order behind it is in Sequence story calls.

Before you begin

  • The agent is connected over Streamable HTTP.
  • The user has at least two saved voices, and a text-to-speech model is installed.

Cast the voices

  1. Call soundbox.list_voices with no arguments.

    The result lists each voice's id, name and model_id. Choose one for the guard and one for the thief. In the examples that follow, <GUARD_VOICE_ID> and <THIEF_VOICE_ID> stand for those ids.

  2. Call soundbox.list_models and find each voice's model_id.

    Its delivery list names the performance controls that model takes. A model with no list has none.

Write the script

  1. Call soundbox.create_story with a title:

    soundbox.create_story arguments
    {
      "title": "Guard and thief"
    }

    Keep the story_id from the result. <STORY_ID> stands for it from here on.

  2. Call soundbox.add_lines with both lines and a beat between them:

    soundbox.add_lines arguments
    {
      "story_id": "<STORY_ID>",
      "lines": [
        {
          "speaker": "Guard",
          "voice_id": "<GUARD_VOICE_ID>",
          "text": "Who goes there?"
        },
        { "kind": "pause", "duration_s": 0.6 },
        {
          "speaker": "Thief",
          "voice_id": "<THIEF_VOICE_ID>",
          "text": "Just the wind."
        }
      ]
    }

    The result reports added: 3, two lines and one pause, with voiced: 0.

    To have a line performed a certain way, add a delivery object to it with names from that model's delivery list. Never write the direction into text: (whispering) is read aloud.

Read it aloud

  1. Call soundbox.speak_story:

    soundbox.speak_story arguments
    {
      "story_id": "<STORY_ID>"
    }

    The call blocks while each line is read on its own voice's model. The result reports read: 2 and models, the number of lines each model read.

  2. If the result has notes, tell the user. A note means a voice's model was not installed and another model read the line, so it will not sound like that voice.

Check and hand over

  1. Call soundbox.get_story with the story_id.

    Both spoken lines show voiced: true, with a duration_s and a start_s that follow one another. The pause has no audio of its own, so it shows voiced: false.

  2. Give the user the open_in_studio link from any of the results, so they can listen and keep editing.

  3. Optional: if the user wants one file, call soundbox.export_story with the story_id. The result is a library sound with an absolute path.

What's next