-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_ep01_v7.py
More file actions
66 lines (54 loc) · 2.12 KB
/
Copy pathgen_ep01_v7.py
File metadata and controls
66 lines (54 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""Generate EP01 final v7 with updated character voices."""
import json, os, sys, io, time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from b2p.tts import synthesize_chunk, pcm16_to_wav, load_character_voices
from pydub import AudioSegment
base = Path(__file__).parent / "output" / "musk"
chars = load_character_voices(base / "characters.yaml")
with open(base / "scripts" / "ep01_chunks_v3.json") as f:
chunks = json.load(f)
print(f"EP01: {len(chunks)} chunks, starting synthesis...", flush=True)
cache_dir = base / "audio" / ".cache_ep01_v7"
cache_dir.mkdir(exist_ok=True)
silence = AudioSegment.silent(duration=180)
final = AudioSegment.empty()
cached = 0
rendered = 0
errors = 0
for i, chunk in enumerate(chunks):
speaker = chunk.get("speaker", "")
text = chunk.get("text", "")
voice_info = chars.get(speaker, {})
cache_file = cache_dir / f"{i:04d}.wav"
if cache_file.exists() and cache_file.stat().st_size > 0:
cached += 1
seg = AudioSegment.from_file(str(cache_file), format="wav")
else:
print(f" [{i+1}/{len(chunks)}] {speaker}: {text[:40]}...", flush=True)
try:
pcm = synthesize_chunk(
text=text,
voice=voice_info.get("voice_design", ""),
style_tags=voice_info.get("mimo_style_tags", ""),
)
wav = pcm16_to_wav(pcm)
cache_file.write_bytes(wav)
buf = io.BytesIO(wav)
seg = AudioSegment.from_file(buf, format="wav")
rendered += 1
except Exception as e:
print(f" ❌ Error at chunk {i}: {e}", flush=True)
seg = AudioSegment.silent(duration=1000)
errors += 1
time.sleep(0.15)
final += seg
if i < len(chunks) - 1:
final += silence
output_path = base / "audio" / "ep01_final_v7.mp3"
final.export(str(output_path), format="mp3", bitrate="192k")
dur = len(final) / 1000
print(f"\n✅ Done! {output_path}")
print(f" Duration: {dur:.0f}s ({dur/60:.1f}min)")
print(f" Cached: {cached}, Rendered: {rendered}, Errors: {errors}, Total: {len(chunks)}")