Download code/ref15_fullft/script_only.py from laion/Humaneness-Voice-Small: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/laion/Humaneness-Voice-Small/resolve/main/code/ref15_fullft/script_only.py
- Command line
-
hf download hf://laion/Humaneness-Voice-Small/code/ref15_fullft/script_only.py
-
curl -L -o script_only.py https://huggingface.co/laion/Humaneness-Voice-Small/resolve/main/code/ref15_fullft/script_only.py
2.66 kB
| """The exact caption-free, reference-conditioned S3 prompt surface. | |
| Keep the inherited sentence-local performance cues, timing, pauses and vocal | |
| bursts; remove the entire GENERAL block and all global/body captions. The | |
| reference codec is provided separately through ScorePacker reference mode. | |
| """ | |
| from __future__ import annotations | |
| import re | |
| from timed_prompt import repair_prompt | |
| RENDERER_VERSION = 'hvs-script-only-source-cue-filter-v2' | |
| _STATIC = re.compile( | |
| r"\b(?:male|female|masculine|feminine|gender|adult|teen|teenage|young|" | |
| r"middle.?aged|elderly|old|child|childlike|baby|androgynous|" | |
| r"woman|man|girl|boy|accent|register|pitch(?:ed)?|" | |
| r"raspy|husky|nasal|heady|hoarse|gravelly|breathy|airy|resonan\w*|" | |
| r"baritone|soprano|tenor|alto|bass|deep.?voice|thin.?voice|thick.?voice)\b", | |
| re.I) | |
| _LEGACY_LEADING_CUE = re.compile(r"^(\s*)\(([^()\n]+)\)(?=\s|$)") | |
| def _without_static_cue(match, removed): | |
| tags = [tag.strip() for tag in match.group(2).split(',') if tag.strip()] | |
| dynamic = [tag for tag in tags if not _STATIC.search(tag)] | |
| removed[0] += len(tags) - len(dynamic) | |
| return f"({', '.join(dynamic)})" if dynamic else "" | |
| def script_only(meta: dict, base_index: int) -> tuple[str, dict]: | |
| # Filter only cues in the *source* prompt before rendering. Filtering the | |
| # rendered script is unsafe: its first parenthesis may be the actual target | |
| # audio's only event, e.g. a 0.6 s giggle with no aligned speech. | |
| source_prompt = str(meta.get("prompt") or "") | |
| removed = [0] | |
| if "SCRIPT:\n" in source_prompt: | |
| head, legacy_script = source_prompt.split("SCRIPT:\n", 1) | |
| lines = [] | |
| for line in legacy_script.splitlines(): | |
| lines.append(_LEGACY_LEADING_CUE.sub( | |
| lambda m: m.group(1) + _without_static_cue(m, removed), line, | |
| count=1)) | |
| source_prompt = head + "SCRIPT:\n" + "\n".join(lines) | |
| filtered_meta = dict(meta, prompt=source_prompt) | |
| repaired, facts = repair_prompt( | |
| filtered_meta, caption=None, form="A", mode="reference", | |
| presentation=int(base_index), phase="S3") | |
| marker = "SCRIPT:\n" | |
| if marker not in repaired: | |
| raise ValueError(f"No structured SCRIPT in {meta['uid']}") | |
| body = repaired.split(marker, 1)[1].strip() | |
| body = body.strip() | |
| if not body or "GENERAL:" in body or "CAPTION:" in body or "TRANSCRIPT:" in body: | |
| raise ValueError(f"Leaked caption/header in {meta['uid']}") | |
| if not meta.get("text"): | |
| raise ValueError(f"Empty transcript in {meta['uid']}") | |
| facts = dict(facts, stable_voice_tags_removed=removed[0]) | |
| return body, facts | |