braidio 0.0.82__tar.gz → 0.0.83__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.83}/PKG-INFO +13 -2
  2. {braidio-0.0.82 → braidio-0.0.83}/README.md +12 -1
  3. {braidio-0.0.82 → braidio-0.0.83}/braidio/bodies/_render_nodes.py +6 -0
  4. {braidio-0.0.82 → braidio-0.0.83}/braidio/conversation.py +8 -4
  5. {braidio-0.0.82 → braidio-0.0.83}/braidio/cost.py +25 -0
  6. {braidio-0.0.82 → braidio-0.0.83}/braidio/multivoice.py +2 -36
  7. {braidio-0.0.82 → braidio-0.0.83}/braidio/render.py +10 -4
  8. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_dialogue.py +48 -20
  9. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_ingest.py +21 -10
  10. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_narration.py +84 -41
  11. {braidio-0.0.82 → braidio-0.0.83}/braidio/tts.py +79 -1
  12. {braidio-0.0.82 → braidio-0.0.83}/braidio/weave_config.py +6 -2
  13. {braidio-0.0.82 → braidio-0.0.83}/pyproject.toml +1 -1
  14. {braidio-0.0.82 → braidio-0.0.83}/tests/test_body_schema_stability.py +1 -0
  15. braidio-0.0.83/tests/test_graph_speak.py +251 -0
  16. {braidio-0.0.82 → braidio-0.0.83}/.editorconfig +0 -0
  17. {braidio-0.0.82 → braidio-0.0.83}/.gitattributes +0 -0
  18. {braidio-0.0.82 → braidio-0.0.83}/.gitignore +0 -0
  19. {braidio-0.0.82 → braidio-0.0.83}/LICENSE +0 -0
  20. {braidio-0.0.82 → braidio-0.0.83}/braidio/__init__.py +0 -0
  21. {braidio-0.0.82 → braidio-0.0.83}/braidio/_paths.py +0 -0
  22. {braidio-0.0.82 → braidio-0.0.83}/braidio/bodies/__init__.py +0 -0
  23. {braidio-0.0.82 → braidio-0.0.83}/braidio/bodies/_domain.py +0 -0
  24. {braidio-0.0.82 → braidio-0.0.83}/braidio/bodies/_tiers.py +0 -0
  25. {braidio-0.0.82 → braidio-0.0.83}/braidio/bodies/_video.py +0 -0
  26. {braidio-0.0.82 → braidio-0.0.83}/braidio/captions.py +0 -0
  27. {braidio-0.0.82 → braidio-0.0.83}/braidio/compose.py +0 -0
  28. {braidio-0.0.82 → braidio-0.0.83}/braidio/data/skills/braidio/SKILL.md +0 -0
  29. {braidio-0.0.82 → braidio-0.0.83}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  30. {braidio-0.0.82 → braidio-0.0.83}/braidio/defaults.py +0 -0
  31. {braidio-0.0.82 → braidio-0.0.83}/braidio/delivery.py +0 -0
  32. {braidio-0.0.82 → braidio-0.0.83}/braidio/downloads.py +0 -0
  33. {braidio-0.0.82 → braidio-0.0.83}/braidio/formats.py +0 -0
  34. {braidio-0.0.82 → braidio-0.0.83}/braidio/genre.py +0 -0
  35. {braidio-0.0.82 → braidio-0.0.83}/braidio/importing/__init__.py +0 -0
  36. {braidio-0.0.82 → braidio-0.0.83}/braidio/importing/__main__.py +0 -0
  37. {braidio-0.0.82 → braidio-0.0.83}/braidio/importing/_catalog.py +0 -0
  38. {braidio-0.0.82 → braidio-0.0.83}/braidio/importing/_manifest.py +0 -0
  39. {braidio-0.0.82 → braidio-0.0.83}/braidio/importing/_writer.py +0 -0
  40. {braidio-0.0.82 → braidio-0.0.83}/braidio/kinds.py +0 -0
  41. {braidio-0.0.82 → braidio-0.0.83}/braidio/leveling.py +0 -0
  42. {braidio-0.0.82 → braidio-0.0.83}/braidio/markdown_script.py +0 -0
  43. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/__init__.py +0 -0
  44. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/_docs.py +0 -0
  45. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/_guide.py +0 -0
  46. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/_helpers.py +0 -0
  47. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/_media.py +0 -0
  48. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/credentials.py +0 -0
  49. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/metering.py +0 -0
  50. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/tools.py +0 -0
  51. {braidio-0.0.82 → braidio-0.0.83}/braidio/mcp/workspace.py +0 -0
  52. {braidio-0.0.82 → braidio-0.0.83}/braidio/music.py +0 -0
  53. {braidio-0.0.82 → braidio-0.0.83}/braidio/pacing.py +0 -0
  54. {braidio-0.0.82 → braidio-0.0.83}/braidio/project.py +0 -0
  55. {braidio-0.0.82 → braidio-0.0.83}/braidio/provenance.py +0 -0
  56. {braidio-0.0.82 → braidio-0.0.83}/braidio/relevance.py +0 -0
  57. {braidio-0.0.82 → braidio-0.0.83}/braidio/rights.py +0 -0
  58. {braidio-0.0.82 → braidio-0.0.83}/braidio/script.py +0 -0
  59. {braidio-0.0.82 → braidio-0.0.83}/braidio/sources.py +0 -0
  60. {braidio-0.0.82 → braidio-0.0.83}/braidio/structure.py +0 -0
  61. {braidio-0.0.82 → braidio-0.0.83}/braidio/style.py +0 -0
  62. {braidio-0.0.82 → braidio-0.0.83}/braidio/textprep.py +0 -0
  63. {braidio-0.0.82 → braidio-0.0.83}/braidio/timeline.py +0 -0
  64. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/__init__.py +0 -0
  65. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_asset_refs.py +0 -0
  66. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_common.py +0 -0
  67. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_episode.py +0 -0
  68. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_segment.py +0 -0
  69. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_video_cut.py +0 -0
  70. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_video_panels.py +0 -0
  71. {braidio-0.0.82 → braidio-0.0.83}/braidio/transforms/_voice.py +0 -0
  72. {braidio-0.0.82 → braidio-0.0.83}/braidio/video.py +0 -0
  73. {braidio-0.0.82 → braidio-0.0.83}/braidio/voice_library.py +0 -0
  74. {braidio-0.0.82 → braidio-0.0.83}/braidio/weave.py +0 -0
  75. {braidio-0.0.82 → braidio-0.0.83}/conftest.py +0 -0
  76. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/Extraction and nw-App Design.md +0 -0
  77. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  78. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  79. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  80. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/README.md +0 -0
  81. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/anti-platitude-checklist.md +0 -0
  82. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/commentary-voice-guide.md +0 -0
  83. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/_style-groups.md +0 -0
  84. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  85. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/david-sims.md +0 -0
  86. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/griffin-newman.md +0 -0
  87. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/helen-molesworth.md +0 -0
  88. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  89. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  90. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  91. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/jon-caramanica.md +0 -0
  92. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  93. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/karina-longworth.md +0 -0
  94. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/katy-hessel.md +0 -0
  95. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/louis-theroux.md +0 -0
  96. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/mallory-rubin.md +0 -0
  97. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  98. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/michael-barbaro.md +0 -0
  99. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  100. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/paul-scheer.md +0 -0
  101. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/sean-fennessey.md +0 -0
  102. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/talk-art.md +0 -0
  103. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/style/voices/yasi-salek.md +0 -0
  104. {braidio-0.0.82 → braidio-0.0.83}/misc/docs/youtube_ingest_credentials.md +0 -0
  105. {braidio-0.0.82 → braidio-0.0.83}/tests/_audio.py +0 -0
  106. {braidio-0.0.82 → braidio-0.0.83}/tests/test_conversation.py +0 -0
  107. {braidio-0.0.82 → braidio-0.0.83}/tests/test_cost.py +0 -0
  108. {braidio-0.0.82 → braidio-0.0.83}/tests/test_credits_card.py +0 -0
  109. {braidio-0.0.82 → braidio-0.0.83}/tests/test_defaults.py +0 -0
  110. {braidio-0.0.82 → braidio-0.0.83}/tests/test_delivery.py +0 -0
  111. {braidio-0.0.82 → braidio-0.0.83}/tests/test_downloads.py +0 -0
  112. {braidio-0.0.82 → braidio-0.0.83}/tests/test_expressiveness.py +0 -0
  113. {braidio-0.0.82 → braidio-0.0.83}/tests/test_formats.py +0 -0
  114. {braidio-0.0.82 → braidio-0.0.83}/tests/test_genre_placement.py +0 -0
  115. {braidio-0.0.82 → braidio-0.0.83}/tests/test_importing.py +0 -0
  116. {braidio-0.0.82 → braidio-0.0.83}/tests/test_leveling.py +0 -0
  117. {braidio-0.0.82 → braidio-0.0.83}/tests/test_markdown_script.py +0 -0
  118. {braidio-0.0.82 → braidio-0.0.83}/tests/test_mcp.py +0 -0
  119. {braidio-0.0.82 → braidio-0.0.83}/tests/test_mcp_caller_key.py +0 -0
  120. {braidio-0.0.82 → braidio-0.0.83}/tests/test_media_auth.py +0 -0
  121. {braidio-0.0.82 → braidio-0.0.83}/tests/test_multivoice.py +0 -0
  122. {braidio-0.0.82 → braidio-0.0.83}/tests/test_music.py +0 -0
  123. {braidio-0.0.82 → braidio-0.0.83}/tests/test_namespaced_source.py +0 -0
  124. {braidio-0.0.82 → braidio-0.0.83}/tests/test_nw_app.py +0 -0
  125. {braidio-0.0.82 → braidio-0.0.83}/tests/test_pacing.py +0 -0
  126. {braidio-0.0.82 → braidio-0.0.83}/tests/test_packaging.py +0 -0
  127. {braidio-0.0.82 → braidio-0.0.83}/tests/test_render_settings.py +0 -0
  128. {braidio-0.0.82 → braidio-0.0.83}/tests/test_script.py +0 -0
  129. {braidio-0.0.82 → braidio-0.0.83}/tests/test_sources.py +0 -0
  130. {braidio-0.0.82 → braidio-0.0.83}/tests/test_speak_seam.py +0 -0
  131. {braidio-0.0.82 → braidio-0.0.83}/tests/test_structure.py +0 -0
  132. {braidio-0.0.82 → braidio-0.0.83}/tests/test_textprep_style.py +0 -0
  133. {braidio-0.0.82 → braidio-0.0.83}/tests/test_timeline.py +0 -0
  134. {braidio-0.0.82 → braidio-0.0.83}/tests/test_transforms.py +0 -0
  135. {braidio-0.0.82 → braidio-0.0.83}/tests/test_transforms_dialogue.py +0 -0
  136. {braidio-0.0.82 → braidio-0.0.83}/tests/test_transforms_episode_members.py +0 -0
  137. {braidio-0.0.82 → braidio-0.0.83}/tests/test_transforms_rights.py +0 -0
  138. {braidio-0.0.82 → braidio-0.0.83}/tests/test_transforms_secrets.py +0 -0
  139. {braidio-0.0.82 → braidio-0.0.83}/tests/test_transforms_structure.py +0 -0
  140. {braidio-0.0.82 → braidio-0.0.83}/tests/test_tts_api_key.py +0 -0
  141. {braidio-0.0.82 → braidio-0.0.83}/tests/test_turn_overlap.py +0 -0
  142. {braidio-0.0.82 → braidio-0.0.83}/tests/test_video.py +0 -0
  143. {braidio-0.0.82 → braidio-0.0.83}/tests/test_video_bodies.py +0 -0
  144. {braidio-0.0.82 → braidio-0.0.83}/tests/test_video_footage.py +0 -0
  145. {braidio-0.0.82 → braidio-0.0.83}/tests/test_video_transforms.py +0 -0
  146. {braidio-0.0.82 → braidio-0.0.83}/tests/test_voice_library.py +0 -0
  147. {braidio-0.0.82 → braidio-0.0.83}/tests/test_weave.py +0 -0
  148. {braidio-0.0.82 → braidio-0.0.83}/tests/test_weave_config.py +0 -0
  149. {braidio-0.0.82 → braidio-0.0.83}/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.83
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).
@@ -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
@@ -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
 
