braidio 0.0.76__tar.gz → 0.0.77__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. {braidio-0.0.76 → braidio-0.0.77}/PKG-INFO +1 -1
  2. {braidio-0.0.76 → braidio-0.0.77}/braidio/delivery.py +13 -0
  3. {braidio-0.0.76 → braidio-0.0.77}/braidio/render.py +20 -13
  4. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_common.py +5 -0
  5. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_narration.py +76 -17
  6. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_voice.py +2 -1
  7. {braidio-0.0.76 → braidio-0.0.77}/pyproject.toml +1 -1
  8. {braidio-0.0.76 → braidio-0.0.77}/tests/test_pacing.py +52 -0
  9. {braidio-0.0.76 → braidio-0.0.77}/tests/test_transforms_rights.py +45 -0
  10. {braidio-0.0.76 → braidio-0.0.77}/.editorconfig +0 -0
  11. {braidio-0.0.76 → braidio-0.0.77}/.gitattributes +0 -0
  12. {braidio-0.0.76 → braidio-0.0.77}/.gitignore +0 -0
  13. {braidio-0.0.76 → braidio-0.0.77}/LICENSE +0 -0
  14. {braidio-0.0.76 → braidio-0.0.77}/README.md +0 -0
  15. {braidio-0.0.76 → braidio-0.0.77}/braidio/__init__.py +0 -0
  16. {braidio-0.0.76 → braidio-0.0.77}/braidio/_paths.py +0 -0
  17. {braidio-0.0.76 → braidio-0.0.77}/braidio/bodies/__init__.py +0 -0
  18. {braidio-0.0.76 → braidio-0.0.77}/braidio/bodies/_domain.py +0 -0
  19. {braidio-0.0.76 → braidio-0.0.77}/braidio/bodies/_render_nodes.py +0 -0
  20. {braidio-0.0.76 → braidio-0.0.77}/braidio/bodies/_tiers.py +0 -0
  21. {braidio-0.0.76 → braidio-0.0.77}/braidio/bodies/_video.py +0 -0
  22. {braidio-0.0.76 → braidio-0.0.77}/braidio/captions.py +0 -0
  23. {braidio-0.0.76 → braidio-0.0.77}/braidio/compose.py +0 -0
  24. {braidio-0.0.76 → braidio-0.0.77}/braidio/conversation.py +0 -0
  25. {braidio-0.0.76 → braidio-0.0.77}/braidio/cost.py +0 -0
  26. {braidio-0.0.76 → braidio-0.0.77}/braidio/data/skills/braidio/SKILL.md +0 -0
  27. {braidio-0.0.76 → braidio-0.0.77}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  28. {braidio-0.0.76 → braidio-0.0.77}/braidio/defaults.py +0 -0
  29. {braidio-0.0.76 → braidio-0.0.77}/braidio/downloads.py +0 -0
  30. {braidio-0.0.76 → braidio-0.0.77}/braidio/formats.py +0 -0
  31. {braidio-0.0.76 → braidio-0.0.77}/braidio/genre.py +0 -0
  32. {braidio-0.0.76 → braidio-0.0.77}/braidio/importing/__init__.py +0 -0
  33. {braidio-0.0.76 → braidio-0.0.77}/braidio/importing/__main__.py +0 -0
  34. {braidio-0.0.76 → braidio-0.0.77}/braidio/importing/_catalog.py +0 -0
  35. {braidio-0.0.76 → braidio-0.0.77}/braidio/importing/_manifest.py +0 -0
  36. {braidio-0.0.76 → braidio-0.0.77}/braidio/importing/_writer.py +0 -0
  37. {braidio-0.0.76 → braidio-0.0.77}/braidio/kinds.py +0 -0
  38. {braidio-0.0.76 → braidio-0.0.77}/braidio/markdown_script.py +0 -0
  39. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/__init__.py +0 -0
  40. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/_docs.py +0 -0
  41. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/_guide.py +0 -0
  42. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/_helpers.py +0 -0
  43. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/_media.py +0 -0
  44. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/credentials.py +0 -0
  45. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/metering.py +0 -0
  46. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/tools.py +0 -0
  47. {braidio-0.0.76 → braidio-0.0.77}/braidio/mcp/workspace.py +0 -0
  48. {braidio-0.0.76 → braidio-0.0.77}/braidio/multivoice.py +0 -0
  49. {braidio-0.0.76 → braidio-0.0.77}/braidio/music.py +0 -0
  50. {braidio-0.0.76 → braidio-0.0.77}/braidio/pacing.py +0 -0
  51. {braidio-0.0.76 → braidio-0.0.77}/braidio/project.py +0 -0
  52. {braidio-0.0.76 → braidio-0.0.77}/braidio/provenance.py +0 -0
  53. {braidio-0.0.76 → braidio-0.0.77}/braidio/relevance.py +0 -0
  54. {braidio-0.0.76 → braidio-0.0.77}/braidio/rights.py +0 -0
  55. {braidio-0.0.76 → braidio-0.0.77}/braidio/script.py +0 -0
  56. {braidio-0.0.76 → braidio-0.0.77}/braidio/sources.py +0 -0
  57. {braidio-0.0.76 → braidio-0.0.77}/braidio/structure.py +0 -0
  58. {braidio-0.0.76 → braidio-0.0.77}/braidio/style.py +0 -0
  59. {braidio-0.0.76 → braidio-0.0.77}/braidio/textprep.py +0 -0
  60. {braidio-0.0.76 → braidio-0.0.77}/braidio/timeline.py +0 -0
  61. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/__init__.py +0 -0
  62. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_asset_refs.py +0 -0
  63. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_dialogue.py +0 -0
  64. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_episode.py +0 -0
  65. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_ingest.py +0 -0
  66. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_segment.py +0 -0
  67. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_video_cut.py +0 -0
  68. {braidio-0.0.76 → braidio-0.0.77}/braidio/transforms/_video_panels.py +0 -0
  69. {braidio-0.0.76 → braidio-0.0.77}/braidio/tts.py +0 -0
  70. {braidio-0.0.76 → braidio-0.0.77}/braidio/video.py +0 -0
  71. {braidio-0.0.76 → braidio-0.0.77}/braidio/voice_library.py +0 -0
  72. {braidio-0.0.76 → braidio-0.0.77}/braidio/weave.py +0 -0
  73. {braidio-0.0.76 → braidio-0.0.77}/braidio/weave_config.py +0 -0
  74. {braidio-0.0.76 → braidio-0.0.77}/conftest.py +0 -0
  75. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/Extraction and nw-App Design.md +0 -0
  76. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  77. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  78. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  79. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/README.md +0 -0
  80. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/anti-platitude-checklist.md +0 -0
  81. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/commentary-voice-guide.md +0 -0
  82. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/_style-groups.md +0 -0
  83. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  84. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/david-sims.md +0 -0
  85. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/griffin-newman.md +0 -0
  86. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/helen-molesworth.md +0 -0
  87. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  88. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  89. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  90. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/jon-caramanica.md +0 -0
  91. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  92. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/karina-longworth.md +0 -0
  93. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/katy-hessel.md +0 -0
  94. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/louis-theroux.md +0 -0
  95. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/mallory-rubin.md +0 -0
  96. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  97. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/michael-barbaro.md +0 -0
  98. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  99. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/paul-scheer.md +0 -0
  100. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/sean-fennessey.md +0 -0
  101. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/talk-art.md +0 -0
  102. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/style/voices/yasi-salek.md +0 -0
  103. {braidio-0.0.76 → braidio-0.0.77}/misc/docs/youtube_ingest_credentials.md +0 -0
  104. {braidio-0.0.76 → braidio-0.0.77}/tests/_audio.py +0 -0
  105. {braidio-0.0.76 → braidio-0.0.77}/tests/test_body_schema_stability.py +0 -0
  106. {braidio-0.0.76 → braidio-0.0.77}/tests/test_conversation.py +0 -0
  107. {braidio-0.0.76 → braidio-0.0.77}/tests/test_cost.py +0 -0
  108. {braidio-0.0.76 → braidio-0.0.77}/tests/test_credits_card.py +0 -0
  109. {braidio-0.0.76 → braidio-0.0.77}/tests/test_defaults.py +0 -0
  110. {braidio-0.0.76 → braidio-0.0.77}/tests/test_delivery.py +0 -0
  111. {braidio-0.0.76 → braidio-0.0.77}/tests/test_downloads.py +0 -0
  112. {braidio-0.0.76 → braidio-0.0.77}/tests/test_expressiveness.py +0 -0
  113. {braidio-0.0.76 → braidio-0.0.77}/tests/test_formats.py +0 -0
  114. {braidio-0.0.76 → braidio-0.0.77}/tests/test_genre_placement.py +0 -0
  115. {braidio-0.0.76 → braidio-0.0.77}/tests/test_importing.py +0 -0
  116. {braidio-0.0.76 → braidio-0.0.77}/tests/test_markdown_script.py +0 -0
  117. {braidio-0.0.76 → braidio-0.0.77}/tests/test_mcp.py +0 -0
  118. {braidio-0.0.76 → braidio-0.0.77}/tests/test_mcp_caller_key.py +0 -0
  119. {braidio-0.0.76 → braidio-0.0.77}/tests/test_media_auth.py +0 -0
  120. {braidio-0.0.76 → braidio-0.0.77}/tests/test_multivoice.py +0 -0
  121. {braidio-0.0.76 → braidio-0.0.77}/tests/test_music.py +0 -0
  122. {braidio-0.0.76 → braidio-0.0.77}/tests/test_namespaced_source.py +0 -0
  123. {braidio-0.0.76 → braidio-0.0.77}/tests/test_nw_app.py +0 -0
  124. {braidio-0.0.76 → braidio-0.0.77}/tests/test_packaging.py +0 -0
  125. {braidio-0.0.76 → braidio-0.0.77}/tests/test_render_settings.py +0 -0
  126. {braidio-0.0.76 → braidio-0.0.77}/tests/test_script.py +0 -0
  127. {braidio-0.0.76 → braidio-0.0.77}/tests/test_sources.py +0 -0
  128. {braidio-0.0.76 → braidio-0.0.77}/tests/test_structure.py +0 -0
  129. {braidio-0.0.76 → braidio-0.0.77}/tests/test_textprep_style.py +0 -0
  130. {braidio-0.0.76 → braidio-0.0.77}/tests/test_timeline.py +0 -0
  131. {braidio-0.0.76 → braidio-0.0.77}/tests/test_transforms.py +0 -0
  132. {braidio-0.0.76 → braidio-0.0.77}/tests/test_transforms_dialogue.py +0 -0
  133. {braidio-0.0.76 → braidio-0.0.77}/tests/test_transforms_episode_members.py +0 -0
  134. {braidio-0.0.76 → braidio-0.0.77}/tests/test_transforms_secrets.py +0 -0
  135. {braidio-0.0.76 → braidio-0.0.77}/tests/test_transforms_structure.py +0 -0
  136. {braidio-0.0.76 → braidio-0.0.77}/tests/test_tts_api_key.py +0 -0
  137. {braidio-0.0.76 → braidio-0.0.77}/tests/test_turn_overlap.py +0 -0
  138. {braidio-0.0.76 → braidio-0.0.77}/tests/test_video.py +0 -0
  139. {braidio-0.0.76 → braidio-0.0.77}/tests/test_video_bodies.py +0 -0
  140. {braidio-0.0.76 → braidio-0.0.77}/tests/test_video_footage.py +0 -0
  141. {braidio-0.0.76 → braidio-0.0.77}/tests/test_video_transforms.py +0 -0
  142. {braidio-0.0.76 → braidio-0.0.77}/tests/test_voice_library.py +0 -0
  143. {braidio-0.0.76 → braidio-0.0.77}/tests/test_weave.py +0 -0
  144. {braidio-0.0.76 → braidio-0.0.77}/tests/test_weave_config.py +0 -0
  145. {braidio-0.0.76 → braidio-0.0.77}/tests/test_wire_descriptions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: braidio
