braidio 0.0.80__tar.gz → 0.0.82__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.80 → braidio-0.0.82}/PKG-INFO +12 -2
  2. {braidio-0.0.80 → braidio-0.0.82}/README.md +10 -0
  3. {braidio-0.0.80 → braidio-0.0.82}/braidio/conversation.py +7 -2
  4. braidio-0.0.82/braidio/leveling.py +115 -0
  5. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/tools.py +7 -14
  6. {braidio-0.0.80 → braidio-0.0.82}/braidio/multivoice.py +5 -27
  7. braidio-0.0.82/braidio/project.py +144 -0
  8. {braidio-0.0.80 → braidio-0.0.82}/braidio/render.py +38 -36
  9. {braidio-0.0.80 → braidio-0.0.82}/braidio/structure.py +40 -21
  10. {braidio-0.0.80 → braidio-0.0.82}/braidio/timeline.py +5 -0
  11. {braidio-0.0.80 → braidio-0.0.82}/braidio/tts.py +91 -0
  12. {braidio-0.0.80 → braidio-0.0.82}/pyproject.toml +2 -2
  13. braidio-0.0.82/tests/test_leveling.py +82 -0
  14. {braidio-0.0.80 → braidio-0.0.82}/tests/test_mcp.py +41 -0
  15. braidio-0.0.82/tests/test_speak_seam.py +160 -0
  16. {braidio-0.0.80 → braidio-0.0.82}/tests/test_structure.py +41 -0
  17. {braidio-0.0.80 → braidio-0.0.82}/tests/test_transforms.py +53 -0
  18. {braidio-0.0.80 → braidio-0.0.82}/tests/test_tts_api_key.py +2 -2
  19. braidio-0.0.80/braidio/project.py +0 -60
  20. {braidio-0.0.80 → braidio-0.0.82}/.editorconfig +0 -0
  21. {braidio-0.0.80 → braidio-0.0.82}/.gitattributes +0 -0
  22. {braidio-0.0.80 → braidio-0.0.82}/.gitignore +0 -0
  23. {braidio-0.0.80 → braidio-0.0.82}/LICENSE +0 -0
  24. {braidio-0.0.80 → braidio-0.0.82}/braidio/__init__.py +0 -0
  25. {braidio-0.0.80 → braidio-0.0.82}/braidio/_paths.py +0 -0
  26. {braidio-0.0.80 → braidio-0.0.82}/braidio/bodies/__init__.py +0 -0
  27. {braidio-0.0.80 → braidio-0.0.82}/braidio/bodies/_domain.py +0 -0
  28. {braidio-0.0.80 → braidio-0.0.82}/braidio/bodies/_render_nodes.py +0 -0
  29. {braidio-0.0.80 → braidio-0.0.82}/braidio/bodies/_tiers.py +0 -0
  30. {braidio-0.0.80 → braidio-0.0.82}/braidio/bodies/_video.py +0 -0
  31. {braidio-0.0.80 → braidio-0.0.82}/braidio/captions.py +0 -0
  32. {braidio-0.0.80 → braidio-0.0.82}/braidio/compose.py +0 -0
  33. {braidio-0.0.80 → braidio-0.0.82}/braidio/cost.py +0 -0
  34. {braidio-0.0.80 → braidio-0.0.82}/braidio/data/skills/braidio/SKILL.md +0 -0
  35. {braidio-0.0.80 → braidio-0.0.82}/braidio/data/skills/braidio-commentary-video/SKILL.md +0 -0
  36. {braidio-0.0.80 → braidio-0.0.82}/braidio/defaults.py +0 -0
  37. {braidio-0.0.80 → braidio-0.0.82}/braidio/delivery.py +0 -0
  38. {braidio-0.0.80 → braidio-0.0.82}/braidio/downloads.py +0 -0
  39. {braidio-0.0.80 → braidio-0.0.82}/braidio/formats.py +0 -0
  40. {braidio-0.0.80 → braidio-0.0.82}/braidio/genre.py +0 -0
  41. {braidio-0.0.80 → braidio-0.0.82}/braidio/importing/__init__.py +0 -0
  42. {braidio-0.0.80 → braidio-0.0.82}/braidio/importing/__main__.py +0 -0
  43. {braidio-0.0.80 → braidio-0.0.82}/braidio/importing/_catalog.py +0 -0
  44. {braidio-0.0.80 → braidio-0.0.82}/braidio/importing/_manifest.py +0 -0
  45. {braidio-0.0.80 → braidio-0.0.82}/braidio/importing/_writer.py +0 -0
  46. {braidio-0.0.80 → braidio-0.0.82}/braidio/kinds.py +0 -0
  47. {braidio-0.0.80 → braidio-0.0.82}/braidio/markdown_script.py +0 -0
  48. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/__init__.py +0 -0
  49. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/_docs.py +0 -0
  50. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/_guide.py +0 -0
  51. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/_helpers.py +0 -0
  52. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/_media.py +0 -0
  53. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/credentials.py +0 -0
  54. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/metering.py +0 -0
  55. {braidio-0.0.80 → braidio-0.0.82}/braidio/mcp/workspace.py +0 -0
  56. {braidio-0.0.80 → braidio-0.0.82}/braidio/music.py +0 -0
  57. {braidio-0.0.80 → braidio-0.0.82}/braidio/pacing.py +0 -0
  58. {braidio-0.0.80 → braidio-0.0.82}/braidio/provenance.py +0 -0
  59. {braidio-0.0.80 → braidio-0.0.82}/braidio/relevance.py +0 -0
  60. {braidio-0.0.80 → braidio-0.0.82}/braidio/rights.py +0 -0
  61. {braidio-0.0.80 → braidio-0.0.82}/braidio/script.py +0 -0
  62. {braidio-0.0.80 → braidio-0.0.82}/braidio/sources.py +0 -0
  63. {braidio-0.0.80 → braidio-0.0.82}/braidio/style.py +0 -0
  64. {braidio-0.0.80 → braidio-0.0.82}/braidio/textprep.py +0 -0
  65. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/__init__.py +0 -0
  66. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_asset_refs.py +0 -0
  67. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_common.py +0 -0
  68. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_dialogue.py +0 -0
  69. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_episode.py +0 -0
  70. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_ingest.py +0 -0
  71. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_narration.py +0 -0
  72. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_segment.py +0 -0
  73. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_video_cut.py +0 -0
  74. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_video_panels.py +0 -0
  75. {braidio-0.0.80 → braidio-0.0.82}/braidio/transforms/_voice.py +0 -0
  76. {braidio-0.0.80 → braidio-0.0.82}/braidio/video.py +0 -0
  77. {braidio-0.0.80 → braidio-0.0.82}/braidio/voice_library.py +0 -0
  78. {braidio-0.0.80 → braidio-0.0.82}/braidio/weave.py +0 -0
  79. {braidio-0.0.80 → braidio-0.0.82}/braidio/weave_config.py +0 -0
  80. {braidio-0.0.80 → braidio-0.0.82}/conftest.py +0 -0
  81. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/Extraction and nw-App Design.md +0 -0
  82. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/research/commentary-formats-and-styles.md +0 -0
  83. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/research/conversational-vs-narration-tts.md +0 -0
  84. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/research/notebooklm-and-conversational-pacing.md +0 -0
  85. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/README.md +0 -0
  86. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/anti-platitude-checklist.md +0 -0
  87. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/commentary-voice-guide.md +0 -0
  88. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/_style-groups.md +0 -0
  89. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/amanda-dobbins.md +0 -0
  90. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/david-sims.md +0 -0
  91. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/griffin-newman.md +0 -0
  92. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/helen-molesworth.md +0 -0
  93. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/hrishikesh-hirway.md +0 -0
  94. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/jason-mantzoukas.md +0 -0
  95. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/john-mcwhorter.md +0 -0
  96. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/jon-caramanica.md +0 -0
  97. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/june-diane-raphael.md +0 -0
  98. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/karina-longworth.md +0 -0
  99. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/katy-hessel.md +0 -0
  100. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/louis-theroux.md +0 -0
  101. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/mallory-rubin.md +0 -0
  102. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/melvyn-bragg.md +0 -0
  103. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/michael-barbaro.md +0 -0
  104. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/nate-sloan-charlie-harding.md +0 -0
  105. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/paul-scheer.md +0 -0
  106. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/sean-fennessey.md +0 -0
  107. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/talk-art.md +0 -0
  108. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/style/voices/yasi-salek.md +0 -0
  109. {braidio-0.0.80 → braidio-0.0.82}/misc/docs/youtube_ingest_credentials.md +0 -0
  110. {braidio-0.0.80 → braidio-0.0.82}/tests/_audio.py +0 -0
  111. {braidio-0.0.80 → braidio-0.0.82}/tests/test_body_schema_stability.py +0 -0
  112. {braidio-0.0.80 → braidio-0.0.82}/tests/test_conversation.py +0 -0
  113. {braidio-0.0.80 → braidio-0.0.82}/tests/test_cost.py +0 -0
  114. {braidio-0.0.80 → braidio-0.0.82}/tests/test_credits_card.py +0 -0
  115. {braidio-0.0.80 → braidio-0.0.82}/tests/test_defaults.py +0 -0
  116. {braidio-0.0.80 → braidio-0.0.82}/tests/test_delivery.py +0 -0
  117. {braidio-0.0.80 → braidio-0.0.82}/tests/test_downloads.py +0 -0
  118. {braidio-0.0.80 → braidio-0.0.82}/tests/test_expressiveness.py +0 -0
  119. {braidio-0.0.80 → braidio-0.0.82}/tests/test_formats.py +0 -0
  120. {braidio-0.0.80 → braidio-0.0.82}/tests/test_genre_placement.py +0 -0
  121. {braidio-0.0.80 → braidio-0.0.82}/tests/test_importing.py +0 -0
  122. {braidio-0.0.80 → braidio-0.0.82}/tests/test_markdown_script.py +0 -0
  123. {braidio-0.0.80 → braidio-0.0.82}/tests/test_mcp_caller_key.py +0 -0
  124. {braidio-0.0.80 → braidio-0.0.82}/tests/test_media_auth.py +0 -0
  125. {braidio-0.0.80 → braidio-0.0.82}/tests/test_multivoice.py +0 -0
  126. {braidio-0.0.80 → braidio-0.0.82}/tests/test_music.py +0 -0
  127. {braidio-0.0.80 → braidio-0.0.82}/tests/test_namespaced_source.py +0 -0
  128. {braidio-0.0.80 → braidio-0.0.82}/tests/test_nw_app.py +0 -0
  129. {braidio-0.0.80 → braidio-0.0.82}/tests/test_pacing.py +0 -0
  130. {braidio-0.0.80 → braidio-0.0.82}/tests/test_packaging.py +0 -0
  131. {braidio-0.0.80 → braidio-0.0.82}/tests/test_render_settings.py +0 -0
  132. {braidio-0.0.80 → braidio-0.0.82}/tests/test_script.py +0 -0
  133. {braidio-0.0.80 → braidio-0.0.82}/tests/test_sources.py +0 -0
  134. {braidio-0.0.80 → braidio-0.0.82}/tests/test_textprep_style.py +0 -0
  135. {braidio-0.0.80 → braidio-0.0.82}/tests/test_timeline.py +0 -0
  136. {braidio-0.0.80 → braidio-0.0.82}/tests/test_transforms_dialogue.py +0 -0
  137. {braidio-0.0.80 → braidio-0.0.82}/tests/test_transforms_episode_members.py +0 -0
  138. {braidio-0.0.80 → braidio-0.0.82}/tests/test_transforms_rights.py +0 -0
  139. {braidio-0.0.80 → braidio-0.0.82}/tests/test_transforms_secrets.py +0 -0
  140. {braidio-0.0.80 → braidio-0.0.82}/tests/test_transforms_structure.py +0 -0
  141. {braidio-0.0.80 → braidio-0.0.82}/tests/test_turn_overlap.py +0 -0
  142. {braidio-0.0.80 → braidio-0.0.82}/tests/test_video.py +0 -0
  143. {braidio-0.0.80 → braidio-0.0.82}/tests/test_video_bodies.py +0 -0
  144. {braidio-0.0.80 → braidio-0.0.82}/tests/test_video_footage.py +0 -0
  145. {braidio-0.0.80 → braidio-0.0.82}/tests/test_video_transforms.py +0 -0
  146. {braidio-0.0.80 → braidio-0.0.82}/tests/test_voice_library.py +0 -0
  147. {braidio-0.0.80 → braidio-0.0.82}/tests/test_weave.py +0 -0
  148. {braidio-0.0.80 → braidio-0.0.82}/tests/test_weave_config.py +0 -0
  149. {braidio-0.0.80 → braidio-0.0.82}/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.80