@@ -38,10 +38,15 @@ from braidio.bodies._render_nodes import (
38
38
  NARRATION_RENDER_V1,
39
39
  NarrationRenderBodyV1,
40
40
  )
41
- from braidio.cost import tts_cost_usd
41
+ from braidio.cost import backend_cost_usd
42
42
  from braidio.delivery import model_supports_speed
43
43
  from braidio.render import narrate_turns, plan_beat_turns
44
- from braidio.tts import DEFAULT_MODEL_ID, DEFAULT_VOICE_ID
44
+ from braidio.tts import (
45
+ DEFAULT_MODEL_ID,
46
+ DEFAULT_VOICE_ID,
47
+ narrator_from_speak,
48
+ tts_backend,
49
+ )
45
50
  from braidio.weave_config import WeaveConfig
46
51
  from braidio.transforms._common import (
47
52
  TIER_NARRATIVE_BEAT,
@@ -67,7 +72,7 @@ NAME = "narration_render.tts"
67
72
 
68
73
 
69
74
  def _narration_cache_key(
70
- transform, text: str, voice_id: str, model_id: str, settings, turns=()
75
+ transform, text: str, voice_id: str, model_id: str, settings, turns=(), *, tts=None
71
76
  ) -> str:
72
77
  """The output identity for one TTS render — nw's shared derivation.
73
78
 
@@ -80,7 +85,9 @@ def _narration_cache_key(
80
85
 
81
86
  ``turns`` is the paced plan (:func:`_beat_turns`): what is synthesized when
82
87
  the config paces narration. Unpaced, it is empty and adds nothing, so an
83
- unpaced project keeps its keys.
88
+ unpaced project keeps its keys. ``tts`` (a registered backend name,
89
+ braidio#132) is folded in only when set, by the same rule: an ElevenLabs
90
+ project keeps its keys, and switching backends changes every one.
84
91
  """
85
92
  from nw.transforms import cache_key as transform_cache_key
86
93
 
@@ -93,9 +100,63 @@ def _narration_cache_key(
93
100
  ]
94
101
  if turns:
95
102
  parts.append(json.dumps([asdict(t) for t in turns], sort_keys=True))
103
+ if tts:
104
+ parts.append(f"tts={tts}")
96
105
  return transform_cache_key(transform, *parts)
97
106
 
98
107
 
108
+ def _speak_beat(
109
+ text: str,
110
+ out_path: Path,
111
+ *,
112
+ tts: str | None,
113
+ turns,
114
+ api_key,
115
+ voice_id: str,
116
+ model_id: str,
117
+ settings,
118
+ ) -> tuple[Path, bool]:
119
+ """Synthesize one beat → ``(audio path, was_cached)``.
120
+
121
+ ElevenLabs through ``braidio.narrate`` (``was_cached``: mixing served it
122
+ from disk), or the registered backend ``tts`` through
123
+ :func:`braidio.tts.narrator_from_speak` (never cached; its file carries
124
+ the format it reported). Paced ``turns`` are one call each, concatenated
125
+ into ``out_path``.
126
+ """
127
+ import braidio # runtime attr access so tests can monkeypatch narrate
128
+
129
+ cached: list[bool] = []
130
+ if tts:
131
+ synthesize = narrator_from_speak(tts_backend(tts).speak)
132
+ else:
133
+
134
+ def synthesize(turn_text, turn_path, **kwargs):
135
+ path, hit = braidio.narrate(
136
+ turn_text, turn_path, return_cache_status=True, **kwargs
137
+ )
138
+ cached.append(hit)
139
+ return path
140
+
141
+ kwargs = dict(api_key=api_key, voice_id=voice_id, model_id=model_id)
142
+ if turns: # paced: one call per turn, real silence between (braidio#118)
143
+ paced = narrate_turns(
144
+ turns,
145
+ stem=out_path.with_suffix(""),
146
+ voice_settings=settings,
147
+ narrate_fn=synthesize,
148
+ **kwargs,
149
+ )
150
+ # one turn and no gap is that turn's own file, in the backend's format
151
+ final = out_path.with_suffix(Path(paced).suffix)
152
+ shutil.move(paced, final)
153
+ for leftover in out_path.parent.glob(f"{out_path.stem}-turn*"):
154
+ leftover.unlink() # per-turn parts and gaps: only the mix is a node
155
+ return final, bool(cached) and all(cached)
156
+ path = synthesize(text, out_path, voice_settings=settings, **kwargs)
157
+ return Path(path), bool(cached) and all(cached)
158
+
159
+
99
160
  def _beat_settings(beat, config: dict) -> dict:
100
161
  """The beat's own voice settings, else the config's — the fast path's rule."""
101
162
  return beat.body.get("voice_settings") or config.get("voice_settings", {})
@@ -140,7 +201,13 @@ class NarrationRenderTTS(BaseTransform):
140
201
  settings = _beat_settings(beat, config)
141
202
  turns = _beat_turns(beat, config, model_id=model_id, settings=settings)
142
203
  cache_key = _narration_cache_key(
143
- self, beat.body.get("text", ""), voice_id, model_id, settings, turns
204
+ self,
205
+ beat.body.get("text", ""),
206
+ voice_id,
207
+ model_id,
208
+ settings,
209
+ turns,
210
+ tts=config.get("tts"),
144
211
  )
145
212
 
146
213
  full = TransformInputs(
@@ -167,8 +234,6 @@ class NarrationRenderTTS(BaseTransform):
167
234
  force: bool = False,
168
235
  secrets=None,
169
236
  ) -> TransformResult:
170
- import braidio # runtime attr access so tests can monkeypatch narrate
171
-
172
237
  skel = skeleton[0]
173
238
  cache_key = skel.body["cache_key"]
174
239
  parents = resolve_parents(skel, graph_index(project))
@@ -178,10 +243,11 @@ class NarrationRenderTTS(BaseTransform):
178
243
  config = cfg.body.get("config", {})
179
244
  text = beat.body.get("text", "")
180
245
  model_id = config.get("model_id", DEFAULT_MODEL_ID)
246
+ tts = config.get("tts") # a registered backend, else ElevenLabs (#132)
181
247
  # ElevenLabs bills per character — the only real spend here. A rate ESTIMATE
182
248
  # (== live-call spend; may over-report on a lower-level mixing-cache hit that
183
249
  # braidio can't yet detect — thorwhalen/braidio#8).
184
- cost = tts_cost_usd(text, model_id=model_id)
250
+ cost = backend_cost_usd(text, tts=tts, model_id=model_id)
185
251
 
186
252
  if use_cache and not force:
187
253
  # Idempotent re-run: the same render over the same, still-fresh
@@ -218,39 +284,16 @@ class NarrationRenderTTS(BaseTransform):
218
284
  # not in the node, not in the cache_key.
219
285
  api_key = elevenlabs_key(secrets)
220
286
  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
- )
287
+ out_path, was_cached = _speak_beat(
288
+ text,
289
+ out_path,
290
+ tts=tts,
291
+ turns=turns,
292
+ api_key=api_key,
293
+ voice_id=voice_id,
294
+ model_id=model_id,
295
+ settings=settings,
296
+ )
254
297
  duration = safe_duration(out_path)
255
298
  artifact = audio_artifact(
256
299
  out_path,