3
- Version: 0.0.76
3
+ Version: 0.0.77
4
4
  Summary: Weave narration with extracted media segments into audiovisual productions
5
5
  Project-URL: Homepage, https://github.com/thorwhalen/braidio
6
6
  Project-URL: Repository, https://github.com/thorwhalen/braidio
@@ -16,6 +16,19 @@ from __future__ import annotations
16
16
  from dataclasses import dataclass, field
17
17
 
18
18
 
19
+ #: Models that ignore ``voice_settings["speed"]`` (eleven v3 has no speed control).
20
+ SPEEDLESS_MODELS = frozenset({"eleven_v3"})
21
+
22
+
23
+ def model_supports_speed(model_id: str) -> bool:
24
+ """Whether ``model_id`` honors ``voice_settings["speed"]``.
25
+
26
+ >>> model_supports_speed("eleven_v3"), model_supports_speed("eleven_multilingual_v2")
27
+ (False, True)
28
+ """
29
+ return model_id not in SPEEDLESS_MODELS
30
+
31
+
19
32
  @dataclass(frozen=True)
20
33
  class Delivery:
21
34
  """A named narration delivery: which model + voice settings to synthesize with."""
@@ -100,26 +100,28 @@ def _tail_gap(src: Path, dst: Path, *, gap_s: float) -> Path:
100
100
  return dst
