"""Numbers MeloTTS's Korean front end reads wrongly are spelled out before it sees them: a number it cannot tag as a counter is read digit by digit ("60%" as "육영퍼센트"), and every dot or comma is a sentence break for it ("4.2미터" as "사. 이미터").""" from __future__ import annotations import json import os import struct import subprocess import sys import textwrap import pytest from voice_worker import melo_child from voice_worker.melo_child import spell_numbers_kr @pytest.mark.unit @pytest.mark.parametrize("text, spoken", [ ("습도 60%입니다.", "습도 육십%입니다."), ("습도 60퍼센트", "습도 육십퍼센트"), ("바람 초속 4.2미터", "바람 초속 사점이미터"), ("최고 25.5도, 최저 0.5도", "최고 이십오점오도, 최저 영점오도"), ("11월 19일, 2026년", "십일월 십구일, 이천이십육년"), ("1,234명", "천이백삼십사명"), ("10 100 1000 10000 110 20만 100000000", "십 백 천 만 백십 이십만 일억"), ("0, 7", "영, 칠"), ]) def test_numbers_are_spelled_as_they_are_read(text, spoken): assert spell_numbers_kr(text) == spoken @pytest.mark.unit def test_numbers_before_native_counters_are_left_for_melo_to_read_natively(): # "3시" is "세시", "10개" is "열개", "5시간" is "다섯시간": MeloTTS's own counter rule reads these. text = "3시 10개 5시간 2마리" assert spell_numbers_kr(text) == text FAKE_MELO = textwrap.dedent(""" import os import numpy as np class _Hps: class data: spk2id = {"KR": 0} sampling_rate = 48000 class TTS: def __init__(self, language, device): self.hps = _Hps def tts_to_file(self, text, speaker, path, speed=1.0, quiet=True): with open(os.environ["FAKE_MELO_LOG"], "a", encoding="utf-8") as f: f.write(text + "\\n") return np.zeros(10) """) def read_frame(stream) -> dict: (n,) = struct.unpack("