Voice mother with Carol and synchronize all call events
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
"""Install verified, word-aligned Carol/Jessica batches; no network/API calls."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import shutil
|
||||
import wave
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
WORK = ROOT / "builds/carol"
|
||||
GAME = ROOT / "do-otboy"
|
||||
|
||||
def read(path):
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
def write(path, data):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||||
|
||||
def main():
|
||||
story = read(GAME / "data/phone_story.json")
|
||||
score = {line["id"]: line for line in read(ROOT / "voiceover/performance.json")["lines"]}
|
||||
assembly = read(WORK / "assembly.json")
|
||||
metadata, alignments, prepared = {}, {}, []
|
||||
# Validate everything before changing a production voice.
|
||||
for batch, source in assembly.items():
|
||||
segments = read(WORK / (batch + "_split/alignment.json"))
|
||||
alignments[batch] = segments
|
||||
for segment in segments:
|
||||
key = segment["id"]
|
||||
assert key not in metadata, key
|
||||
line = story["lines"][key]
|
||||
assert segment["text"] == line["text"], key
|
||||
assert segment["reference_words"] == segment["matched_words"], key
|
||||
path = WORK / (batch + "_split") / (key + ".wav")
|
||||
with wave.open(str(path)) as wav:
|
||||
assert wav.getsampwidth() == 2 and wav.getnchannels() == 1 and wav.getnframes() > 0
|
||||
duration = wav.getnframes() / wav.getframerate()
|
||||
metadata[key] = dict(id=key, **line, provider="ElevenLabs", **source,
|
||||
voice=source["voice_name"], file="assets/voice/" + path.name,
|
||||
source_start=segment["start"], source_end=segment["end"],
|
||||
wav_duration=round(duration, 3),
|
||||
sha256=hashlib.sha256(path.read_bytes()).hexdigest(),
|
||||
direction=score[key]["direction"], tts_text=score[key]["tts_text"],
|
||||
pronunciation=score[key]["pronunciation"])
|
||||
prepared.append((path, GAME / "assets/voice" / path.name))
|
||||
assert set(metadata) == set(story["lines"]), "All 102 lines must be ready"
|
||||
for source, destination in prepared:
|
||||
shutil.copyfile(source, destination)
|
||||
write(GAME / "data/voice_manifest.json", metadata)
|
||||
write(ROOT / "voiceover/alignment.json", alignments)
|
||||
for character, speaker in [("carol", "Мама"), ("jessica", "Катя")]:
|
||||
entries = [dict(item, file="../../do-otboy/" + item["file"])
|
||||
for item in metadata.values() if item["speaker"] == speaker]
|
||||
write(ROOT / "voiceover" / character / "manifest.json",
|
||||
dict(status="complete", version="0.2.2", voice_id=entries[0]["voice_id"],
|
||||
voice_name=entries[0]["voice_name"], ready=entries, pending=[]))
|
||||
write(ROOT / "voiceover" / character / "alignment.json",
|
||||
[entry for batch in alignments.values() for entry in batch
|
||||
if story["lines"][entry["id"]]["speaker"] == speaker])
|
||||
print("Installed", len(metadata), "directed lines: Carol 54, Jessica 48")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user