101
101
 
102
102
 
103
- def _plan_beat_turns(
103
+ def plan_beat_turns(
104
104
  text: str,
105
105
  *,
106
106
  config: WeaveConfig | None,
107
- delivery: Delivery,
107
+ supports_speed: bool,
108
108
  settings: dict,
109
109
  seed_offset: int,
110
110
  ) -> list[NarrationTurn]:
111
111
  """Plan one narration beat's turns, or ``[]`` for the unpaced single call.
112
112
 
113
- The speed each turn is jittered around is the *delivery's* own ``speed``
113
+ The speed each turn is jittered around is the beat's own ``speed`` setting
114
114
  when it sets one (so a grave ``v2-narrator``'s 0.94 survives being paced),
115
115
  falling back to ``WeaveConfig.speed_base``. A model with no speed control
116
- (eleven v3 — :attr:`braidio.delivery.Delivery.supports_speed`) plans none.
116
+ (eleven v3 — :attr:`braidio.delivery.Delivery.supports_speed`,
117
+ :func:`braidio.delivery.model_supports_speed`) plans none.
118
+
119
+ Shared by the fast path and the graph's ``narration_render.tts``, which is
120
+ what keeps their per-beat durations (and so their timelines) equal.
117
121
  """
118
122
  if config is None or not config.paces_narration:
119
123
  return []
120
- speed_base = (
121
- settings.get("speed", config.speed_base) if delivery.supports_speed else None
122
- )
124
+ speed_base = settings.get("speed", config.speed_base) if supports_speed else None
123
125
  return plan_turns(
124
126
  text,
125
127
  unit=config.segmentation_unit,
@@ -132,7 +134,7 @@ def _plan_beat_turns(
132
134
  )
133
135
 
134
136
 
135
- def _narrate_turns(
137
+ def narrate_turns(
136
138
  turns: list[NarrationTurn],
137
139
  *,
138
140
  stem: Path,
@@ -140,6 +142,7 @@ def _narrate_turns(
140
142
  voice_id: str | None,
141
143
  model_id: str,
142
144
  voice_settings: dict,
145
+ narrate_fn=None,
143
146
  ) -> Path:
144
147
  """Synthesize a paced narration beat: one TTS call per turn, real silence between.
145
148
 
@@ -147,13 +150,17 @@ def _narrate_turns(
147
150
  varies (a fresh prosodic arc per turn, a per-turn speed where the model has
148
151
  one) and the silence between turns is proportional to how strongly the
149
152
  boundary closes, instead of one flat arc with nothing inside it.
153
+
154
+ ``narrate_fn`` is the synthesis call (default: this module's ``narrate``);
155
+ a caller that wants the cache status, or a stub, passes its own.
150
156
  """
157
+ synthesize = narrate_fn or narrate
151
158
  parts: list[Path] = []
152
159
  for j, turn in enumerate(turns):
153
160
  settings = dict(voice_settings)
154
161
  if turn.speed is not None:
155
162
  settings["speed"] = turn.speed
156
- part = narrate(
163
+ part = synthesize(
157
164
  turn.text,
158
165
  stem.with_name(f"{stem.name}-turn{j:02d}.mp3"),
159
166
  api_key=api_key,
@@ -375,15 +382,15 @@ def render_production(
375
382
  )
376
383
  # Intra-beat pacing — empty plan (the default `segmentation_unit=
377
384
  # "beat"`) keeps the historical one-call-per-beat path untouched.
378
- turns = _plan_beat_turns(
385
+ turns = plan_beat_turns(
379
386
  pb.content,
380
387
  config=config,
381
- delivery=delivery,
388
+ supports_speed=delivery.supports_speed,
382
389
  settings=beat_settings,
383
- seed_offset=i,
390
+ seed_offset=pb.from_index, # the script position, as the graph's beat_id
384
391
  )
385
392
  if turns:
386
- raw = _narrate_turns(
393
+ raw = narrate_turns(
387
394
  turns,
388
395
  stem=beat_stem,
389
396
  api_key=api_key,
@@ -141,6 +141,11 @@ def beat_id(index: int) -> str:
141
141
  return f"{index:0{BEAT_ID_WIDTH}d}"
142
142
 
143
143
 
144
+ def beat_ordinal(beat: Annotation) -> int:
145
+ """A narrative beat's script position — what casting and pacing seed on."""
146
+ return int(beat.body.get("beat_id", "0") or 0)
147
+
148
+
144
149
  def planned_value(ann: Annotation) -> dict:
145
150
  """``ann.body`` minus its :data:`RENDER_OUTPUT_KEYS` — what its plan decided.
146
151
 
@@ -21,7 +21,9 @@ audio-affecting input). ``None`` falls back to the process environment
21
21
  from __future__ import annotations
22
22
 
23
23
  import json
24
+ import shutil
24
25
  import uuid
26
+ from dataclasses import asdict
25
27
  from pathlib import Path
26
28
 
27
29
  from falaw import Plan
@@ -37,12 +39,16 @@ from braidio.bodies._render_nodes import (
37
39
  NarrationRenderBodyV1,
38
40
  )
39
41
  from braidio.cost import tts_cost_usd
42
+ from braidio.delivery import model_supports_speed
43
+ from braidio.render import narrate_turns, plan_beat_turns
40
44
  from braidio.tts import DEFAULT_MODEL_ID, DEFAULT_VOICE_ID
45
+ from braidio.weave_config import WeaveConfig
41
46
  from braidio.transforms._common import (
42
47
  TIER_NARRATIVE_BEAT,
43
48
  TIER_VOICE_ASSIGNMENT,
44
49
  TIER_WEAVE_CONFIG,
45
50
  TIER_NARRATION_RENDER,
51
+ beat_ordinal,
46
52
  child_at_tier,
47
53
  singleton,
48
54
  graph_index,
@@ -61,7 +67,7 @@ NAME = "narration_render.tts"
61
67
 
62
68
 
63
69
  def _narration_cache_key(
64
- transform, text: str, voice_id: str, model_id: str, settings
70
+ transform, text: str, voice_id: str, model_id: str, settings, turns=()
65
71
  ) -> str:
66
72
  """The output identity for one TTS render — nw's shared derivation.
67
73
 
@@ -71,17 +77,23 @@ def _narration_cache_key(
71
77
  bump — which is then the first salt (nw#54; drift in the previous
72
78
  private ``mixing._cache`` import would have silently changed cache keys
73
79
  on PAID calls).
80
+
81
+ ``turns`` is the paced plan (:func:`_beat_turns`): what is synthesized when
82
+ the config paces narration. Unpaced, it is empty and adds nothing, so an
83
+ unpaced project keeps its keys.
74
84
  """
75
85
  from nw.transforms import cache_key as transform_cache_key
76
86
 
77
- return transform_cache_key(
78
- transform,
87
+ parts = [
79
88
  "narration",
80
89
  text,
81
90
  voice_id,
82
91
  model_id,
83
92
  json.dumps(settings or {}, sort_keys=True),
84
- )
93
+ ]
94
+ if turns:
95
+ parts.append(json.dumps([asdict(t) for t in turns], sort_keys=True))
96
+ return transform_cache_key(transform, *parts)
85
97
 
86
98
 
87
99
  def _beat_settings(beat, config: dict) -> dict:
@@ -89,6 +101,24 @@ def _beat_settings(beat, config: dict) -> dict:
89
101
  return beat.body.get("voice_settings") or config.get("voice_settings", {})
90
102
 
91
103
 
104
+ def _beat_turns(beat, config: dict, *, model_id: str, settings: dict) -> list:
105
+ """The beat's paced turns — ``[]`` when the config does not pace narration.
106
+
107
+ The fast path's planner (:func:`braidio.render.plan_beat_turns`), so a
108
+ ``segmentation_unit`` other than ``"beat"`` cuts a beat the same way on both
109
+ paths. Seeded by the beat's script position (``beat_id`` here,
110
+ ``PlannedBeat.from_index`` on the fast path), which a dropped beat leaves
111
+ unchanged.
112
+ """
113
+ return plan_beat_turns(
114
+ beat.body.get("text", ""),
115
+ config=WeaveConfig.from_snapshot(config),
116
+ supports_speed=model_supports_speed(model_id),
117
+ settings=settings,
118
+ seed_offset=beat_ordinal(beat),
119
+ )
120
+
121
+
92
122
  @register_transform(NAME)
93
123
  class NarrationRenderTTS(BaseTransform):
94
124
  """Narrative beat (+ voice-assignment + weave-config) → ``narration-render/v1``."""
@@ -108,8 +138,9 @@ class NarrationRenderTTS(BaseTransform):
108
138
  voice_id = va.body.get("voice_id") or DEFAULT_VOICE_ID
109
139
  model_id = config.get("model_id", DEFAULT_MODEL_ID)
110
140
  settings = _beat_settings(beat, config)
141
+ turns = _beat_turns(beat, config, model_id=model_id, settings=settings)
111
142
  cache_key = _narration_cache_key(
112
- self, beat.body.get("text", ""), voice_id, model_id, settings
143
+ self, beat.body.get("text", ""), voice_id, model_id, settings, turns
113
144
  )
114
145
 
115
146
  full = TransformInputs(
@@ -180,18 +211,46 @@ class NarrationRenderTTS(BaseTransform):
180
211
  out_path.parent.mkdir(parents=True, exist_ok=True)
181
212
  # was_cached: mixing served this from its on-disk cache (no ElevenLabs call
182
213
  # = $0 real spend) even though our graph cache missed — braidio#8.
183
- _, was_cached = braidio.narrate(
184
- text,
185
- out_path,
186
- # The caller's key, if the driver handed one in (nw's `secrets=`
187
- # seam; thorwhalen/braidio#58) — else None, the process env. Never
188
- # persisted: not in the node, not in the cache_key.
189
- api_key=elevenlabs_key(secrets),
190
- voice_id=va.body.get("voice_id") or DEFAULT_VOICE_ID,
191
- model_id=model_id,
192
- voice_settings=_beat_settings(beat, config),
193
- return_cache_status=True,
194
- )
214
+ voice_id = va.body.get("voice_id") or DEFAULT_VOICE_ID
215
+ settings = _beat_settings(beat, config)
216
+ # The caller's key, if the driver handed one in (nw's `secrets=` seam;
217
+ # thorwhalen/braidio#58) — else None, the process env. Never persisted:
218
+ # not in the node, not in the cache_key.
219
+ api_key = elevenlabs_key(secrets)
220
+ turns = _beat_turns(beat, config, model_id=model_id, settings=settings)
221
+ if turns: # paced: one call per turn, real silence between (braidio#118)
222
+ cached: list[bool] = []
223
+
224
+ def synthesize(turn_text, turn_path, **kwargs):
225
+ path, hit = braidio.narrate(
226
+ turn_text, turn_path, return_cache_status=True, **kwargs
227
+ )
228
+ cached.append(hit)
229
+ return path
230
+
231
+ paced = narrate_turns(
232
+ turns,
233
+ stem=out_path.with_suffix(""),
234
+ api_key=api_key,
235
+ voice_id=voice_id,
236
+ model_id=model_id,
237
+ voice_settings=settings,
238
+ narrate_fn=synthesize,
239
+ )
240
+ shutil.move(paced, out_path)
241
+ for leftover in out_path.parent.glob(f"{skel.id}-turn*"):
242
+ leftover.unlink() # per-turn parts and gaps: only the mix is a node
243
+ was_cached = all(cached)
244
+ else:
245
+ _, was_cached = braidio.narrate(
246
+ text,
247
+ out_path,
248
+ api_key=api_key,
249
+ voice_id=voice_id,
250
+ model_id=model_id,
251
+ voice_settings=settings,
252
+ return_cache_status=True,
253
+ )
195
254
  duration = safe_duration(out_path)
196
255
  artifact = audio_artifact(
197
256
  out_path,
@@ -32,6 +32,7 @@ from braidio.tts import resolve_voice_id
32
32
  from braidio.weave_config import WeaveConfig
33
33
  from braidio.transforms._common import (
34
34
  TIER_VOICE_ASSIGNMENT,
35
+ beat_ordinal,
35
36
  fresh_equivalent,
36
37
  singleton,
37
38
  )
@@ -53,7 +54,7 @@ class BeatToVoiceAssignment(BaseTransform):
53
54
  beat = inputs.primary[0]
54
55
  cfg = singleton(project, "weave-configs")
55
56
  config = WeaveConfig.from_snapshot(cfg.body.get("config", {}))
56
- ordinal = int(beat.body.get("beat_id", "0") or 0)
57
+ ordinal = beat_ordinal(beat)
57
58
  # the beat's own override, else the pool — the fast path's rule exactly
58
59
  voice_id = config.cast_voice(
59
60
  ordinal, override=beat.body.get("voice")
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "braidio"
9
- version = "0.0.76"
9
+ version = "0.0.77"
10
10
  description = "Weave narration with extracted media segments into audiovisual productions"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
@@ -284,3 +284,55 @@ def test_config_crossfade_is_honoured_on_the_concat_path(
284
284
  tight = _render(script2, tmp_path, config=cfg.with_(crossfade_s=0.0), name="cf0")
285
285
  wide = _render(script2, tmp_path, config=cfg.with_(crossfade_s=0.3), name="cf3")
286
286
  assert duration_s(tight) - duration_s(wide) == pytest.approx(0.3, abs=0.1)
287
+
288
+
289
+ # --- the graph path paces too (braidio#118) ----------------------------------
290
+
291
+
292
+ @needs_ffmpeg
293
+ def test_graph_narration_render_paces_like_the_fast_path(
294
+ script, tmp_path, tone_narration, monkeypatch
295
+ ):
296
+ """``segmentation_unit`` reaches ``narration_render.tts``: same turns, one
297
+ call each, and a rendered file as long as the fast path's."""
298
+ import nw
299
+ from nw import TransformInputs
300
+
301
+ graph_calls: list[str] = []
302
+
303
+ def graph_narrate(text, out_path, *, return_cache_status=False, **kw):
304
+ graph_calls.append(text)
305
+ path = tone(Path(out_path), 440, 0.5)
306
+ return (path, False) if return_cache_status else path
307
+
308
+ monkeypatch.setattr(braidio, "narrate", graph_narrate)
309
+ cfg = WeaveConfig(
310
+ segmentation_unit="sentence", min_turn=1, max_turn=1, gap_turn_s=0.2
311
+ )
312
+ fast = _render(script, tmp_path, config=cfg, name="fast")
313
+
314
+ project = braidio.Project.init(tmp_path / "proj", title="t")
315
+ braidio.transforms.ingest_script(project, script, source=None, config=cfg)
316
+ beat = nw.annotations_at_tier(project.root, "narrative-beats")[0]
317
+ voice = nw.get_transform("beat_to_voice_assignment.default")
318
+ narration = nw.get_transform("narration_render.tts")
319
+ voice.execute(project, *voice.plan(project, TransformInputs(primary=(beat,))))
320
+ plan, skel = narration.plan(project, TransformInputs(primary=(beat,)))
321
+ node = narration.execute(project, plan, skel).annotations[0]
322
+
323
+ assert graph_calls == [c["text"] for c in tone_narration] # the fast path's turns
324
+ assert len(graph_calls) == 4
325
+ assert node.body["duration_s"] == pytest.approx(duration_s(fast), abs=0.15)
326
+
327
+
328
+ def test_unpaced_graph_cache_key_is_unchanged_by_the_pacing_plan():
329
+ from braidio.transforms._narration import _narration_cache_key
330
+
331
+ class _T:
332
+ name = "narration_render.tts"
333
+ impl_version = 1
334
+
335
+ plain = _narration_cache_key(_T, "t", "v", "m", {})
336
+ assert plain == _narration_cache_key(_T, "t", "v", "m", {}, ())
337
+ paced = plan_turns("One. Two.", unit="sentence", min_turn=1, max_turn=1)
338
+ assert plain != _narration_cache_key(_T, "t", "v", "m", {}, paced)
@@ -404,3 +404,48 @@ def test_declaring_the_default_profile_renders_the_same_members(
404
404
  profile=braidio.Profile.PERSONAL,
405
405
  )
406
406
  assert undeclared.body["profile"] == declared.body["profile"] == "personal"
407
+
408
+
409
+ @needs_ffmpeg
410
+ def test_paced_seed_is_the_script_position_on_both_paths(
411
+ project, source, tone_narration, tmp_path, monkeypatch
412
+ ):
413
+ """A dropped segment shifts plan positions, not script positions: both paths
414
+ must seed pacing on the latter (braidio#118)."""
415
+ import braidio.render as render_mod
416
+ import braidio.transforms._narration as narration_mod
417
+
418
+ seeds: dict[str, list[int]] = {"fast": [], "graph": []}
419
+
420
+ def spy(name, real):
421
+ def planner(*args, **kw):
422
+ seeds[name].append(kw["seed_offset"])
423
+ return real(*args, **kw)
424
+
425
+ return planner
426
+
427
+ def fast_narrate(text, out, **kw): # the fast path calls render's own `narrate`
428
+ return tone(Path(out), 220, 1.0)
429
+
430
+ monkeypatch.setattr(render_mod, "narrate", fast_narrate)
431
+ real = render_mod.plan_beat_turns
432
+ monkeypatch.setattr(render_mod, "plan_beat_turns", spy("fast", real))
433
+ monkeypatch.setattr(narration_mod, "plan_beat_turns", spy("graph", real))
434
+ script = _personal_only_script()
435
+ cfg = braidio.WeaveConfig(segmentation_unit="sentence", min_turn=1, max_turn=3)
436
+
437
+ braidio.render_production(
438
+ script,
439
+ source=source,
440
+ config=cfg,
441
+ profile=braidio.Profile.PUBLISHED,
442
+ out_path=tmp_path / "fast.mp3",
443
+ tts_dir=tmp_path / "tts",
444
+ clips_dir=tmp_path / "clips",
445
+ )
446
+ braidio.weave_project(
447
+ project, script, source=source, profile=braidio.Profile.PUBLISHED, config=cfg
448
+ )
449
+
450
+ # (the graph plans in `plan` and again in `execute`: one seed per beat)
451
+ assert seeds["fast"] == sorted(set(seeds["graph"])) == [0, 2]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes