feat: improve library and audiobook workflow
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Apply the duration-aware export fix to the installed VoiceStudio router."""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
source = path.read_text(encoding='utf-8')
|
||||
old = ''' await run_ffmpeg(
|
||||
build_render_cmd('''
|
||||
new = ''' # Long audiobooks can take hours to encode on the CMP CPU.
|
||||
# Keep a bounded timeout proportional to the prepared audio duration.
|
||||
encode_timeout = min(21600.0, max(1800.0,
|
||||
sum(d for _, d in chapters_meta) / 1000.0 * 0.5))
|
||||
returncode, _, encode_error = await run_ffmpeg(
|
||||
build_render_cmd('''
|
||||
tail = ''' job_id=job_id,
|
||||
)
|
||||
|
||||
if job_store is not None:'''
|
||||
replacement = ''' job_id=job_id, timeout=encode_timeout,
|
||||
)
|
||||
if returncode != 0:
|
||||
logger.error("[%s] ffmpeg export failed: %s", job_id,
|
||||
(encode_error or b"").decode(errors="replace")[-2000:])
|
||||
raise RuntimeError("Audio export failed")
|
||||
|
||||
if job_store is not None:'''
|
||||
if 'encode_timeout = min(21600.0' not in source:
|
||||
assert source.count(old) == 1
|
||||
assert source.count(tail) == 1
|
||||
backup = path.with_suffix('.py.before-duration-timeout')
|
||||
if not backup.exists():
|
||||
backup.write_text(source, encoding='utf-8')
|
||||
source = source.replace(old, new).replace(tail, replacement)
|
||||
compile(source, str(path), 'exec')
|
||||
path.write_text(source, encoding='utf-8')
|
||||
Reference in New Issue
Block a user