3
+ Version: 0.0.82
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
@@ -26,7 +26,7 @@ Classifier: Topic :: Multimedia :: Video
26
26
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
27
  Requires-Python: >=3.10
28
28
  Requires-Dist: elevenlabs
29
- Requires-Dist: mixing[media]>=0.0.28
29
+ Requires-Dist: mixing[media]>=0.0.77
30
30
  Provides-Extra: dev
31
31
  Requires-Dist: build; extra == 'dev'
32
32
  Requires-Dist: pytest-cov>=4.0; extra == 'dev'
@@ -212,6 +212,16 @@ ElevenLabs TTS is braidio's only spend (everything else is local ffmpeg). `braid
212
212
 
213
213
  Every render entry point — `narrate`, `render_dialogue`, `render_production`, `render_format` and the graph driver `weave_project` — takes an explicit `api_key=` for a caller's own ElevenLabs key; `None` (the default) resolves from the environment. On the graph path the key reaches the two synthesis transforms through nw's `execute(secrets=)` seam and is never persisted: not in a node, provenance, a cache key or a usage ledger (thorwhalen/braidio#58). The MCP server reads it from the `X-Elevenlabs-Key` request header, never from a tool argument.
214
214
 
215
+ ### Any voice backend (`speak=`)
216
+
217
+ ElevenLabs is the default, not a requirement. `render_production` and `render_format` take `speak=`, any callable `speak(text, *, voice) -> (audio_bytes, format)`, and route every narration beat and turn through it; a dialogue beat is spoken turn by turn, since only ElevenLabs has the one-pass Text-to-Dialogue path. Formats, pacing and weaving are unchanged, so a local model (through `voxy`, say) gives a free preview of `DEEP_DIVE`, and a test or CI can render with no key at all:
218
+
219
+ ```python
220
+ render_format(DEEP_DIVE, script, source=None, speak=my_local_tts)
221
+ ```
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).
224
+
215
225
  ## What it deliberately does *not* do
