Fix narration quality: colon/semicolon normalization, 150ms leading silence, short clause merge, 0.95 soft limiter, speed=0.88/temp=0.88
Browse filesFiles changed (4)
87 unmodified lines88899091929394959697989987 unmodified linesvocoder_repo: str = "charactr/vocos-mel-24khz"# Winning Natural Smooth defaults from V1.5 evaluationdefault_speed: float = 0.92min_frames: int = 2default_steps: int = 48default_cfg_scale: float = 1.3default_temperature: float = 0.90@dataclass87 unmodified lines88899091929394959697989987 unmodified linesvocoder_repo: str = "charactr/vocos-mel-24khz"# Winning Natural Smooth defaultsdefault_speed: float = 0.88min_frames: int = 2default_steps: int = 48default_cfg_scale: float = 1.3default_temperature: float = 0.88@dataclass
454 unmodified lines455456457458459460454 unmodified linestext = unicodedata.normalize("NFC", text)text = text.replace("’", "'").replace("‘", "'")text = text.replace("।", ".").replace("॥", ".")text = re.sub(r"[“”\"()\[\]{}]", " ", text)text = re.sub(r"(?<![A-Za-z])'|'(?![A-Za-z])", " ", text)text = re.sub(r"\s+", " ", text).strip()454 unmodified lines455456457458459460461454 unmodified linestext = unicodedata.normalize("NFC", text)text = text.replace("’", "'").replace("‘", "'")text = text.replace("।", ".").replace("॥", ".")text = text.replace(":", ",").replace(";", ",")text = re.sub(r"[“”\"()\[\]{}]", " ", text)text = re.sub(r"(?<![A-Za-z])'|'(?![A-Za-z])", " ", text)text = re.sub(r"\s+", " ", text).strip()
31 unmodified lines3233343536373821 unmodified lines60616263646512 unmodified lines78798081828314 unmodified lines98991001011021031041051062 unmodified lines10911011111211311411511611711818 unmodified lines13713813914014114214321 unmodified lines1651661671681691704 unmodified lines1751761771781791801 unmodified line18218318418531 unmodified lines_SENTENCE_RE = re.compile(r".+?(?:[।॥!?]+[\"'”’)]*(?=\s|\Z)|\.[\"'”’)]*(?=\s+\S|\Z)|\Z)")def script_chunks(text, tokenizer, limit=220, language="hi"):lang_arg = None if language == "auto" else languagefor paragraph in re.split(r"\n\s*\n", text.strip()):para = paragraph.strip()21 unmodified lineswords.append(word)if words:parts.append((" ".join(words), 120))if parts:parts[-1] = (parts[-1][0], 260)yield from parts12 unmodified linesspeed=None,seed=42,language="hi",):device = next(model.parameters()).deviceemotion_id = EMOTION_TO_ID[emotion]14 unmodified linestorch.cuda.manual_seed(int(seed))with wave.open(temporary, "wb") as wav:wav.setparams((1, 2, cfg.audio.sample_rate, 0, "NONE", "not compressed"))pause = 0rendered = 0for chunk, next_pause in script_chunks(text, tokenizer, language=language):ids = tokenizer.text_to_ids(chunk, language=(None if language == "auto" else language))if not ids.numel():continue2 unmodified linesspeaker_id=int(speaker_id),emotion_id=emotion_id,speed=speed,)samples = vocoder.decode(mel)[0].float().cpu().flatten()if not samples.numel() or not torch.isfinite(samples).all():raise ValueError("Vocoder returned invalid audio")fade = min(samples.numel() // 2, cfg.audio.sample_rate // 200)if fade:ramp = torch.linspace(0, 1, fade)18 unmodified lines@torch.inference_mode()def render(checkpoint, text, destination, speaker="0", emotion="neutral", speed=None, language="hi", use_ema=True):device = torch.device("cuda" if torch.cuda.is_available() else "cpu")state = torch.load(checkpoint, map_location="cpu", weights_only=True)cfg = MurliV16Config()21 unmodified linesrender_with_model(model, tokenizer, vocoder, cfg, text, destination,speaker_id=speaker_id, emotion=emotion, speed=speed, language=language,)4 unmodified linesp.add_argument("--speaker", default="0", help="Speaker ID (default 0=syspin_male_01) or alias")p.add_argument("--emotion", choices=sorted(EMOTION_TO_ID), default="neutral")p.add_argument("--speed", type=float)p.add_argument("--language", choices=["hi", "en", "auto"], default="hi")p.add_argument("--no_ema", action="store_true", help="Use raw model weights instead of EMA weights")text_group = p.add_mutually_exclusive_group(required=True)1 unmodified linetext_group.add_argument("--text_file")args = p.parse_args()text = Path(args.text_file).read_text(encoding="utf-8") if args.text_file else args.textrender(args.checkpoint, text, args.output, args.speaker, args.emotion, args.speed, args.language, use_ema=not args.no_ema)31 unmodified lines3233343536373821 unmodified lines60616263646566676869707172737475767778798012 unmodified lines9394959697989910010114 unmodified lines1161171181191201211221231242 unmodified lines12712812913013113213313413513613713813914014114218 unmodified lines16116216316416516616721 unmodified lines1891901911921931941954 unmodified lines2002012022032042052062072081 unmodified line21021121221321421521631 unmodified lines_SENTENCE_RE = re.compile(r".+?(?:[।॥!?]+[\"'”’)]*(?=\s|\Z)|\.[\"'”’)]*(?=\s+\S|\Z)|\Z)")def script_chunks(text, tokenizer, limit=220, language="hi", merge_short=False):lang_arg = None if language == "auto" else languagefor paragraph in re.split(r"\n\s*\n", text.strip()):para = paragraph.strip()21 unmodified lineswords.append(word)if words:parts.append((" ".join(words), 120))if merge_short and len(parts) > 1:merged = []i = 0while i < len(parts):txt, gap = parts[i]if len(txt.split()) <= 3 and i + 1 < len(parts):nxt_txt, nxt_gap = parts[i + 1]combined = f"{txt} {nxt_txt}"if tokenizer.text_to_ids(combined, language=lang_arg).numel() <= limit:merged.append((combined, nxt_gap))i += 2continuemerged.append((txt, gap))i += 1parts = mergedif parts:parts[-1] = (parts[-1][0], 260)yield from parts12 unmodified linesspeed=None,seed=42,language="hi",steps=None,cfg_scale=None,temperature=None,):device = next(model.parameters()).deviceemotion_id = EMOTION_TO_ID[emotion]14 unmodified linestorch.cuda.manual_seed(int(seed))with wave.open(temporary, "wb") as wav:wav.setparams((1, 2, cfg.audio.sample_rate, 0, "NONE", "not compressed"))pause = 150rendered = 0for chunk, next_pause in script_chunks(text, tokenizer, language=language, merge_short=True):ids = tokenizer.text_to_ids(chunk, language=(None if language == "auto" else language))if not ids.numel():continue2 unmodified linesspeaker_id=int(speaker_id),emotion_id=emotion_id,speed=speed,steps=steps,cfg_scale=cfg_scale,temperature=temperature,)samples = vocoder.decode(mel)[0].float().cpu().flatten()if not samples.numel() or not torch.isfinite(samples).all():raise ValueError("Vocoder returned invalid audio")peak = float(samples.abs().max())if peak > 0.95:samples = samples * (0.95 / peak)fade = min(samples.numel() // 2, cfg.audio.sample_rate // 200)if fade:ramp = torch.linspace(0, 1, fade)18 unmodified lines@torch.inference_mode()def render(checkpoint, text, destination, speaker="0", emotion="neutral", speed=None, language="hi", use_ema=True, steps=None, cfg_scale=None, temperature=None):device = torch.device("cuda" if torch.cuda.is_available() else "cpu")state = torch.load(checkpoint, map_location="cpu", weights_only=True)cfg = MurliV16Config()21 unmodified linesrender_with_model(model, tokenizer, vocoder, cfg, text, destination,speaker_id=speaker_id, emotion=emotion, speed=speed, language=language,steps=steps, cfg_scale=cfg_scale, temperature=temperature,)4 unmodified linesp.add_argument("--speaker", default="0", help="Speaker ID (default 0=syspin_male_01) or alias")p.add_argument("--emotion", choices=sorted(EMOTION_TO_ID), default="neutral")p.add_argument("--speed", type=float)p.add_argument("--steps", type=int)p.add_argument("--cfg_scale", type=float)p.add_argument("--temperature", type=float)p.add_argument("--language", choices=["hi", "en", "auto"], default="hi")p.add_argument("--no_ema", action="store_true", help="Use raw model weights instead of EMA weights")text_group = p.add_mutually_exclusive_group(required=True)1 unmodified linetext_group.add_argument("--text_file")args = p.parse_args()text = Path(args.text_file).read_text(encoding="utf-8") if args.text_file else args.textrender(args.checkpoint, text, args.output, args.speaker, args.emotion, args.speed,args.language, use_ema=not args.no_ema, steps=args.steps, cfg_scale=args.cfg_scale, temperature=args.temperature,)
266 unmodified lines267268269270271272266 unmodified linesself.assertTrue(torch.isfinite(mel_batch).all())chunks = list(script_chunks("नमस्ते! आज मौसम अच्छा है।\n\nचलो चलते हैं।", tok))self.assertEqual(len(chunks), 3)abbr_chunks = list(script_chunks('Dr. Rao arrived early. "Hello!"', tok, language="en"))self.assertEqual(len(abbr_chunks), 2)self.assertEqual(abbr_chunks[0][0], "Dr. Rao arrived early.")266 unmodified lines267268269270271272273274275266 unmodified linesself.assertTrue(torch.isfinite(mel_batch).all())chunks = list(script_chunks("नमस्ते! आज मौसम अच्छा है।\n\nचलो चलते हैं।", tok))self.assertEqual(len(chunks), 3)merged_chunks = list(script_chunks("नमस्ते! आज मौसम अच्छा है।\n\nचलो चलते हैं।", tok, merge_short=True))self.assertEqual(len(merged_chunks), 2)self.assertNotIn(":", tok.clean_text("नाम है: पुराना; नया"))abbr_chunks = list(script_chunks('Dr. Rao arrived early. "Hello!"', tok, language="en"))self.assertEqual(len(abbr_chunks), 2)self.assertEqual(abbr_chunks[0][0], "Dr. Rao arrived early.")
config.py+3-3
data/text_cleaner.py+1
narrate.py+36-5
tests/test_v16.py+3