videopython 0.62.1__tar.gz → 0.62.3__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 (103) hide show
  1. {videopython-0.62.1 → videopython-0.62.3}/PKG-INFO +3 -3
  2. {videopython-0.62.1 → videopython-0.62.3}/pyproject.toml +5 -6
  3. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/dubber.py +100 -1
  4. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/pipeline.py +109 -54
  5. {videopython-0.62.1 → videopython-0.62.3}/.gitignore +0 -0
  6. {videopython-0.62.1 → videopython-0.62.3}/LICENSE +0 -0
  7. {videopython-0.62.1 → videopython-0.62.3}/README.md +0 -0
  8. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/__init__.py +0 -0
  9. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/_exceptions.py +0 -0
  10. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/_ffmpeg.py +0 -0
  11. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/__init__.py +0 -0
  12. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/_device.py +0 -0
  13. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/_ollama.py +0 -0
  14. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/_optional.py +0 -0
  15. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/_predictor.py +0 -0
  16. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/_revisions.py +0 -0
  17. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/_text_chunks.py +0 -0
  18. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/__init__.py +0 -0
  19. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/_speech.py +0 -0
  20. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/backend.py +0 -0
  21. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/catalog.py +0 -0
  22. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/editor.py +0 -0
  23. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/local.py +0 -0
  24. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/models.py +0 -0
  25. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/auto_edit/resolve.py +0 -0
  26. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/__init__.py +0 -0
  27. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/_phrases.py +0 -0
  28. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/_synthesis.py +0 -0
  29. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/_tts_backend.py +0 -0
  30. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/audio_ops.py +0 -0
  31. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/config.py +0 -0
  32. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/models.py +0 -0
  33. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/quality.py +0 -0
  34. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/remux.py +0 -0
  35. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/separation.py +0 -0
  36. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/timing.py +0 -0
  37. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/translation.py +0 -0
  38. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/dubbing/voice_sample.py +0 -0
  39. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/effects.py +0 -0
  40. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/errors.py +0 -0
  41. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/generation/__init__.py +0 -0
  42. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/generation/_speech_graphs.py +0 -0
  43. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/generation/_speech_tokens.py +0 -0
  44. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/generation/audio.py +0 -0
  45. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/generation/image.py +0 -0
  46. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/generation/video.py +0 -0
  47. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/keyframe.py +0 -0
  48. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/ops.py +0 -0
  49. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/transforms.py +0 -0
  50. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/__init__.py +0 -0
  51. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/_detector.py +0 -0
  52. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/_pyannote_patches.py +0 -0
  53. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/audio.py +0 -0
  54. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/classification.py +0 -0
  55. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/faces.py +0 -0
  56. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/image.py +0 -0
  57. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/objects.py +0 -0
  58. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/understanding/temporal.py +0 -0
  59. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/__init__.py +0 -0
  60. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/_identity.py +0 -0
  61. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/analyzer.py +0 -0
  62. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/detectors.py +0 -0
  63. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/models.py +0 -0
  64. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/sampling.py +0 -0
  65. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/ai/video_analysis/source_metadata.py +0 -0
  66. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/audio/__init__.py +0 -0
  67. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/audio/analysis.py +0 -0
  68. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/audio/audio.py +0 -0
  69. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/__init__.py +0 -0
  70. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/_dimensions.py +0 -0
  71. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/_video_io.py +0 -0
  72. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/description.py +0 -0
  73. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/draw_detections.py +0 -0
  74. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/Anton-OFL.txt +0 -0
  75. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/Anton-Regular.ttf +0 -0
  76. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/BebasNeue-OFL.txt +0 -0
  77. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/BebasNeue-Regular.ttf +0 -0
  78. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/DejaVuSans.ttf +0 -0
  79. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/LICENSE_DEJAVU +0 -0
  80. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/Lato-Bold.ttf +0 -0
  81. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/Lato-OFL.txt +0 -0
  82. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/Poppins-Bold.ttf +0 -0
  83. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/Poppins-OFL.txt +0 -0
  84. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/fonts/__init__.py +0 -0
  85. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/transcription.py +0 -0
  86. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/base/video.py +0 -0
  87. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/__init__.py +0 -0
  88. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/_ass.py +0 -0
  89. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/_easing.py +0 -0
  90. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/_schema.py +0 -0
  91. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/audio_ops.py +0 -0
  92. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/effects.py +0 -0
  93. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/errors.py +0 -0
  94. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/operation.py +0 -0
  95. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/progress.py +0 -0
  96. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/streaming.py +0 -0
  97. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/transcription_overlay.py +0 -0
  98. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/transforms.py +0 -0
  99. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/editing/video_edit.py +0 -0
  100. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/mcp/__init__.py +0 -0
  101. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/mcp/_models.py +0 -0
  102. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/mcp/server.py +0 -0
  103. {videopython-0.62.1 → videopython-0.62.3}/src/videopython/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: videopython
3
- Version: 0.62.1
3
+ Version: 0.62.3
4
4
  Summary: LLM-friendly Python video editing with JSON plans, local AI, and MCP tools.
5
5
  Project-URL: Homepage, https://videopython.com
6
6
  Project-URL: Repository, https://github.com/bartwojtowicz/videopython/
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.14
19
19
  Requires-Python: <3.15,>=3.11
20
20
  Requires-Dist: numpy>=1.25.2
21
21
  Requires-Dist: opencv-python-headless>=4.9.0.80
22
- Requires-Dist: pillow>=12.1.1
22
+ Requires-Dist: pillow>=13.0.0
23
23
  Requires-Dist: pydantic>=2.8.0
24
24
  Requires-Dist: resvg-py>=0.3.2
25
25
  Requires-Dist: soxr>=0.5
@@ -46,7 +46,7 @@ Requires-Dist: videopython-chatterbox>=0.1.7.post2; extra == 'ai'
46
46
  Provides-Extra: mcp
47
47
  Requires-Dist: faster-whisper>=1.2.1; extra == 'mcp'
48
48
  Requires-Dist: imagehash>=4.3; extra == 'mcp'
49
- Requires-Dist: mcp<2,>=1.27; extra == 'mcp'
49
+ Requires-Dist: mcp<2,>=1.30; extra == 'mcp'
50
50
  Requires-Dist: ollama>=0.5.0; extra == 'mcp'
51
51
  Requires-Dist: torch>=2.8.0; extra == 'mcp'
52
52
  Requires-Dist: torchvision>=0.23.0; extra == 'mcp'
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "videopython"
3
- version = "0.62.1"
3
+ version = "0.62.3"
4
4
  description = "LLM-friendly Python video editing with JSON plans, local AI, and MCP tools."
5
5
  authors = [
6
6
  { name = "Bartosz Wójtowicz", email = "bartoszwojtowicz@outlook.com" },
@@ -41,7 +41,7 @@ dependencies = [
41
41
  "numpy>=1.25.2",
42
42
  "soxr>=0.5", # polyphase resampling for Audio.resample; the engine librosa uses
43
43
  "opencv-python-headless>=4.9.0.80",
44
- "pillow>=12.1.1",
44
+ "pillow>=13.0.0",
45
45
  "resvg-py>=0.3.2",
46
46
  "tqdm>=4.66.3",
47
47
  "pydantic>=2.8.0",
@@ -50,7 +50,7 @@ dependencies = [
50
50
  [dependency-groups]
51
51
  dev = [
52
52
  "imagehash>=4.3",
53
- "mcp>=1.27,<2",
53
+ "mcp>=1.30,<2",
54
54
  "pre-commit>=3.8.0",
55
55
  "pyloudnorm>=0.1.1",
56
56
  "ruff>=0.1.14",
@@ -122,7 +122,7 @@ ai = [
122
122
  # Agent-editing pipeline: analysis + AI editing operations, without generation,
123
123
  # dubbing, diarization, source separation, or TTS. Pin MCP <2 — v2 is breaking.
124
124
  mcp = [
125
- "mcp>=1.27,<2",
125
+ "mcp>=1.30,<2",
126
126
  "faster-whisper>=1.2.1",
127
127
  "transnetv2-pytorch>=1.0.5",
128
128
  "transformers>=5.2.0",
@@ -171,8 +171,7 @@ ignore_missing_imports = true
171
171
  # No overrides, deliberately: they are a uv workspace feature and do not ship in
172
172
  # the wheel, so anything patched here is invisible to `pip install`. Fix the
173
173
  # dependency's metadata instead — see DEVELOPMENT.md "Dependencies".
174
- # requests: CVE floor. pygments <2.20.0: 2.20.0 breaks mkdocs (passes None to html.escape).
175
- constraint-dependencies = ["requests>=2.33.0", "pygments>=2.19.2,<2.20.0"]
174
+ constraint-dependencies = ["requests>=2.33.0", "pygments>=2.21.0"]
176
175
 
177
176
  [build-system]
178
177
  requires = ["hatchling"]
@@ -2,12 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import json
5
6
  import logging
6
7
  from pathlib import Path
7
8
  from typing import TYPE_CHECKING, Any, Callable
8
9
 
9
10
  from videopython.ai.dubbing.config import DubbingConfig
10
- from videopython.ai.dubbing.models import DubbingResult, RevoiceResult
11
+ from videopython.ai.dubbing.models import DubbingResult, RevoiceResult, TranslatedSegment
11
12
 
12
13
  if TYPE_CHECKING:
13
14
  from videopython.ai.dubbing._tts_backend import SpeechBackend
@@ -118,6 +119,88 @@ class VideoDubber:
118
119
  )
119
120
  return video.add_audio(result.dubbed_audio, overlay=False)
120
121
 
122
+ @staticmethod
123
+ def _load_translation_file(
124
+ translation_path: Path,
125
+ target_lang: str,
126
+ ) -> tuple[Any, list[TranslatedSegment], list[int], str]:
127
+ from videopython.base.transcription import Transcription
128
+
129
+ payload = json.loads(translation_path.read_text(encoding="utf-8"))
130
+ if payload["format_version"] != 1:
131
+ raise ValueError(f"Unsupported translation file version: {payload['format_version']}")
132
+ if payload["target_lang"] != target_lang:
133
+ raise ValueError(f"Translation file targets {payload['target_lang']!r}, not {target_lang!r}")
134
+
135
+ transcription = Transcription.model_validate(payload["transcription"])
136
+ segments = [TranslatedSegment.model_validate(value) for value in payload["segments"]]
137
+ failures = []
138
+ for source_index in payload["translation_failures"]:
139
+ affected = [
140
+ segment
141
+ for segment in segments
142
+ if segment.source_segment_index == source_index
143
+ and any(character.isalnum() for character in segment.original_text)
144
+ ]
145
+ if not affected or any(not segment.translated_text.strip() for segment in affected):
146
+ failures.append(source_index)
147
+ return transcription, segments, failures, payload["source_lang"]
148
+
149
+ def prepare_dub_file(
150
+ self,
151
+ input_path: str | Path,
152
+ target_lang: str,
153
+ translation_path: str | Path,
154
+ source_lang: str | None = None,
155
+ enable_diarization: bool = False,
156
+ progress_callback: Callable[[str, float], None] | None = None,
157
+ transcription: Any = None,
158
+ ) -> Path:
159
+ """Write an editable translation file without synthesizing speech.
160
+
161
+ Edit only ``segments[].translated_text`` in the returned file, then pass
162
+ it to :meth:`dub_file` as ``translation_path``.
163
+ """
164
+ from videopython.audio import Audio
165
+
166
+ input_path = Path(input_path)
167
+ translation_path = Path(translation_path)
168
+ if not input_path.exists():
169
+ raise FileNotFoundError(f"Input video not found: {input_path}")
170
+
171
+ source_audio = Audio.from_path(input_path)
172
+ if self._local_pipeline is None:
173
+ self._init_local_pipeline()
174
+ source_transcription, translated_segments, failures, detected_lang = self._local_pipeline.prepare_translation(
175
+ source_audio=source_audio,
176
+ target_lang=target_lang,
177
+ source_lang=source_lang,
178
+ enable_diarization=enable_diarization,
179
+ progress_callback=progress_callback,
180
+ transcription=transcription,
181
+ )
182
+ translation_path.parent.mkdir(parents=True, exist_ok=True)
183
+ translation_path.write_text(
184
+ json.dumps(
185
+ {
186
+ "format_version": 1,
187
+ "instructions": (
188
+ "Edit only segments[].translated_text, then pass this file to dub_file as translation_path."
189
+ ),
190
+ "source_lang": detected_lang,
191
+ "target_lang": target_lang,
192
+ "transcription": source_transcription.model_dump(mode="json"),
193
+ "segments": [segment.model_dump(mode="json") for segment in translated_segments],
194
+ "translation_failures": failures,
195
+ },
196
+ ensure_ascii=False,
197
+ indent=2,
198
+ sort_keys=True,
199
+ ),
200
+ encoding="utf-8",
201
+ )
202
+ return translation_path
203
+
121
204
  def dub_file(
122
205
  self,
123
206
  input_path: str | Path,
@@ -129,6 +212,7 @@ class VideoDubber:
129
212
  enable_diarization: bool = False,
130
213
  progress_callback: Callable[[str, float], None] | None = None,
131
214
  transcription: Any = None,
215
+ translation_path: str | Path | None = None,
132
216
  keep_original_audio: bool = False,
133
217
  ) -> DubbingResult:
134
218
  """Dub a video file in place on disk without loading video frames into memory.
@@ -156,6 +240,9 @@ class VideoDubber:
156
240
  step. Speaker labels on the supplied transcription drive per-speaker
157
241
  voice cloning. If it has no speakers, pass ``enable_diarization=True``
158
242
  to add them via pyannote (requires word-level timings).
243
+ translation_path: Translation JSON from :meth:`prepare_dub_file`. When
244
+ provided, its transcription and reviewed translations replace
245
+ ``transcription`` and skip Whisper and translation.
159
246
  keep_original_audio: If True, retain the source audio in the output
160
247
  as a secondary track behind the dubbed one (editorial A/B).
161
248
 
@@ -175,6 +262,16 @@ class VideoDubber:
175
262
  logger.info("dub_file: loading audio from %s", input_path)
176
263
  source_audio = Audio.from_path(input_path)
177
264
 
265
+ translated_segments = None
266
+ translation_failures = None
267
+ if translation_path is not None:
268
+ transcription, translated_segments, translation_failures, prepared_source_lang = (
269
+ self._load_translation_file(Path(translation_path), target_lang)
270
+ )
271
+ if source_lang is not None and source_lang != prepared_source_lang:
272
+ raise ValueError(f"Translation file uses source language {prepared_source_lang!r}, not {source_lang!r}")
273
+ source_lang = prepared_source_lang
274
+
178
275
  if self._local_pipeline is None:
179
276
  self._init_local_pipeline()
180
277
 
@@ -187,6 +284,8 @@ class VideoDubber:
187
284
  enable_diarization=enable_diarization,
188
285
  progress_callback=progress_callback,
189
286
  transcription=transcription,
287
+ translated_segments=translated_segments,
288
+ translation_failures=translation_failures,
190
289
  )
191
290
 
192
291
  # Stream the dubbed Audio directly into ffmpeg via stdin instead of
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any, Callable
10
10
  from videopython.ai.dubbing import audio_ops, voice_sample
11
11
  from videopython.ai.dubbing.config import DubbingConfig
12
12
  from videopython.ai.dubbing.models import DubbingResult, Expressiveness, RevoiceResult, SeparatedAudio, TimingSummary
13
- from videopython.ai.dubbing.quality import GarbageTranscriptError, assess_transcript
13
+ from videopython.ai.dubbing.quality import GarbageTranscriptError, TranscriptQuality, assess_transcript
14
14
  from videopython.ai.dubbing.timing import TimingSynchronizer
15
15
  from videopython.ai.dubbing.translation import DEFAULT_TRANSLATION_MODEL, OllamaTranslator
16
16
 
@@ -291,6 +291,97 @@ class LocalDubbingPipeline:
291
291
  final_audio = dubbed_speech
292
292
  return audio_ops.loudness_match(final_audio, source_audio)
293
293
 
294
+ def _resolve_transcription(
295
+ self,
296
+ source_audio: Audio,
297
+ enable_diarization: bool,
298
+ transcription: Any | None,
299
+ report_progress: Callable[[str, float], None],
300
+ ) -> Transcription:
301
+ if transcription is not None:
302
+ report_progress("Using provided transcription", 0.05)
303
+ if transcription.speakers:
304
+ logger.info(
305
+ "Using provided transcription: %d segment(s), %d speaker(s)",
306
+ len(transcription.segments),
307
+ len(transcription.speakers),
308
+ )
309
+ if enable_diarization:
310
+ logger.info("enable_diarization=True ignored: supplied transcription already has speaker labels.")
311
+ elif enable_diarization:
312
+ report_progress("Diarizing supplied transcription", 0.10)
313
+ if self._transcriber is None or self._transcriber_diarization is not True:
314
+ self._init_transcriber(enable_diarization=True)
315
+ self._transcriber_diarization = True
316
+ transcription = self._transcriber.diarize_transcription(source_audio, transcription)
317
+ self._maybe_unload("_transcriber")
318
+ logger.info(
319
+ "Diarized supplied transcription: %d segment(s), %d speaker(s)",
320
+ len(transcription.segments),
321
+ len(transcription.speakers),
322
+ )
323
+ else:
324
+ logger.info(
325
+ "Using provided transcription: %d segment(s), no speaker labels. "
326
+ "All segments will share a single voice clone. Pass "
327
+ "enable_diarization=True to add per-speaker labels, or "
328
+ "voice_clone=False to use the default TTS voice.",
329
+ len(transcription.segments),
330
+ )
331
+ else:
332
+ report_progress("Transcribing audio", 0.05)
333
+ transcription = self._transcribe(source_audio, enable_diarization)
334
+ return transcription
335
+
336
+ def _assess_transcription(self, transcription: Transcription, source_audio: Audio) -> TranscriptQuality:
337
+ quality = assess_transcript(transcription, source_audio.metadata.duration_seconds)
338
+ if quality.recommendation == "reject" and self.config.strict_quality:
339
+ raise GarbageTranscriptError(
340
+ f"Refusing to dub: {', '.join(quality.flags)}",
341
+ quality,
342
+ )
343
+ if quality.recommendation in ("warn", "reject"):
344
+ logger.warning(
345
+ "Transcript quality flags raised: %s (recommendation=%s)",
346
+ ", ".join(quality.flags),
347
+ quality.recommendation,
348
+ )
349
+ return quality
350
+
351
+ def prepare_translation(
352
+ self,
353
+ source_audio: Audio,
354
+ target_lang: str,
355
+ source_lang: str | None = None,
356
+ enable_diarization: bool = False,
357
+ progress_callback: Callable[[str, float], None] | None = None,
358
+ transcription: Any | None = None,
359
+ ) -> tuple[Transcription, list[TranslatedSegment], list[int], str]:
360
+ """Transcribe and translate without separating or synthesizing audio."""
361
+
362
+ def report_progress(stage: str, progress: float) -> None:
363
+ if progress_callback:
364
+ progress_callback(stage, progress)
365
+
366
+ transcription = self._resolve_transcription(
367
+ source_audio,
368
+ enable_diarization,
369
+ transcription,
370
+ report_progress,
371
+ )
372
+ detected_lang = source_lang or transcription.language or "en"
373
+ if not transcription.segments:
374
+ translated_segments: list[TranslatedSegment] = []
375
+ translation_failures: list[int] = []
376
+ else:
377
+ self._assess_transcription(transcription, source_audio)
378
+ report_progress("Translating text", 0.35)
379
+ translated_segments, translation_failures = self._translate(
380
+ transcription, detected_lang, target_lang, report_progress
381
+ )
382
+ report_progress("Translation ready for review", 1.0)
383
+ return transcription, translated_segments, translation_failures, detected_lang
384
+
294
385
  def process(
295
386
  self,
296
387
  source_audio: Audio,
@@ -301,6 +392,8 @@ class LocalDubbingPipeline:
301
392
  enable_diarization: bool = False,
302
393
  progress_callback: Callable[[str, float], None] | None = None,
303
394
  transcription: Any | None = None,
395
+ translated_segments: list[TranslatedSegment] | None = None,
396
+ translation_failures: list[int] | None = None,
304
397
  ) -> DubbingResult:
305
398
  """Run the dubbing pipeline against the given source audio.
306
399
 
@@ -327,39 +420,12 @@ class LocalDubbingPipeline:
327
420
  if progress_callback:
328
421
  progress_callback(stage, progress)
329
422
 
330
- if transcription is not None:
331
- report_progress("Using provided transcription", 0.05)
332
- if transcription.speakers:
333
- logger.info(
334
- "Using provided transcription: %d segment(s), %d speaker(s)",
335
- len(transcription.segments),
336
- len(transcription.speakers),
337
- )
338
- if enable_diarization:
339
- logger.info("enable_diarization=True ignored: supplied transcription already has speaker labels.")
340
- elif enable_diarization:
341
- report_progress("Diarizing supplied transcription", 0.10)
342
- if self._transcriber is None or self._transcriber_diarization is not True:
343
- self._init_transcriber(enable_diarization=True)
344
- self._transcriber_diarization = True
345
- transcription = self._transcriber.diarize_transcription(source_audio, transcription)
346
- self._maybe_unload("_transcriber")
347
- logger.info(
348
- "Diarized supplied transcription: %d segment(s), %d speaker(s)",
349
- len(transcription.segments),
350
- len(transcription.speakers),
351
- )
352
- else:
353
- logger.info(
354
- "Using provided transcription: %d segment(s), no speaker labels. "
355
- "All segments will share a single voice clone. Pass "
356
- "enable_diarization=True to add per-speaker labels, or "
357
- "voice_clone=False to use the default TTS voice.",
358
- len(transcription.segments),
359
- )
360
- else:
361
- report_progress("Transcribing audio", 0.05)
362
- transcription = self._transcribe(source_audio, enable_diarization)
423
+ transcription = self._resolve_transcription(
424
+ source_audio,
425
+ enable_diarization and translated_segments is None,
426
+ transcription,
427
+ report_progress,
428
+ )
363
429
 
364
430
  if not transcription.segments:
365
431
  return DubbingResult(
@@ -370,22 +436,7 @@ class LocalDubbingPipeline:
370
436
  target_lang=target_lang,
371
437
  )
372
438
 
373
- # Cheap heuristic gate before the expensive Demucs/translation/TTS
374
- # stages. Lets strict_quality callers refuse-and-refund without
375
- # running the rest of the pipeline; non-strict runs continue but
376
- # surface the assessment on DubbingResult.
377
- transcript_quality = assess_transcript(transcription, source_audio.metadata.duration_seconds)
378
- if transcript_quality.recommendation == "reject" and self.config.strict_quality:
379
- raise GarbageTranscriptError(
380
- f"Refusing to dub: {', '.join(transcript_quality.flags)}",
381
- transcript_quality,
382
- )
383
- if transcript_quality.recommendation in ("warn", "reject"):
384
- logger.warning(
385
- "Transcript quality flags raised: %s (recommendation=%s)",
386
- ", ".join(transcript_quality.flags),
387
- transcript_quality.recommendation,
388
- )
439
+ transcript_quality = self._assess_transcription(transcription, source_audio)
389
440
 
390
441
  detected_lang = source_lang or transcription.language or "en"
391
442
 
@@ -403,10 +454,14 @@ class LocalDubbingPipeline:
403
454
  report_progress("Extracting voice samples", 0.25)
404
455
  voice_samples = voice_sample.extract(vocal_audio, background_audio, transcription)
405
456
 
406
- report_progress("Translating text", 0.35)
407
- translated_segments, translation_failures = self._translate(
408
- transcription, detected_lang, target_lang, report_progress
409
- )
457
+ if translated_segments is None:
458
+ report_progress("Translating text", 0.35)
459
+ translated_segments, translation_failures = self._translate(
460
+ transcription, detected_lang, target_lang, report_progress
461
+ )
462
+ else:
463
+ report_progress("Using reviewed translation", 0.50)
464
+ translation_failures = translation_failures if translation_failures is not None else []
410
465
 
411
466
  # Per-segment expressiveness derived from source vocals RMS.
412
467
  # Computed before vocal_audio is released so the TTS loop doesn't
File without changes
File without changes
File without changes