216
226
 
217
227
  braidio is a thin orchestration layer. It **delegates**:
@@ -143,6 +143,16 @@ ElevenLabs TTS is braidio's only spend (everything else is local ffmpeg). `braid
143
143
 
144
144
  Every render entry point — `narrate`, `render_dialogue`, `render_production`, `render_format` and the graph driver `weave_project` — takes an explicit `api_key=` for a caller's own ElevenLabs key; `None` (the default) resolves from the environment. On the graph path the key reaches the two synthesis transforms through nw's `execute(secrets=)` seam and is never persisted: not in a node, provenance, a cache key or a usage ledger (thorwhalen/braidio#58). The MCP server reads it from the `X-Elevenlabs-Key` request header, never from a tool argument.
145
145
 
146
+ ### Any voice backend (`speak=`)
147
+
148
+ ElevenLabs is the default, not a requirement. `render_production` and `render_format` take `speak=`, any callable `speak(text, *, voice) -> (audio_bytes, format)`, and route every narration beat and turn through it; a dialogue beat is spoken turn by turn, since only ElevenLabs has the one-pass Text-to-Dialogue path. Formats, pacing and weaving are unchanged, so a local model (through `voxy`, say) gives a free preview of `DEEP_DIVE`, and a test or CI can render with no key at all:
149
+
150
+ ```python
151
+ render_format(DEEP_DIVE, script, source=None, speak=my_local_tts)
152
+ ```
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).
155
+
146
156
  ## What it deliberately does *not* do
147
157
 
148
158
  braidio is a thin orchestration layer. It **delegates**:
@@ -164,18 +164,23 @@ def render_turns_sequential(
164
164
  work_dir: str | Path = "data/tts/conversation",
165
165
  voice_settings: dict | None = None,
166
166
  gap_s: float = 0.25,
167
+ narrate_fn=None,
167
168
  ) -> Path:
168
169
  """Per-line baseline: synthesize each turn alone (its role's voice) and
169
170
  concatenate with ``gap_s`` gaps. Prosody is NOT shared across turns — this is
170
171
  what tends to sound like alternating monologues (the thing to beat).
171
172
 
172
173
  ``api_key`` is threaded to :func:`braidio.tts.narrate`; ``None`` (default)
173
- keeps the ``$ELEVENLABS_API_KEY`` fallback."""
174
+ keeps the ``$ELEVENLABS_API_KEY`` fallback. ``narrate_fn`` is the per-turn
175
+ synthesizer (default :func:`braidio.tts.narrate`): a renderer given another
176
+ TTS backend (:func:`braidio.tts.narrator_from_speak`) renders dialogue here,
177
+ since only ElevenLabs has the one-pass path."""
178
+ synthesize = narrate_fn or narrate
174
179
  work = Path(work_dir)
175
180
  work.mkdir(parents=True, exist_ok=True)
176
181
  parts: list[Path] = []
177
182
  for i, (role, text) in enumerate(turns):
178
- raw = narrate(
183
+ raw = synthesize(
179
184
  text,
180
185
  work / f"turn{i:02d}-{role}.mp3",
181
186
  api_key=api_key,
@@ -0,0 +1,115 @@
1
+ """Level one spoken part to a loudness target with a single measured gain.
2
+
3
+ Every narration take, dialogue exchange and source clip is levelled before it
4
+ is woven, so a quiet clip sits beside a loud take. ffmpeg's one-pass
5
+ ``loudnorm`` would do that *dynamically*: it rides the gain through the part,
6
+ flattening a voice's own dynamics (a whisper, an emphasis) and pumping quiet
7
+ passages. :func:`level_part` instead measures the part once and applies one
8
+ gain, then a true-peak limiter holds the ceiling. The measurement and the
9
+ limiter are :mod:`mixing.loudness` (the fleet's one loudness component);
10
+ this module only decodes, applies and encodes.
11
+
12
+ >>> peak_ceiling(DEFAULT_TRUE_PEAK_DB) # doctest: +ELLIPSIS
13
+ 0.84...
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import subprocess
19
+ from contextlib import closing
20
+ from pathlib import Path
21
+
22
+ import numpy as np
23
+ from mixing.decode import decode_float_chunks
24
+ from mixing.loudness import level_group, limit_peaks
25
+ from mixing.util import ffmpeg_exe
26
+
27
+ #: Integrated loudness a spoken part is levelled to, in LUFS.
28
+ DEFAULT_TARGET_LUFS = -16.0
29
+ #: True-peak ceiling of a levelled part, in dBTP.
30
+ DEFAULT_TRUE_PEAK_DB = -1.5
31
+ #: Sample rate every levelled part is written at, so the weave concatenates
32
+ #: parts of one rate whatever each source was.
33
+ OUTPUT_SAMPLE_RATE = 44100
34
+
35
+ _PCM_FORMAT = "f32le" # how float samples travel to the encoder
36
+ _STDERR_TAIL_CHARS = 800 # how much of ffmpeg's complaint an error carries
37
+
38
+
39
+ def peak_ceiling(true_peak_db: float) -> float:
40
+ """The linear ceiling (full scale 1.0) of a ``true_peak_db`` dBTP limit."""
41
+ return 10.0 ** (true_peak_db / 20.0)
42
+
43
+
44
+ def _decode(src: Path) -> tuple[np.ndarray, int]:
45
+ rate, chunks = decode_float_chunks(src)
46
+ with closing(chunks):
47
+ parts = list(chunks)
48
+ return (np.concatenate(parts) if parts else np.zeros((0, 1), np.float32)), rate
49
+
50
+
51
+ def _encode(samples: np.ndarray, rate: int, dst: Path, *, sample_rate: int) -> None:
52
+ proc = subprocess.run(
53
+ [
54
+ ffmpeg_exe(),
55
+ "-y",
56
+ "-f",
57
+ _PCM_FORMAT,
58
+ "-ar",
59
+ str(rate),
60
+ "-ac",
61
+ str(samples.shape[1]),
62
+ "-i",
63
+ "-",
64
+ "-ar",
65
+ str(sample_rate), # the resample, as its own step
66
+ str(dst),
67
+ ],
68
+ input=np.ascontiguousarray(samples, dtype="<f4").tobytes(),
69
+ capture_output=True,
70
+ )
71
+ if proc.returncode != 0:
72
+ tail = proc.stderr.decode(errors="replace").strip()[-_STDERR_TAIL_CHARS:]
73
+ raise RuntimeError(f"ffmpeg could not write {dst.name}: {tail}")
74
+
75
+
76
+ def level_part(
77
+ src: str | Path,
78
+ dst: str | Path,
79
+ *,
80
+ target_lufs: float = DEFAULT_TARGET_LUFS,
81
+ true_peak_db: float = DEFAULT_TRUE_PEAK_DB,
82
+ sample_rate: int = OUTPUT_SAMPLE_RATE,
83
+ ) -> Path:
84
+ """Write ``src`` to ``dst`` at ``target_lufs`` with one gain, true-peak limited.
85
+
86
+ The gain is :func:`mixing.loudness.level_group` over the whole part (so the
87
+ part keeps its own dynamics; silence gets none), the limiter
88
+ :func:`mixing.loudness.limit_peaks` at ``true_peak_db``. Gains are applied
89
+ in float, so nothing clips before the limiter. ``dst`` is written at
90
+ ``sample_rate``, in the format its suffix names.
91
+
92
+ Bounds worth knowing:
93
+
94
+ - The gain is capped at ``mixing.loudness.MAX_GAIN_DB`` (with a warning):
95
+ a part far below the target comes out quieter than it, rather than as
96
+ amplified noise (``loudnorm`` would have pulled it all the way up).
97
+ - The ceiling holds on the samples handed to the encoder; a lossy ``dst``
98
+ (mp3) can read a few tenths of a dB over it. A levelled part is an
99
+ intermediate: the final master limits again.
100
+ - The whole part is decoded into memory (float, plus the limiter's copy):
101
+ fine for spoken parts and clips of minutes, roughly 1 GB for 10 minutes
102
+ of 48 kHz stereo. A streaming file-level leveller belongs in ``mixing``.
103
+ """
104
+ src, dst = Path(src), Path(dst)
105
+ dst.parent.mkdir(parents=True, exist_ok=True)
106
+ samples, rate = _decode(src)
107
+ gain_db, _ = level_group([samples], rate, target_lufs=target_lufs)
108
+ leveled = limit_peaks(
109
+ samples * 10.0 ** (gain_db / 20.0),
110
+ ceiling=peak_ceiling(true_peak_db),
111
+ true_peak=True,
112
+ fs=rate,
113
+ )
114
+ _encode(leveled, rate, dst, sample_rate=sample_rate)
115
+ return dst
@@ -323,23 +323,16 @@ def list_projects() -> dict:
323
323
 
324
324
 
325
325
  def project_status(project_id: str) -> dict:
326
- """A project's status: its finished episode renders (url + duration), if any.
327
-
328
- Each episode row carries ``episode_id`` — the id ``resolve`` accepts and a
329
- download claim is minted against. The body's own ``artifact_id`` is the
330
- lacing CONTENT hash: an identity for provenance, not a retrieval key
331
- (braidio#32 — the tool used to return only the body, so the one id a
332
- caller could see was the one no download tool accepted).
326
+ """A project's status: beat/render counts, the next step, and its finished
327
+ episodes (url + duration). Each episode's ``episode_id`` is the id ``resolve``
328
+ accepts; the body's ``artifact_id`` is a content hash, not a download key.
333
329
  """
334
330
  _require_nw("project_status")
335
- import nw
336
-
337
331
  proj = _workspace().open_project(project_id)
338
- episodes = [
339
- {"episode_id": str(a.id), **to_json(a.body)}
340
- for a in nw.annotations_at_tier(proj.root, "episode-renders")
341
- ]
342
- return {"project_id": project_id, "episodes": episodes}
332
+ # The genre's status (what a host's one project_status door serves) plus every
333
+ # episode's full body, url included: this caller owns the workspace.
334
+ episodes = [{"episode_id": str(a.id), **to_json(a.body)} for a in proj.episodes()]
335
+ return {"project_id": project_id, **proj.genre_status(), "episodes": episodes}
343
336
 
344
337
 
345
338
  #: Content types whose extracted text has lost its markdown structure, so
@@ -18,13 +18,13 @@ from __future__ import annotations
18
18
 
19
19
  import random
20
20
  import re
21
- import shutil
22
21
  import subprocess
23
22
  from dataclasses import dataclass
24
23
  from pathlib import Path
25
24
 
26
25
  from mixing import concatenate_audio
27
26
 
27
+ from braidio.leveling import DEFAULT_TARGET_LUFS, level_part
28
28
  from braidio.tts import narrate
29
29
 
30
30
  _MARKUP_RE = re.compile(r"<[^>]*>|\[[^\]]*\]")
@@ -122,30 +122,6 @@ def group_turns(
122
122
  return turns
123
123
 
124
124
 
125
- def _loudnorm(
126
- src: Path, dst: Path, *, target_lufs: float = -16.0, true_peak: float = -1.5
127
- ) -> Path:
128
- if shutil.which("ffmpeg") is None:
129
- raise RuntimeError("ffmpeg not found on PATH.")
130
- dst.parent.mkdir(parents=True, exist_ok=True)
131
- subprocess.run(
132
- [
133
- "ffmpeg",
134
- "-y",
135
- "-i",
136
- str(src),
137
- "-af",
138
- f"loudnorm=I={target_lufs}:TP={true_peak}:LRA=11",
139
- "-ar",
140
- "44100",
141
- str(dst),
142
- ],
143
- check=True,
144
- capture_output=True,
145
- )
146
- return dst
147
-
148
-
149
125
  def render_multivoice(
150
126
  segments: list[str],
151
127
  pool: list[Voice],
@@ -163,7 +139,7 @@ def render_multivoice(
163
139
  speed_jitter: float = 0.04,
164
140
  crossfade_s: float = 0.1,
165
141
  gap_s: float = 0.0,
166
- target_lufs: float = -16.0,
142
+ target_lufs: float = DEFAULT_TARGET_LUFS,
167
143
  ) -> list[tuple[Voice, str]]:
168
144
  """Render ``segments`` cycling ``pool`` → ``out_path``.
169
145
 
@@ -198,7 +174,9 @@ def render_multivoice(
198
174
  model_id=model_id,
199
175
  voice_settings={**settings, "speed": speed},
200
176
  )
201
- parts.append(_loudnorm(raw, work / f"norm{i:03d}.mp3", target_lufs=target_lufs))
177
+ parts.append(
178
+ level_part(raw, work / f"norm{i:03d}.mp3", target_lufs=target_lufs)
179
+ )
202
180
  out = Path(out_path)
203
181
  out.parent.mkdir(parents=True, exist_ok=True)
204
182
  if gap_s > 0:
@@ -0,0 +1,144 @@
1
+ """braidio as an nw app: a :class:`nw.Project` for commentary-weave productions.
2
+
3
+ Subclassing ``nw.Project`` inherits the whole folder facade + lacing graph +
4
+ freshness (``stale_after``) machinery; braidio adds its production kind and its
5
+ domain/render body-schema vocabulary (registered on import of
6
+ :mod:`braidio.bodies`). This module requires ``nw``; it is imported lazily by
7
+ ``braidio/__init__`` only when ``nw`` is available.
8
+
9
+ The costed ``plan``/``execute`` Transform pipeline (each transform delegating to
10
+ braidio's functional core for the actual audio, and recording provenance via
11
+ :mod:`braidio.provenance`) is the next increment — see the design doc and
12
+ nw#9 (generalizing nw's shot/mp4 render seam).
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from pathlib import Path
18
+
19
+ import nw
20
+
21
+ from braidio import bodies as _bodies # noqa: F401 (import registers schemas)
22
+ from braidio.kinds import WeaveKind
23
+
24
+
25
+ #: The next step, by how far the project has got: ``(op, why)``, ``op`` in
26
+ #: braidio's own vocabulary (a host maps it to its tool name, prefix and all).
27
+ NEXT_STEP_SAVE_SCRIPT = ("save_script", "there is no script yet")
28
+ NEXT_STEP_WEAVE = ("weave_project", "the script has not been rendered yet")
29
+ NEXT_STEP_DONE = (
30
+ "weave_project",
31
+ "an episode is made — download it by its episode_id, or weave again after "
32
+ "changing the script",
33
+ )
34
+
35
+
36
+ def _tiers():
37
+ """The tier names, from the one table the transforms write by (lazy: the
38
+ transforms package is heavy and this module is imported with ``braidio``)."""
39
+ from braidio.transforms import _common
40
+
41
+ return _common
42
+
43
+
44
+ def _episode_row(annotation) -> dict:
45
+ """One finished episode, path-free: the body's ``file://`` url and its
46
+ (large) timeline are left out."""
47
+ body = annotation.body
48
+ duration = body.get("duration_s")
49
+ return {
50
+ "episode_id": str(annotation.id),
51
+ "profile": body.get("profile"),
52
+ "duration_s": None if duration is None else round(float(duration), 2),
53
+ }
54
+
55
+
56
+ class Project(nw.Project):
57
+ """An nw project for a braidio commentary-weave production."""
58
+
59
+ KIND: WeaveKind = WeaveKind.COMMENTARY_WEAVE
60
+
61
+ def episodes(self) -> list:
62
+ """The project's finished episodes (``episode-renders`` nodes), oldest first.
63
+
64
+ A re-weave adds an episode and keeps the earlier ones, so the last is
65
+ the current one.
66
+ """
67
+ tiers = _tiers()
68
+ return sorted(
69
+ nw.annotations_at_tier(self.root, tiers.TIER_EPISODE_RENDER),
70
+ # generation time, then id: nw's own order (ties: legacy tick-0 stamps)
71
+ key=lambda a: (a.provenance.generated_at_time.to_seconds(), str(a.id)),
72
+ )
73
+
74
+ def genre_status(self) -> dict:
75
+ """Where this production stands, for a host's one ``project_status`` door
76
+ (``nw.Project.genre_status``, nw#133; braidio#125).
77
+
78
+ Counted, in muvid's shape: the script's beats by kind, how many episodes
79
+ were rendered, the latest one (path-free), and the next step as
80
+ ``{"op", "why"}``. Indexed tier reads only — no freshness walk, no file
81
+ probe — and no per-item list, so it stays small however often the
82
+ project is re-woven, and never names a path.
83
+
84
+ >>> import tempfile
85
+ >>> with tempfile.TemporaryDirectory() as d:
86
+ ... status = create_project_at(d, "ep").genre_status()
87
+ >>> status["episode_count"], status["next_step"]["op"]
88
+ (0, 'save_script')
89
+ """
90
+ tiers = _tiers()
91
+ counts = {
92
+ key: len(nw.annotations_at_tier(self.root, tier))
93
+ for key, tier in (
94
+ ("narration_beats", tiers.TIER_NARRATIVE_BEAT),
95
+ ("dialogue_beats", tiers.TIER_DIALOGUE_BEAT),
96
+ ("clips", tiers.TIER_AUDIO_CLIP),
97
+ ("scene_breaks", tiers.TIER_SCENE_BREAK),
98
+ )
99
+ }
100
+ episodes = self.episodes()
101
+ if episodes:
102
+ op, why = NEXT_STEP_DONE
103
+ elif any(counts.values()):
104
+ op, why = NEXT_STEP_WEAVE
105
+ else:
106
+ op, why = NEXT_STEP_SAVE_SCRIPT
107
+ return {
108
+ **counts,
109
+ "episode_count": len(episodes),
110
+ "latest_episode": _episode_row(episodes[-1]) if episodes else None,
111
+ "next_step": {"op": op, "why": why},
112
+ }
113
+
114
+
115
+ def create_project_at(
116
+ projects_dir: "str | Path", project_id: str, *, title: str = "", force: bool = False
117
+ ) -> Project:
118
+ """Create a braidio project at ``projects_dir/<project_id>`` — the *host-placed* create.
119
+
120
+ The counterpart to :meth:`braidio.mcp.workspace.Workspace.create_project`, which
121
+ places a project in braidio's own per-caller workspace. This one takes the
122
+ directory from its caller, because a host that will **serve** the project
123
+ (reelee, over HTTP) has to put it where its own resolver and lister look — under
124
+ braidio's data home it would be a sibling of nothing the host can address. See
125
+ nw's ``projects_dir`` placement contract (thorwhalen/nw#84).
126
+
127
+ Deliberately here and not in ``braidio.mcp.workspace``: importing that module
128
+ runs ``braidio/mcp/__init__.py`` and pulls **fastmcp**, and the host-placed path
129
+ has no reason to require the MCP extra. ``project_id`` is validated as a single
130
+ traversal-safe component, so the result is always a direct child of
131
+ ``projects_dir`` — which is the property the host's lister depends on, and which
132
+ nw verifies after the fact.
133
+
134
+ >>> import tempfile
135
+ >>> with tempfile.TemporaryDirectory() as d:
136
+ ... p = create_project_at(d, "ep_01", title="Episode 1")
137
+ ... p.root.name
138
+ 'ep_01'
139
+ """
140
+ from braidio._paths import safe_component
141
+
142
+ root = Path(projects_dir) / safe_component(project_id, label="project_id")
143
+ root.parent.mkdir(parents=True, exist_ok=True)
144
+ return Project.init(root, title=title or project_id, force=force)
@@ -22,7 +22,12 @@ from pathlib import Path
22
22
 
23
23
  from mixing import concatenate_audio
24
24
 
25
- from braidio.conversation import DEFAULT_CAST, ConversationCast, render_dialogue
25
+ from braidio.conversation import (
26
+ DEFAULT_CAST,
27
+ ConversationCast,
28
+ render_dialogue,
29
+ render_turns_sequential,
30
+ )
26
31
  from braidio.defaults import default_delivery
27
32
  from braidio.delivery import Delivery
28
33
  from braidio.pacing import NarrationTurn, plan_turns
@@ -33,17 +38,14 @@ from braidio.rights import (
33
38
  RightsPolicy,
34
39
  plan_production,
35
40
  )
41
+ from braidio.leveling import DEFAULT_TARGET_LUFS, level_part
36
42
  from braidio.script import Script
37
43
  from braidio.sources import SegmentSource
38
44
  from braidio.structure import DEFAULT_STRUCTURE, prepare_pause, prepare_sting
39
- from braidio.tts import narrate
45
+ from braidio.tts import Speak, narrate, narrator_from_speak, tts_name
40
46
  from braidio.weave import TimelineItem, extract_padded, weave_timeline
41
47
  from braidio.weave_config import WeaveConfig, speaker_key
42
48
 
43
- _DEFAULT_LUFS = -16.0
44
- _TRUE_PEAK = -1.5
45
- _LOUDNESS_RANGE = 11 # loudnorm LRA target for a spoken part
46
-
47
49
 
48
50
  def _require_ffmpeg() -> None:
49
51
  if shutil.which("ffmpeg") is None:
@@ -215,32 +217,12 @@ def _end_tail(path: Path, *, fade_s: float, silence_s: float) -> None:
215
217
  pass # not a real/probeable audio file — leave it untailed
216
218
 
217
219
 
218
- def _loudnorm(src: Path, dst: Path, *, target_lufs: float = _DEFAULT_LUFS) -> Path:
219
- _require_ffmpeg()
220
- dst.parent.mkdir(parents=True, exist_ok=True)
221
- subprocess.run(
222
- [
223
- "ffmpeg",
224
- "-y",
225
- "-i",
226
- str(src),
227
- "-af",
228
- f"loudnorm=I={target_lufs}:TP={_TRUE_PEAK}:LRA={_LOUDNESS_RANGE}",
229
- "-ar",
230
- "44100",
231
- str(dst),
232
- ],
233
- check=True,
234
- capture_output=True,
235
- )
236
- return dst
237
-
238
-
239
220
  def render_production(
240
221
  script: Script,
241
222
  *,
242
223
  source: SegmentSource,
243
224
  api_key: str | None = None,
225
+ speak: Speak | None = None,
244
226
  config: WeaveConfig | None = None,
245
227
  profile: Profile = DEFAULT_PROFILE,
246
228
  rights: RightsPolicy | None = None,
@@ -300,10 +282,20 @@ def render_production(
300
282
  explicit key lets a caller (e.g. a per-user BYO-key request) override the
301
283
  environment without mutating it. Segment beats never call ElevenLabs, so the
302
284
  key does not touch them.
285
+
286
+ ``speak`` swaps the voice backend (a :data:`braidio.tts.Speak`, e.g. a local
287
+ model through ``voxy``): every narration beat and turn is spoken through it,
288
+ and a dialogue beat is spoken turn by turn (only ElevenLabs has the one-pass
289
+ Text-to-Dialogue path). Formats, pacing and weaving are unchanged. It is
290
+ handed the voice ids this render resolves (the format's, the cast's), so
291
+ pass ``voice_id=`` / ``cast=`` in its vocabulary, or map them inside it.
292
+ ``None`` (default) is the ElevenLabs path, exactly as before.
303
293
  """
294
+ # the voice backend: ElevenLabs unless the caller supplied another one
295
+ synthesize = narrate if speak is None else narrator_from_speak(speak)
304
296
  publishable = rights.publishable_clip_rights if rights else PUBLISHABLE_CLIP_RIGHTS
305
297
  plan = plan_production(script, profile, publishable_clip_rights=publishable)
306
- target_lufs = config.target_lufs if config is not None else _DEFAULT_LUFS
298
+ target_lufs = config.target_lufs if config is not None else DEFAULT_TARGET_LUFS
307
299
  duck_db = config.duck_db if config is not None else -15.0
308
300
  structure = structure if structure is not None else DEFAULT_STRUCTURE
309
301
 
@@ -397,9 +389,10 @@ def render_production(
397
389
  voice_id=beat_voice,
398
390
  model_id=delivery.model_id,
399
391
  voice_settings=beat_settings,
392
+ narrate_fn=synthesize,
400
393
  )
401
394
  else:
402
- raw = narrate(
395
+ raw = synthesize(
403
396
  pb.content,
404
397
  beat_stem.with_name(beat_stem.name + ".mp3"),
405
398
  api_key=api_key,
@@ -414,13 +407,21 @@ def render_production(
414
407
  raw, Path(tts_dir) / f"{script.id_slug}-lead{i:02d}.mp3", gap_s=gap
415
408
  )
416
409
  elif pb.kind == "dialogue":
417
- raw = render_dialogue(
418
- list(pb.turns),
419
- cast,
420
- api_key=api_key,
421
- out_path=Path(tts_dir)
422
- / f"{script.id_slug}-{profile.value}-dlg{i:02d}.mp3",
410
+ dlg_path = (
411
+ Path(tts_dir) / f"{script.id_slug}-{profile.value}-dlg{i:02d}.mp3"
423
412
  )
413
+ if speak is None:
414
+ raw = render_dialogue(
415
+ list(pb.turns), cast, api_key=api_key, out_path=dlg_path
416
+ )
417
+ else:
418
+ raw = render_turns_sequential(
419
+ list(pb.turns),
420
+ cast,
421
+ out_path=dlg_path,
422
+ work_dir=dlg_path.with_suffix(""),
423
+ narrate_fn=synthesize,
424
+ )
424
425
  else: # segment
425
426
  rs = source.resolve(pb.content)
426
427
  if rs is None:
@@ -439,7 +440,7 @@ def render_production(
439
440
  min_len_s=clip_min_len,
440
441
  )
441
442
  parts.append(
442
- _loudnorm(raw, work / f"part{i:02d}.mp3", target_lufs=target_lufs)
443
+ level_part(raw, work / f"part{i:02d}.mp3", target_lufs=target_lufs)
443
444
  if normalize
444
445
  else raw
445
446
  )
@@ -544,6 +545,7 @@ def render_production(
544
545
  delivery=delivery,
545
546
  profile=profile,
546
547
  normalize=normalize,
548
+ tts=tts_name(speak),
547
549
  ),
548
550
  )
549
551
  return out, tl
@@ -27,9 +27,11 @@ from __future__ import annotations
27
27
 
28
28
  import shutil
29
29
  import subprocess
30
+ import tempfile
30
31
  from dataclasses import dataclass
31
32
  from pathlib import Path
32
33
 
34
+ from braidio.leveling import DEFAULT_TRUE_PEAK_DB, level_part
33
35
  from braidio.script import SCENE_MARKERS, SceneBreak, SegmentBeat
34
36
 
35
37
  # A sting is levelled to the production target, then sat this far under the
@@ -40,9 +42,6 @@ _DEFAULT_STING_FADE_OUT_S = 0.5
40
42
  _DEFAULT_STING_GAP_AFTER_S = 0.3
41
43
  # Silence at a break that has no sting to play: the boundary as white space.
42
44
  _DEFAULT_BREAK_PAUSE_S = 0.8
43
- # Levelling for a sting part (matches the renderer's true-peak ceiling).
44
- _STING_TRUE_PEAK = -1.5
45
- _STING_LRA = 11
46
45
 
47
46
 
48
47
  @dataclass(frozen=True)
@@ -137,9 +136,11 @@ def prepare_sting(
137
136
  ) -> Path:
138
137
  """Render ``sting`` to a ready-to-place part: trimmed, faded, levelled, padded.
139
138
 
140
- The result is already at production level (``target_lufs`` then
141
- ``sting.gain_db``), so the caller places it as-is rather than normalizing
142
- it again. Returns ``out_path``.
139
+ The result is already at production level (``target_lufs + sting.gain_db``),
140
+ so the caller places it as-is rather than normalizing it again. The level is
141
+ one measured gain with a true-peak limit applied last, so the ceiling holds
142
+ whatever ``gain_db`` is (:func:`braidio.leveling.level_part`, as every
143
+ spoken part gets), not a gain ridden through the sting. Returns ``out_path``.
143
144
  """
144
145
  _require_ffmpeg()
145
146
  from braidio.weave import duration_s
@@ -148,21 +149,39 @@ def prepare_sting(
148
149
  fo_start = max(0.0, length - sting.fade_out_s)
149
150
  out = Path(out_path)
150
151
  out.parent.mkdir(parents=True, exist_ok=True)
151
- # The trim is a filter, not an output `-t`: an output duration would also
152
- # cut the `apad` breathing room off the end (the gap would never render).
153
- af = (
154
- f"atrim=end={length:.3f},"
155
- f"afade=t=out:st={fo_start:.3f}:d={sting.fade_out_s},"
156
- f"loudnorm=I={target_lufs}:TP={_STING_TRUE_PEAK}:LRA={_STING_LRA},"
157
- f"volume={sting.gain_db}dB,"
158
- f"apad=pad_dur={sting.gap_after_s},"
159
- f"aformat=sample_rates={sample_rate}:channel_layouts=stereo"
160
- )
161
- subprocess.run(
162
- ["ffmpeg", "-y", "-i", str(sting.asset_path), "-af", af, str(out)],
163
- check=True,
164
- capture_output=True,
165
- )
152
+
153
+ def _ffmpeg(src: Path, af: str, dst: Path, *extra: str) -> Path:
154
+ subprocess.run(
155
+ ["ffmpeg", "-y", "-i", str(src), "-af", af, *extra, str(dst)],
156
+ check=True,
157
+ capture_output=True,
158
+ )
159
+ return dst
160
+
161
+ with tempfile.TemporaryDirectory(dir=out.parent, prefix=".sting-") as work:
162
+ work = Path(work)
163
+ shaped = _ffmpeg(
164
+ Path(sting.asset_path),
165
+ f"atrim=end={length:.3f},afade=t=out:st={fo_start:.3f}:d={sting.fade_out_s}",
166
+ work / "shaped.wav",
167
+ "-c:a",
168
+ "pcm_f32le", # float: no rounding before the gain
169
+ )
170
+ leveled = level_part(
171
+ shaped,
172
+ work / "leveled.wav",
173
+ target_lufs=target_lufs + sting.gain_db,
174
+ true_peak_db=DEFAULT_TRUE_PEAK_DB,
175
+ sample_rate=sample_rate,
176
+ )
177
+ # The pad is a filter, not an output `-t`, and comes after the level:
178
+ # the breathing room must render, and silence must not be measured.
179
+ _ffmpeg(
180
+ leveled,
181
+ f"apad=pad_dur={sting.gap_after_s},"
182
+ f"aformat=sample_rates={sample_rate}:channel_layouts=stereo",
183
+ out,
184
+ )
166
185
  return out
167
186
 
168
187