braidio 0.0.82__tar.gz → 0.0.84__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 (149) hide show
  1. {braidio-0.0.82 → braidio-0.0.84}/PKG-INFO +13 -2
  2. {braidio-0.0.82 → braidio-0.0.84}/README.md +12 -1
  3. {braidio-0.0.82 → braidio-0.0.84}/braidio/bodies/_render_nodes.py +6 -0
  4. {braidio-0.0.82 → braidio-0.0.84}/braidio/conversation.py +8 -4
  5. {braidio-0.0.82 → braidio-0.0.84}/braidio/cost.py +25 -0
  6. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/tools.py +1 -1
  7. {braidio-0.0.82 → braidio-0.0.84}/braidio/multivoice.py +2 -36
  8. {braidio-0.0.82 → braidio-0.0.84}/braidio/render.py +10 -4
  9. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/__init__.py +53 -10
  10. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_dialogue.py +48 -20
  11. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_ingest.py +21 -10
  12. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_narration.py +84 -41
  13. {braidio-0.0.82 → braidio-0.0.84}/braidio/tts.py +79 -1
  14. {braidio-0.0.82 → braidio-0.0.84}/braidio/weave_config.py +6 -2
  15. {braidio-0.0.82 → braidio-0.0.84}/pyproject.toml +1 -1
  16. {braidio-0.0.82 → braidio-0.0.84}/tests/test_body_schema_stability.py +1 -0
  17. braidio-0.0.84/tests/test_graph_speak.py +251 -0
  18. {braidio-0.0.82 → braidio-0.0.84}/tests/test_transforms.py +88 -2
  19. {braidio-0.0.82 → braidio-0.0.84}/.editorconfig +0 -0
  20. {braidio-0.0.82 → braidio-0.0.84}/.gitattributes +0 -0
  21. {braidio-0.0.82 → braidio-0.0.84}/.gitignore +0 -0
  22. {braidio-0.0.82 → braidio-0.0.84}/LICENSE +0 -0
  23. {braidio-0.0.82 → braidio-0.0.84}/braidio/__init__.py +0 -0
  24. {braidio-0.0.82 → braidio-0.0.84}/braidio/_paths.py +0 -0
  25. {braidio-0.0.82 → braidio-0.0.84}/braidio/bodies/__init__.py +0 -0
  26. {braidio-0.0.82 → braidio-0.0.84}/braidio/bodies/_domain.py +0 -0
  27. {braidio-0.0.82 → braidio-0.0.84}/braidio/bodies/_tiers.py +0 -0
  28. {braidio-0.0.82 → braidio-0.0.84}/braidio/bodies/_video.py +0 -0
  29. {braidio-0.0.82 → braidio-0.0.84}/braidio/captions.py +0 -0
  30. {braidio-0.0.82 → braidio-0.0.84}/braidio/compose.py +0 -0
  31. {braidio-0.0.82 → braidio-0.0.84}/braidio/data/skills/braidio/SKILL.md +0 -0
  32. {braidio-0.0.82 → braidio-0.0.84}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  33. {braidio-0.0.82 → braidio-0.0.84}/braidio/defaults.py +0 -0
  34. {braidio-0.0.82 → braidio-0.0.84}/braidio/delivery.py +0 -0
  35. {braidio-0.0.82 → braidio-0.0.84}/braidio/downloads.py +0 -0
  36. {braidio-0.0.82 → braidio-0.0.84}/braidio/formats.py +0 -0
  37. {braidio-0.0.82 → braidio-0.0.84}/braidio/genre.py +0 -0
  38. {braidio-0.0.82 → braidio-0.0.84}/braidio/importing/__init__.py +0 -0
  39. {braidio-0.0.82 → braidio-0.0.84}/braidio/importing/__main__.py +0 -0
  40. {braidio-0.0.82 → braidio-0.0.84}/braidio/importing/_catalog.py +0 -0
  41. {braidio-0.0.82 → braidio-0.0.84}/braidio/importing/_manifest.py +0 -0
  42. {braidio-0.0.82 → braidio-0.0.84}/braidio/importing/_writer.py +0 -0
  43. {braidio-0.0.82 → braidio-0.0.84}/braidio/kinds.py +0 -0
  44. {braidio-0.0.82 → braidio-0.0.84}/braidio/leveling.py +0 -0
  45. {braidio-0.0.82 → braidio-0.0.84}/braidio/markdown_script.py +0 -0
  46. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/__init__.py +0 -0
  47. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/_docs.py +0 -0
  48. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/_guide.py +0 -0
  49. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/_helpers.py +0 -0
  50. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/_media.py +0 -0
  51. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/credentials.py +0 -0
  52. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/metering.py +0 -0
  53. {braidio-0.0.82 → braidio-0.0.84}/braidio/mcp/workspace.py +0 -0
  54. {braidio-0.0.82 → braidio-0.0.84}/braidio/music.py +0 -0
  55. {braidio-0.0.82 → braidio-0.0.84}/braidio/pacing.py +0 -0
  56. {braidio-0.0.82 → braidio-0.0.84}/braidio/project.py +0 -0
  57. {braidio-0.0.82 → braidio-0.0.84}/braidio/provenance.py +0 -0
  58. {braidio-0.0.82 → braidio-0.0.84}/braidio/relevance.py +0 -0
  59. {braidio-0.0.82 → braidio-0.0.84}/braidio/rights.py +0 -0
  60. {braidio-0.0.82 → braidio-0.0.84}/braidio/script.py +0 -0
  61. {braidio-0.0.82 → braidio-0.0.84}/braidio/sources.py +0 -0
  62. {braidio-0.0.82 → braidio-0.0.84}/braidio/structure.py +0 -0
  63. {braidio-0.0.82 → braidio-0.0.84}/braidio/style.py +0 -0
  64. {braidio-0.0.82 → braidio-0.0.84}/braidio/textprep.py +0 -0
  65. {braidio-0.0.82 → braidio-0.0.84}/braidio/timeline.py +0 -0
  66. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_asset_refs.py +0 -0
  67. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_common.py +0 -0
  68. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_episode.py +0 -0
  69. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_segment.py +0 -0
  70. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_video_cut.py +0 -0
  71. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_video_panels.py +0 -0
  72. {braidio-0.0.82 → braidio-0.0.84}/braidio/transforms/_voice.py +0 -0
  73. {braidio-0.0.82 → braidio-0.0.84}/braidio/video.py +0 -0
  74. {braidio-0.0.82 → braidio-0.0.84}/braidio/voice_library.py +0 -0
  75. {braidio-0.0.82 → braidio-0.0.84}/braidio/weave.py +0 -0
  76. {braidio-0.0.82 → braidio-0.0.84}/conftest.py +0 -0
  77. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/Extraction and nw-App Design.md +0 -0
  78. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  79. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  80. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  81. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/README.md +0 -0
  82. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/anti-platitude-checklist.md +0 -0
  83. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/commentary-voice-guide.md +0 -0
  84. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/_style-groups.md +0 -0
  85. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  86. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/david-sims.md +0 -0
  87. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/griffin-newman.md +0 -0
  88. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/helen-molesworth.md +0 -0
  89. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  90. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  91. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  92. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/jon-caramanica.md +0 -0
  93. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  94. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/karina-longworth.md +0 -0
  95. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/katy-hessel.md +0 -0
  96. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/louis-theroux.md +0 -0
  97. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/mallory-rubin.md +0 -0
  98. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  99. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/michael-barbaro.md +0 -0
  100. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  101. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/paul-scheer.md +0 -0
  102. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/sean-fennessey.md +0 -0
  103. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/talk-art.md +0 -0
  104. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/style/voices/yasi-salek.md +0 -0
  105. {braidio-0.0.82 → braidio-0.0.84}/misc/docs/youtube_ingest_credentials.md +0 -0
  106. {braidio-0.0.82 → braidio-0.0.84}/tests/_audio.py +0 -0
  107. {braidio-0.0.82 → braidio-0.0.84}/tests/test_conversation.py +0 -0
  108. {braidio-0.0.82 → braidio-0.0.84}/tests/test_cost.py +0 -0
  109. {braidio-0.0.82 → braidio-0.0.84}/tests/test_credits_card.py +0 -0
  110. {braidio-0.0.82 → braidio-0.0.84}/tests/test_defaults.py +0 -0
  111. {braidio-0.0.82 → braidio-0.0.84}/tests/test_delivery.py +0 -0
  112. {braidio-0.0.82 → braidio-0.0.84}/tests/test_downloads.py +0 -0
  113. {braidio-0.0.82 → braidio-0.0.84}/tests/test_expressiveness.py +0 -0
  114. {braidio-0.0.82 → braidio-0.0.84}/tests/test_formats.py +0 -0
  115. {braidio-0.0.82 → braidio-0.0.84}/tests/test_genre_placement.py +0 -0
  116. {braidio-0.0.82 → braidio-0.0.84}/tests/test_importing.py +0 -0
  117. {braidio-0.0.82 → braidio-0.0.84}/tests/test_leveling.py +0 -0
  118. {braidio-0.0.82 → braidio-0.0.84}/tests/test_markdown_script.py +0 -0
  119. {braidio-0.0.82 → braidio-0.0.84}/tests/test_mcp.py +0 -0
  120. {braidio-0.0.82 → braidio-0.0.84}/tests/test_mcp_caller_key.py +0 -0
  121. {braidio-0.0.82 → braidio-0.0.84}/tests/test_media_auth.py +0 -0
  122. {braidio-0.0.82 → braidio-0.0.84}/tests/test_multivoice.py +0 -0
  123. {braidio-0.0.82 → braidio-0.0.84}/tests/test_music.py +0 -0
  124. {braidio-0.0.82 → braidio-0.0.84}/tests/test_namespaced_source.py +0 -0
  125. {braidio-0.0.82 → braidio-0.0.84}/tests/test_nw_app.py +0 -0
  126. {braidio-0.0.82 → braidio-0.0.84}/tests/test_pacing.py +0 -0
  127. {braidio-0.0.82 → braidio-0.0.84}/tests/test_packaging.py +0 -0
  128. {braidio-0.0.82 → braidio-0.0.84}/tests/test_render_settings.py +0 -0
  129. {braidio-0.0.82 → braidio-0.0.84}/tests/test_script.py +0 -0
  130. {braidio-0.0.82 → braidio-0.0.84}/tests/test_sources.py +0 -0
  131. {braidio-0.0.82 → braidio-0.0.84}/tests/test_speak_seam.py +0 -0
  132. {braidio-0.0.82 → braidio-0.0.84}/tests/test_structure.py +0 -0
  133. {braidio-0.0.82 → braidio-0.0.84}/tests/test_textprep_style.py +0 -0
  134. {braidio-0.0.82 → braidio-0.0.84}/tests/test_timeline.py +0 -0
  135. {braidio-0.0.82 → braidio-0.0.84}/tests/test_transforms_dialogue.py +0 -0
  136. {braidio-0.0.82 → braidio-0.0.84}/tests/test_transforms_episode_members.py +0 -0
  137. {braidio-0.0.82 → braidio-0.0.84}/tests/test_transforms_rights.py +0 -0
  138. {braidio-0.0.82 → braidio-0.0.84}/tests/test_transforms_secrets.py +0 -0
  139. {braidio-0.0.82 → braidio-0.0.84}/tests/test_transforms_structure.py +0 -0
  140. {braidio-0.0.82 → braidio-0.0.84}/tests/test_tts_api_key.py +0 -0
  141. {braidio-0.0.82 → braidio-0.0.84}/tests/test_turn_overlap.py +0 -0
  142. {braidio-0.0.82 → braidio-0.0.84}/tests/test_video.py +0 -0
  143. {braidio-0.0.82 → braidio-0.0.84}/tests/test_video_bodies.py +0 -0
  144. {braidio-0.0.82 → braidio-0.0.84}/tests/test_video_footage.py +0 -0
  145. {braidio-0.0.82 → braidio-0.0.84}/tests/test_video_transforms.py +0 -0
  146. {braidio-0.0.82 → braidio-0.0.84}/tests/test_voice_library.py +0 -0
  147. {braidio-0.0.82 → braidio-0.0.84}/tests/test_weave.py +0 -0
  148. {braidio-0.0.82 → braidio-0.0.84}/tests/test_weave_config.py +0 -0
  149. {braidio-0.0.82 → braidio-0.0.84}/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.82
3
+ Version: 0.0.84
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
@@ -220,7 +220,18 @@ ElevenLabs is the default, not a requirement. `render_production` and `render_fo
220
220
  render_format(DEEP_DIVE, script, source=None, speak=my_local_tts)
221
221
  ```
222
222
 
223
- `voice` is the id braidio resolved for the line (the format's narrator, the cast's roles), which under the shipped formats is an ElevenLabs id: pass `voice_id=` / `cast=` in your backend's vocabulary, or map ids inside `speak`. Inline `[audio tags]` are stripped before `speak` sees the text, speed and other ElevenLabs settings are ignored, and nothing is cached. The render's settings record names the backend under `resolved.tts`. Only the one-call path takes `speak` today; the graph path (`weave_project`) still synthesizes through ElevenLabs (#132).
223
+ `voice` is the id braidio resolved for the line (the format's narrator, the cast's roles), which under the shipped formats is an ElevenLabs id: pass `voice_id=` / `cast=` in your backend's vocabulary, or map ids inside `speak`. Inline `[audio tags]` are stripped before `speak` sees the text, speed and other ElevenLabs settings are ignored, and nothing is cached. The render's settings record names the backend under `resolved.tts`.
224
+
225
+ The graph path (`weave_project`) cannot persist a callable, so it takes a backend by **name**: register it once, then select it in the config, on either path.
226
+
227
+ ```python
228
+ from braidio.tts import register_tts
229
+
230
+ register_tts("kokoro", my_local_tts, usd_per_1k_chars=0.0) # None: unpriced
231
+ weave_project(project, script, config=WeaveConfig(tts="kokoro"))
232
+ ```
233
+
234
+ The name is recorded in the weave-config and the dialogue cast and folded into the render cache keys, so switching backends re-synthesizes the spoken parts (the free nodes that also read the weave-config re-run too, served from cache), and an ElevenLabs project (no `tts`) keeps its graph and keys byte for byte. An explicit `config=` replaces a format's `weave` entirely, so to keep a format's knobs write `fmt.weave.with_(tts="kokoro")`. The key is the name: register a different name for a different voice, since re-registering one keeps the renders cached under it.
224
235
 
225
236
  ## What it deliberately does *not* do
226
237
 
@@ -151,7 +151,18 @@ ElevenLabs is the default, not a requirement. `render_production` and `render_fo
151
151
  render_format(DEEP_DIVE, script, source=None, speak=my_local_tts)
152
152
  ```
153
153
 
154
- `voice` is the id braidio resolved for the line (the format's narrator, the cast's roles), which under the shipped formats is an ElevenLabs id: pass `voice_id=` / `cast=` in your backend's vocabulary, or map ids inside `speak`. Inline `[audio tags]` are stripped before `speak` sees the text, speed and other ElevenLabs settings are ignored, and nothing is cached. The render's settings record names the backend under `resolved.tts`. Only the one-call path takes `speak` today; the graph path (`weave_project`) still synthesizes through ElevenLabs (#132).
154
+ `voice` is the id braidio resolved for the line (the format's narrator, the cast's roles), which under the shipped formats is an ElevenLabs id: pass `voice_id=` / `cast=` in your backend's vocabulary, or map ids inside `speak`. Inline `[audio tags]` are stripped before `speak` sees the text, speed and other ElevenLabs settings are ignored, and nothing is cached. The render's settings record names the backend under `resolved.tts`.
155
+
156
+ The graph path (`weave_project`) cannot persist a callable, so it takes a backend by **name**: register it once, then select it in the config, on either path.
157
+
158
+ ```python
159
+ from braidio.tts import register_tts
160
+
161
+ register_tts("kokoro", my_local_tts, usd_per_1k_chars=0.0) # None: unpriced
162
+ weave_project(project, script, config=WeaveConfig(tts="kokoro"))
163
+ ```
164
+
165
+ The name is recorded in the weave-config and the dialogue cast and folded into the render cache keys, so switching backends re-synthesizes the spoken parts (the free nodes that also read the weave-config re-run too, served from cache), and an ElevenLabs project (no `tts`) keeps its graph and keys byte for byte. An explicit `config=` replaces a format's `weave` entirely, so to keep a format's knobs write `fmt.weave.with_(tts="kokoro")`. The key is the name: register a different name for a different voice, since re-registering one keeps the renders cached under it.
155
166
 
156
167
  ## What it deliberately does *not* do
157
168
 
@@ -151,6 +151,12 @@ class DialogueCastBodyV1(BaseModel):
151
151
  settings: Optional[dict[str, Any]] = Field(
152
152
  None, description="Model settings passed to Text-to-Dialogue (stability…)."
153
153
  )
154
+ # Additive (default None, and omitted from the stored body when unset, so a
155
+ # project voiced by ElevenLabs keeps the exact cast node it had): the
156
+ # registered voice backend the turns are spoken with (braidio#132).
157
+ tts: Optional[str] = Field(
158
+ None, description="Registered voice backend (braidio.tts); None: ElevenLabs."
159
+ )
154
160
 
155
161
 
156
162
  class SourceMediaBodyV1(BaseModel):
@@ -119,7 +119,7 @@ def render_dialogue(
119
119
  return (out, was_cached) if return_cache_status else out
120
120
 
121
121
 
122
- def _concat_with_gaps(
122
+ def concat_with_gaps(
123
123
  parts: list[Path], out: Path, *, gap_s: float, sample_rate: int = 44100
124
124
  ) -> Path:
125
125
  """Concatenate audio parts with ``gap_s`` seconds of silence between them."""
@@ -130,7 +130,8 @@ def _concat_with_gaps(
130
130
  if gap_s <= 0:
131
131
  concatenate_audio(*[str(p) for p in parts], output=str(out), crossfade=0.0)
132
132
  return out
133
- sil = out.parent / "_gap.mp3"
133
+ # beside its output, named for it: two renders in one folder never share it
134
+ sil = out.with_name(f".{out.stem}-gap.mp3")
134
135
  subprocess.run(
135
136
  [
136
137
  "ffmpeg",
@@ -151,7 +152,10 @@ def _concat_with_gaps(
151
152
  if i:
152
153
  interleaved.append(str(sil))
153
154
  interleaved.append(str(p))
154
- concatenate_audio(*interleaved, output=str(out), crossfade=0.0)
155
+ try:
156
+ concatenate_audio(*interleaved, output=str(out), crossfade=0.0)
157
+ finally:
158
+ sil.unlink(missing_ok=True)
155
159
  return out
156
160
 
157
161
 
@@ -190,4 +194,4 @@ def render_turns_sequential(
190
194
  )
191
195
  parts.append(raw)
192
196
  out = Path(out_path)
193
- return _concat_with_gaps(parts, out, gap_s=gap_s)
197
+ return concat_with_gaps(parts, out, gap_s=gap_s)
@@ -116,6 +116,31 @@ def tts_cost_usd(
116
116
  return round(chars / 1000 * rate, 6)
117
117
 
118
118
 
119
+ def backend_cost_usd(
120
+ text: Optional[str], *, tts: Optional[str], model_id: Optional[str] = None
121
+ ) -> Optional[float]:
122
+ """Estimated USD for ``text`` on the voice backend that speaks it.
123
+
124
+ ``tts=None`` is ElevenLabs (:func:`tts_cost_usd`); a registered backend
125
+ (:func:`braidio.tts.register_tts`) prices at its own rate. A name that is
126
+ not registered (a runner serving cached renders need not register it)
127
+ is unpriced, ``None``, never an error and never ``0.0``.
128
+
129
+ >>> backend_cost_usd("", tts="anything")
130
+ 0.0
131
+ >>> backend_cost_usd("hi", tts="not-registered") is None
132
+ True
133
+ """
134
+ from braidio.tts import TTS_BACKENDS
135
+
136
+ if not tts:
137
+ return tts_cost_usd(text, model_id=model_id)
138
+ if billable_chars(text) == 0:
139
+ return 0.0
140
+ backend = TTS_BACKENDS.get(tts)
141
+ return None if backend is None else backend.cost_usd(text or "")
142
+
143
+
119
144
  @dataclass(frozen=True)
120
145
  class CostLine:
121
146
  """One billable line of an estimate (a narration beat or a dialogue beat).
@@ -450,7 +450,7 @@ def save_script(
450
450
  ingested = braidio.transforms.ingest_script(
451
451
  proj,
452
452
  scr,
453
- config=braidio.transforms.format_config(fmt),
453
+ config=braidio.transforms.resolve_config(proj, fmt),
454
454
  source=src,
455
455
  structure=structure,
456
456
  bed=bed,
@@ -18,12 +18,12 @@ from __future__ import annotations
18
18
 
19
19
  import random
20
20
  import re
21
- import subprocess
22
21
  from dataclasses import dataclass
23
22
  from pathlib import Path
24
23
 
25
24
  from mixing import concatenate_audio
26
25
 
26
+ from braidio.conversation import concat_with_gaps
27
27
  from braidio.leveling import DEFAULT_TARGET_LUFS, level_part
28
28
  from braidio.tts import narrate
29
29
 
@@ -180,43 +180,9 @@ def render_multivoice(
180
180
  out = Path(out_path)
181
181
  out.parent.mkdir(parents=True, exist_ok=True)
182
182
  if gap_s > 0:
183
- _concat_with_gaps(parts, out, gap_s=gap_s)
183
+ concat_with_gaps(parts, out, gap_s=gap_s)
184
184
  else:
185
185
  concatenate_audio(
186
186
  *[str(p) for p in parts], output=str(out), crossfade=crossfade_s
187
187
  )
188
188
  return list(zip(voices, turns))
189
-
190
-
191
- def _concat_with_gaps(parts: list[Path], out: Path, *, gap_s: float) -> Path:
192
- """Concatenate audio parts with ``gap_s`` seconds of silence between them."""
193
- from mixing import Audio # local import; audio object model
194
-
195
- silence = None
196
- pieces: list[str] = []
197
- for p in parts:
198
- pieces.append(str(p))
199
- # Build via ffmpeg: create a silence file and interleave.
200
- sil = out.parent / "_gap.mp3"
201
- subprocess.run(
202
- [
203
- "ffmpeg",
204
- "-y",
205
- "-f",
206
- "lavfi",
207
- "-i",
208
- f"anullsrc=r=44100:cl=stereo",
209
- "-t",
210
- f"{gap_s:.3f}",
211
- str(sil),
212
- ],
213
- check=True,
214
- capture_output=True,
215
- )
216
- interleaved: list[str] = []
217
- for i, p in enumerate(pieces):
218
- if i:
219
- interleaved.append(str(sil))
220
- interleaved.append(p)
221
- concatenate_audio(*interleaved, output=str(out), crossfade=0.0)
222
- return out
@@ -42,7 +42,7 @@ from braidio.leveling import DEFAULT_TARGET_LUFS, level_part
42
42
  from braidio.script import Script
43
43
  from braidio.sources import SegmentSource
44
44
  from braidio.structure import DEFAULT_STRUCTURE, prepare_pause, prepare_sting
45
- from braidio.tts import Speak, narrate, narrator_from_speak, tts_name
45
+ from braidio.tts import Speak, narrate, narrator_from_speak, tts_backend, tts_name
46
46
  from braidio.weave import TimelineItem, extract_padded, weave_timeline
47
47
  from braidio.weave_config import WeaveConfig, speaker_key
48
48
 
@@ -289,9 +289,15 @@ def render_production(
289
289
  Text-to-Dialogue path). Formats, pacing and weaving are unchanged. It is
290
290
  handed the voice ids this render resolves (the format's, the cast's), so
291
291
  pass ``voice_id=`` / ``cast=`` in its vocabulary, or map them inside it.
292
- ``None`` (default) is the ElevenLabs path, exactly as before.
292
+ ``None`` (default) is the ElevenLabs path, exactly as before, unless
293
+ ``config.tts`` names a registered backend (:func:`braidio.tts.register_tts`),
294
+ which is how the graph path selects one too; an explicit ``speak`` wins.
293
295
  """
294
- # the voice backend: ElevenLabs unless the caller supplied another one
296
+ # the voice backend: an explicit `speak`, else the config's registered one,
297
+ # else ElevenLabs
298
+ backend_name = None
299
+ if speak is None and config is not None and config.tts:
300
+ backend_name, speak = config.tts, tts_backend(config.tts).speak
295
301
  synthesize = narrate if speak is None else narrator_from_speak(speak)
296
302
  publishable = rights.publishable_clip_rights if rights else PUBLISHABLE_CLIP_RIGHTS
297
303
  plan = plan_production(script, profile, publishable_clip_rights=publishable)
@@ -545,7 +551,7 @@ def render_production(
545
551
  delivery=delivery,
546
552
  profile=profile,
547
553
  normalize=normalize,
548
- tts=tts_name(speak),
554
+ tts=backend_name or tts_name(speak),
549
555
  ),
550
556
  )
551
557
  return out, tl
@@ -91,6 +91,7 @@ video_cut_reuses_existing = _video_cut.reuses_existing_cut
91
91
 
92
92
  __all__ = [
93
93
  "format_config",
94
+ "resolve_config",
94
95
  "ingest_script",
95
96
  "IngestedScript",
96
97
  "weave_project",
@@ -122,16 +123,27 @@ __all__ = [
122
123
  ]
123
124
 
124
125
 
126
+ #: What a narration render was synthesized with: the config keys a re-weave
127
+ #: must keep, or every one of those renders re-synthesizes (and re-bills).
128
+ VOICE_KEYS = ("model_id", "voice_settings")
129
+
130
+
125
131
  def format_config(fmt=None, *, config=None, voice_id=None):
126
- """The weave-config a production records: one rule for every writer.
132
+ """The weave-config a production asks for: one rule for every writer.
127
133
 
128
134
  ``config`` else the format's ``weave``, carrying the narration voice —
129
- ``voice_id`` else ``fmt.narration_voice`` — when there is one. ``weave_project``
130
- and ``save_script`` both resolve through here, so saving and then weaving a
131
- format never rewrites the config node (and so never re-stales its renders).
135
+ ``voice_id`` else ``fmt.narration_voice`` — when there is one. A format's
136
+ ``weave`` holds the editing knobs and its ``narration_delivery`` what the
137
+ narrator speaks with, so the format's config takes the delivery's model and
138
+ settings: what the fast path renders with (braidio#120). An explicit
139
+ ``config`` is used as given. Pure: :func:`resolve_config` is what applies
140
+ it to a project.
132
141
  """
133
142
  if config is None and fmt is not None:
134
- config = fmt.weave
143
+ delivery = fmt.narration_delivery
144
+ config = fmt.weave.with_(
145
+ model_id=delivery.model_id, voice_settings=dict(delivery.voice_settings)
146
+ )
135
147
  if voice_id is None and fmt is not None:
136
148
  voice_id = fmt.narration_voice
137
149
  if voice_id is not None:
@@ -139,6 +151,33 @@ def format_config(fmt=None, *, config=None, voice_id=None):
139
151
  return config
140
152
 
141
153
 
154
+ def resolve_config(project, fmt=None, *, config=None, voice_id=None):
155
+ """The weave-config to ingest into ``project``: :func:`format_config`, minus
156
+ any change to what its narration was already synthesized with.
157
+
158
+ Once a project has narration renders, a re-weave keeps the model and
159
+ settings (:data:`VOICE_KEYS`) its weave-config records, with or without a
160
+ format, unless the caller passes ``config=`` explicitly: changing them
161
+ would re-synthesize, and re-bill, every narration beat (braidio#135,
162
+ option 2). So the model and settings are fixed by a project's first
163
+ render; ``config=`` is how to change them. Before any render (a script
164
+ saved, not yet woven) there is nothing to re-bill, and the format's
165
+ delivery applies. ``weave_project`` and ``save_script`` both resolve
166
+ through here, so saving and then weaving never rewrites the config node.
167
+ """
168
+ import nw
169
+
170
+ resolved = format_config(fmt, config=config, voice_id=voice_id)
171
+ if config is not None or not nw.annotations_at_tier(
172
+ project.root, "narration-renders"
173
+ ):
174
+ return resolved
175
+ nodes = nw.annotations_at_tier(project.root, "weave-configs")
176
+ recorded = dict(nodes[0].body.get("config", {})) if nodes else {}
177
+ kept = {key: recorded[key] for key in VOICE_KEYS if key in recorded}
178
+ return (resolved or WeaveConfig()).with_(**kept)
179
+
180
+
142
181
  def weave_project(
143
182
  project,
144
183
  script,
@@ -168,10 +207,14 @@ def weave_project(
168
207
  ``fmt`` (a :class:`~braidio.formats.Format`) supplies the format's declared
169
208
  defaults — its ``weave`` config, its ``structure`` and its dialogue
170
209
  ``cast`` — for whichever of ``config`` / ``structure`` / ``cast`` the
171
- caller left out; an explicit argument always wins. ``bed`` is the
172
- app-supplied music bed (:class:`~braidio.music.MusicBed`). With no format,
173
- no structure and no bed, this is the plain weave it always was
174
- (thorwhalen/braidio#39).
210
+ caller left out; an explicit argument always wins. Its config carries the
211
+ format's ``narration_delivery`` model and settings, as the fast path renders
212
+ them, until the project has narration renders: from then on a re-weave
213
+ keeps the model and settings it was synthesized with, so it never re-bills
214
+ by surprise, and ``config=`` is how to change them (:func:`resolve_config`,
215
+ braidio#120). ``bed`` is the app-supplied music bed
216
+ (:class:`~braidio.music.MusicBed`). With no format, no structure and no
217
+ bed, this is the plain weave it always was (thorwhalen/braidio#39).
175
218
 
176
219
  ``cast`` (a :class:`~braidio.conversation.ConversationCast`) is what the
177
220
  script's :class:`~braidio.script.Dialogue` beats are voiced with, resolved
@@ -218,7 +261,7 @@ def weave_project(
218
261
  """
219
262
  import nw
220
263
 
221
- config = format_config(fmt, config=config, voice_id=voice_id)
264
+ config = resolve_config(project, fmt, config=config, voice_id=voice_id)
222
265
  if fmt is not None:
223
266
  structure = structure if structure is not None else fmt.structure
224
267
  cast = cast if cast is not None else fmt.cast
@@ -32,6 +32,7 @@ A caller's ElevenLabs key reaches the synthesis exactly as it does in
32
32
  from __future__ import annotations
33
33
 
34
34
  import json
35
+ import shutil
35
36
  import uuid
36
37
 
37
38
  from falaw import Plan
@@ -46,7 +47,8 @@ from braidio.bodies._render_nodes import (
46
47
  DialogueRenderBodyV1,
47
48
  )
48
49
  from braidio.conversation import ConversationCast
49
- from braidio.cost import tts_cost_usd
50
+ from braidio.cost import backend_cost_usd
51
+ from braidio.tts import narrator_from_speak, tts_backend
50
52
  from braidio.transforms._common import (
51
53
  TIER_DIALOGUE_BEAT,
52
54
  TIER_DIALOGUE_CAST,
@@ -88,24 +90,30 @@ def _billable_text(turns) -> str:
88
90
  return "".join(text for _role, text in turns)
89
91
 
90
92
 
91
- def _dialogue_cache_key(transform, turns, cast: ConversationCast) -> str:
93
+ def _dialogue_cache_key(
94
+ transform, turns, cast: ConversationCast, *, tts: str | None = None
95
+ ) -> str:
92
96
  """The output identity for one dialogue take — nw's shared derivation.
93
97
 
94
98
  Hashes everything that reaches the audio: the turns (role + text, in
95
99
  order), the role → voice map, the model and its settings. Same
96
100
  ``nw.transforms.cache_key`` as the narration and extraction transforms,
97
- with a ``"dialogue"`` tag so the three can never collide (nw#54).
101
+ with a ``"dialogue"`` tag so the three can never collide (nw#54). A
102
+ registered voice backend ``tts`` (braidio#132) is folded in only when set,
103
+ so an ElevenLabs project keeps its keys.
98
104
  """
99
105
  from nw.transforms import cache_key as transform_cache_key
100
106
 
101
- return transform_cache_key(
102
- transform,
107
+ parts = [
103
108
  "dialogue",
104
109
  json.dumps(list(turns), ensure_ascii=False),
105
110
  json.dumps(dict(cast.roles), sort_keys=True),
106
111
  cast.model_id,
107
112
  json.dumps(cast.settings or {}, sort_keys=True),
108
- )
113
+ ]
114
+ if tts:
115
+ parts.append(f"tts={tts}")
116
+ return transform_cache_key(transform, *parts)
109
117
 
110
118
 
111
119
  @register_transform(NAME)
@@ -121,7 +129,9 @@ class DialogueRenderTTS(BaseTransform):
121
129
  ) -> tuple[Plan, tuple[Annotation, ...]]:
122
130
  beat = inputs.primary[0]
123
131
  cast_node = singleton(project, TIER_DIALOGUE_CAST)
124
- cache_key = _dialogue_cache_key(self, _turns(beat), _cast(cast_node))
132
+ cache_key = _dialogue_cache_key(
133
+ self, _turns(beat), _cast(cast_node), tts=cast_node.body.get("tts")
134
+ )
125
135
 
126
136
  full = TransformInputs(
127
137
  primary=(beat,), context={DIALOGUE_CAST_V1: (cast_node,)}
@@ -152,11 +162,13 @@ class DialogueRenderTTS(BaseTransform):
152
162
  cache_key = skel.body["cache_key"]
153
163
  parents = resolve_parents(skel, graph_index(project))
154
164
  beat = require_tier(parents, TIER_DIALOGUE_BEAT)
155
- cast = _cast(require_tier(parents, TIER_DIALOGUE_CAST))
165
+ cast_node = require_tier(parents, TIER_DIALOGUE_CAST)
166
+ cast, tts = _cast(cast_node), cast_node.body.get("tts")
156
167
  turns = _turns(beat)
157
168
  # ElevenLabs bills per character of the submitted turns — the only real
158
- # spend here. A rate ESTIMATE (== live-call spend; see braidio#8).
159
- cost = tts_cost_usd(_billable_text(turns), model_id=cast.model_id)
169
+ # spend here. A rate ESTIMATE (== live-call spend; see braidio#8). A
170
+ # registered backend reports its own rate, or none (unpriced).
171
+ cost = backend_cost_usd(_billable_text(turns), tts=tts, model_id=cast.model_id)
160
172
 
161
173
  if use_cache and not force:
162
174
  # Same two-step as narration_render: the fresh equivalent node if
@@ -184,16 +196,32 @@ class DialogueRenderTTS(BaseTransform):
184
196
  out_path.parent.mkdir(parents=True, exist_ok=True)
185
197
  # was_cached: the take came from the on-disk dialogue cache (no
186
198
  # ElevenLabs call = $0 real spend) even though our graph cache missed.
187
- _, was_cached = braidio.render_dialogue(
188
- turns,
189
- cast,
190
- # The caller's key, if the driver handed one in (nw's `secrets=`
191
- # seam; thorwhalen/braidio#58) — else None, the process env. Never
192
- # persisted: not in the node, not in the cache_key.
193
- api_key=elevenlabs_key(secrets),
194
- out_path=out_path,
195
- return_cache_status=True,
196
- )
199
+ if tts:
200
+ # another backend has no one-pass dialogue: turn by turn, never
201
+ # cached (the fast path's fallback, braidio#123)
202
+ work = out_path.with_suffix("")
203
+ try:
204
+ braidio.render_turns_sequential(
205
+ turns,
206
+ cast,
207
+ out_path=out_path,
208
+ work_dir=work,
209
+ narrate_fn=narrator_from_speak(tts_backend(tts).speak),
210
+ )
211
+ finally:
212
+ shutil.rmtree(work, ignore_errors=True)
213
+ was_cached = False
214
+ else:
215
+ _, was_cached = braidio.render_dialogue(
216
+ turns,
217
+ cast,
218
+ # The caller's key, if the driver handed one in (nw's `secrets=`
219
+ # seam; thorwhalen/braidio#58) — else None, the process env.
220
+ # Never persisted: not in the node, not in the cache_key.
221
+ api_key=elevenlabs_key(secrets),
222
+ out_path=out_path,
223
+ return_cache_status=True,
224
+ )
197
225
  duration = safe_duration(out_path)
198
226
  artifact = audio_artifact(
199
227
  out_path,
@@ -67,6 +67,7 @@ from braidio.rights import (
67
67
  plan_production,
68
68
  )
69
69
  from braidio.script import Script, SegmentBeat
70
+ from braidio.tts import tts_backend
70
71
  from braidio.weave_config import WeaveConfig
71
72
  from braidio.bodies._domain import (
72
73
  NARRATIVE_BEAT_V1,
@@ -233,6 +234,8 @@ def ingest_script(
233
234
  and a retry after any failure converges (see the module docstring).
234
235
  """
235
236
  config = config or WeaveConfig()
237
+ if config.tts: # an unregistered voice backend fails here, before any write
238
+ tts_backend(config.tts)
236
239
  publishable = rights.publishable_clip_rights if rights else PUBLISHABLE_CLIP_RIGHTS
237
240
  plan = plan_production(
238
241
  script,
@@ -305,7 +308,7 @@ def _plan_nodes(
305
308
  profile_node = _profile_node(profile=profile, publishable=publishable, plan=plan)
306
309
  if profile_node is not None:
307
310
  nodes.append(profile_node)
308
- cast_node = _cast_node(cast=cast, plan=plan)
311
+ cast_node = _cast_node(cast=cast, plan=plan, tts=config.tts)
309
312
  if cast_node is not None:
310
313
  nodes.append(cast_node)
311
314
 
@@ -408,7 +411,9 @@ def _profile_node(
408
411
  )
409
412
 
410
413
 
411
- def _cast_node(*, cast: ConversationCast, plan: RenderPlan) -> _AuthoringNode | None:
414
+ def _cast_node(
415
+ *, cast: ConversationCast, plan: RenderPlan, tts: str | None = None
416
+ ) -> _AuthoringNode | None:
412
417
  """The singleton ``dialogue-cast/v1`` node, or ``None``.
413
418
 
414
419
  Written iff the plan has a dialogue beat: the cast is the decision of what
@@ -416,20 +421,26 @@ def _cast_node(*, cast: ConversationCast, plan: RenderPlan) -> _AuthoringNode |
416
421
  a script without dialogue keeps the graph it had before this node existed,
417
422
  whatever cast the caller or format supplied. With dialogue it is always
418
423
  written, default cast included, because the dialogue renders must derive
419
- from the voices they actually used (thorwhalen/braidio#46).
424
+ from the voices they actually used (thorwhalen/braidio#46). ``tts`` (the
425
+ config's registered voice backend, braidio#132) is recorded only when set,
426
+ so an ElevenLabs production keeps the exact body it had.
420
427
  """
421
428
  if not any(b.kind == "dialogue" for b in plan.beats):
422
429
  return None
430
+ body = _json(
431
+ DialogueCastBodyV1(
432
+ roles=dict(cast.roles),
433
+ model_id=cast.model_id,
434
+ settings=dict(cast.settings) if cast.settings is not None else None,
435
+ tts=tts,
436
+ )
437
+ )
438
+ if body["tts"] is None: # the absence rule
439
+ del body["tts"]
423
440
  return _AuthoringNode(
424
441
  tier=TIER_DIALOGUE_CAST,
425
442
  identity=TIER_DIALOGUE_CAST,
426
- body=_json(
427
- DialogueCastBodyV1(
428
- roles=dict(cast.roles),
429
- model_id=cast.model_id,
430
- settings=dict(cast.settings) if cast.settings is not None else None,
431
- )
432
- ),
443
+ body=body,
433
444
  body_schema_uri=DIALOGUE_CAST_V1,
434
445
  )
435
446