cajpany's picture
Genre-distinct fixture writer so live broadcasts vary by genre
b32696b verified
Raw
History Blame Contribute Delete
11.9 kB
"""Deterministic, genre-distinct fixtures used as the live (CPU) writer.
The hosted Space can't run the 4B Nemotron writer, so this fixture *is* what
listeners hear. To keep broadcasts from all sounding the same, each genre has
its own cast (different Kokoro voices), opening, dialogue, SFX, and music — plus
a per-premise variant so reruns within a genre still vary. It stays fully
deterministic (same premise + genre -> same script).
"""
from __future__ import annotations
from .schema import CastMember, Delivery, Genre, Line, MusicPlan, Scene, Script, VoiceID
def fixture_script(premise: str, genre: Genre = Genre.WEIRD) -> Script:
genre = Genre(genre)
clean_premise = " ".join(premise.strip().split())[:300] or "a signal with no sender"
title = _title_from_premise(clean_premise)
variant = _variant(clean_premise)
cast, scenes, music, seconds = _GENRE_BUILDERS[genre](clean_premise, title, variant)
script = Script(
title=title,
logline=_LOGLINES[genre].format(premise=clean_premise),
genre=genre,
cast=cast,
scenes=scenes,
music=music,
estimated_seconds=seconds,
)
script.validate()
return script
def _variant(premise: str, choices: int = 2) -> int:
"""Stable (unsalted) premise hash so a premise always picks the same line."""
return sum(ord(ch) for ch in premise) % choices
def _title_from_premise(premise: str) -> str:
words = [word.strip(".,:;!?").title() for word in premise.split() if word.strip()]
core = " ".join(words[:6]) or "The Signal"
return f"The Case of {core}"
def _member(id: str, name: str, voice: VoiceID, description: str) -> CastMember:
return CastMember(id=id, name=name, voice=voice, description=description)
_LOGLINES = {
Genre.NOIR: "A rain-soaked detective takes the case of {premise}.",
Genre.WEIRD: "A late-night broadcast catches the story of {premise}.",
Genre.WESTERN: "A frontier town reckons with {premise}.",
Genre.ROMANCE: "Two hearts meet again over {premise}.",
Genre.COMEDY: "A radio studio descends into chaos over {premise}.",
Genre.HINDI_MELODRAMA: "Fate tears two lovers apart over {premise}.",
}
# --- Per-genre builders: (premise, title, variant) -> (cast, scenes, music, seconds) ---
def _noir(premise: str, title: str, v: int):
cast = [
_member("sam", "Sam Calloway", VoiceID.DETECTIVE, "A tired private eye who has seen it all."),
_member("vera", "Vera Lake", VoiceID.INGENUE, "A client with a secret and nowhere left to run."),
]
open_line = [
f"It was the kind of night that drags strange cases through my door. Mine was {premise}.",
f"I'd seen this city do its worst, but {premise}? That was a brand-new shade of trouble.",
][v]
scenes = [
Scene(
title="Rain on the Glass",
sfx=["rain on a window", "a distant saxophone", "a ticking wall clock"],
lines=[
Line(cast="sam", delivery=Delivery.DEADPAN, text=open_line),
Line(cast="vera", delivery=Delivery.URGENT, text=f"You have to help me. It's about {premise}, and someone already knows I'm here."),
Line(cast="sam", delivery=Delivery.NEUTRAL, text="I poured a drink and let her talk. The clock kept time with my pulse."),
],
),
Scene(
title="The Double Cross",
sfx=["a door creaks open", "a revolver cocks"],
lines=[
Line(cast="vera", delivery=Delivery.WHISPER, text="They followed me here. I'm certain of it."),
Line(cast="sam", delivery=Delivery.SLOW, text="In this town, certainty is the first thing they take from you."),
],
),
]
music = MusicPlan(genre=Genre.NOIR, opening_sting="muted trumpet sting", bed="rain-soaked piano bed", closing_sting="lonely upright bass note")
return cast, scenes, music, 70
def _weird(premise: str, title: str, v: int):
cast = [
_member("announcer", "The Announcer", VoiceID.ANNOUNCER, "Warm, precise, and a little too calm."),
_member("caller", "The Caller", VoiceID.INGENUE, "Tired, urgent, and listening for an answer."),
]
open_line = [
f"Good evening, travelers. Tonight: {title}.",
f"We interrupt the silence to bring you a transmission concerning {premise}.",
][v]
scenes = [
Scene(
title="The Signal Opens",
sfx=["soft radio static", "a distant electrical hum"],
lines=[
Line(cast="announcer", delivery=Delivery.BOOMING, text=open_line),
Line(cast="caller", delivery=Delivery.URGENT, text=f"I found {premise}, and it knew my name before I spoke."),
Line(cast="announcer", delivery=Delivery.DEADPAN, text="Then keep your hand on the receiver. Dead air dislikes witnesses."),
],
),
Scene(
title="The Line Answers",
sfx=["a rotary phone ring", "low thunder"],
lines=[
Line(cast="caller", delivery=Delivery.WHISPER, text="The dial is turning by itself now."),
Line(cast="announcer", delivery=Delivery.SLOW, text="Listeners, if your lamps flicker, do not adjust the frequency."),
],
),
]
music = MusicPlan(genre=Genre.WEIRD, opening_sting="uneasy brass sting", bed="low midnight organ bed", closing_sting="final unresolved chord")
return cast, scenes, music, 65
def _western(premise: str, title: str, v: int):
cast = [
_member("dunn", "Sheriff Dunn", VoiceID.ANNOUNCER, "A weathered lawman with one last reckoning in him."),
_member("stranger", "The Stranger", VoiceID.VILLAIN, "A drifter who rode in with the dust and bad news."),
]
open_line = [
f"Folks 'round here don't speak of {premise}. I aim to find out why.",
f"Sun was high when the trouble rode in: {premise}.",
][v]
scenes = [
Scene(
title="High Noon Dust",
sfx=["jingling spurs", "saloon doors swinging", "a distant coyote"],
lines=[
Line(cast="dunn", delivery=Delivery.NEUTRAL, text=open_line),
Line(cast="stranger", delivery=Delivery.DEADPAN, text=f"You're chasing {premise}, Sheriff? Some trails end in the dirt."),
Line(cast="dunn", delivery=Delivery.BOOMING, text="Then I'll dig. This town's owed a reckoning."),
],
),
Scene(
title="The Standoff",
sfx=["a revolver cocks", "wind over the plains"],
lines=[
Line(cast="stranger", delivery=Delivery.AGITATED, text="Last chance to ride away clean."),
Line(cast="dunn", delivery=Delivery.SLOW, text="I never did learn that particular trick."),
],
),
]
music = MusicPlan(genre=Genre.WESTERN, opening_sting="lone harmonica sting", bed="dusty acoustic guitar bed", closing_sting="single struck anvil")
return cast, scenes, music, 68
def _romance(premise: str, title: str, v: int):
cast = [
_member("eleanor", "Eleanor", VoiceID.INGENUE, "Hopeful, guarded, and out of second chances."),
_member("thomas", "Thomas", VoiceID.ELDER, "Steady and warm, carrying a question he never asked."),
]
open_line = [
f"I almost didn't come. But {premise} — it changed everything.",
f"They told me {premise}. I came to the station to see if it was true.",
][v]
scenes = [
Scene(
title="The Platform",
sfx=["a steam train arriving", "gentle rain", "a station bell"],
lines=[
Line(cast="eleanor", delivery=Delivery.SLOW, text=open_line),
Line(cast="thomas", delivery=Delivery.NEUTRAL, text=f"I would have waited all night. Even for {premise}."),
Line(cast="eleanor", delivery=Delivery.WHISPER, text="Then don't let go this time."),
],
),
Scene(
title="The Last Train",
sfx=["a train whistle", "footsteps on a platform"],
lines=[
Line(cast="thomas", delivery=Delivery.URGENT, text="Come with me. We can leave all of it behind."),
Line(cast="eleanor", delivery=Delivery.NEUTRAL, text="Ask me again — and mean it this time."),
],
),
]
music = MusicPlan(genre=Genre.ROMANCE, opening_sting="tender string swell", bed="soft piano romance bed", closing_sting="warm cello resolve")
return cast, scenes, music, 66
def _comedy(premise: str, title: str, v: int):
cast = [
_member("benny", "Benny", VoiceID.COMIC, "A fast-talking schemer with terrible ideas."),
_member("wallace", "Mr. Wallace", VoiceID.ANNOUNCER, "The long-suffering station manager."),
]
open_line = [
f"Boss, you won't believe it — {premise}! Right here in the lobby!",
f"So I says to the fella, '{premise}?' And he faints clean away!",
][v]
scenes = [
Scene(
title="The Mix-Up",
sfx=["a slide whistle", "a door slams", "a studio audience laughs"],
lines=[
Line(cast="benny", delivery=Delivery.AGITATED, text=open_line),
Line(cast="wallace", delivery=Delivery.DEADPAN, text=f"Benny. We do not have a budget for {premise}."),
Line(cast="benny", delivery=Delivery.URGENT, text="We do now! I already sold the tickets!"),
],
),
Scene(
title="The Payoff",
sfx=["a rim shot", "applause"],
lines=[
Line(cast="wallace", delivery=Delivery.SLOW, text="Then why is the mayor calling my office?"),
Line(cast="benny", delivery=Delivery.BOOMING, text="Funny story! Remember those tickets?"),
],
),
]
music = MusicPlan(genre=Genre.COMEDY, opening_sting="bouncy clarinet sting", bed="vaudeville upright piano bed", closing_sting="comic tuba button")
return cast, scenes, music, 62
def _hindi(premise: str, title: str, v: int):
cast = [
_member("meera", "Meera", VoiceID.HINDI_FEMALE, "Torn between her heart and her family's honor."),
_member("arjun", "Arjun", VoiceID.HINDI_MALE, "A lover who would defy destiny itself."),
]
open_line = [
f"Arjun! After everything — {premise}? How can destiny be so cruel?",
f"They told me {premise}. My heart refused to believe a single word.",
][v]
scenes = [
Scene(
title="Bichhde Hue",
sfx=["monsoon rain", "a temple bell", "distant thunder"],
lines=[
Line(cast="meera", delivery=Delivery.AGITATED, text=open_line),
Line(cast="arjun", delivery=Delivery.URGENT, text=f"Meera, I crossed every river for you. Even {premise} cannot stop me."),
Line(cast="meera", delivery=Delivery.WHISPER, text="Maa will never accept us. You know this in your heart."),
],
),
Scene(
title="Taqdeer",
sfx=["a train whistle", "anklet bells", "rolling thunder"],
lines=[
Line(cast="arjun", delivery=Delivery.BOOMING, text="Then tonight we will write a new destiny, together!"),
Line(cast="meera", delivery=Delivery.SLOW, text="Promise me. On this rain, on this night, promise me."),
],
),
]
music = MusicPlan(genre=Genre.HINDI_MELODRAMA, opening_sting="swelling sitar sting", bed="harmonium melodrama bed", closing_sting="tabla heartbeat fade")
return cast, scenes, music, 75
_GENRE_BUILDERS = {
Genre.NOIR: _noir,
Genre.WEIRD: _weird,
Genre.WESTERN: _western,
Genre.ROMANCE: _romance,
Genre.COMEDY: _comedy,
Genre.HINDI_MELODRAMA: _hindi,
}