Compare commits
12 Commits
app-v0.1.3
...
app-v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c816358552 | ||
|
|
9f5f3d891f | ||
|
|
04c23f9bf7 | ||
|
|
49050b18a9 | ||
|
|
9f62bfb059 | ||
|
|
e428aad58a | ||
|
|
a665dd8d21 | ||
|
|
a5afdbb221 | ||
|
|
9199ccbd0e | ||
|
|
2a95f58a0e | ||
|
|
81d1e26f61 | ||
|
|
88ee5ec2cb |
2
app/Cargo.lock
generated
2
app/Cargo.lock
generated
@@ -1520,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.30"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.30"
|
||||
version = "0.1.35"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
|
||||
|
||||
4
app/shell/Cargo.lock
generated
4
app/shell/Cargo.lock
generated
@@ -2637,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.30"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
@@ -2666,7 +2666,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.30"
|
||||
version = "0.1.35"
|
||||
dependencies = [
|
||||
"jarvis-app",
|
||||
"serde_json",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.30"
|
||||
version = "0.1.35"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
- **게임 중 LLM이 답하는 동안**: STT와 LLM은 같은 GPU를 씁니다. 10명이 쉬지 않고 말하며 부분 전사를 계속 돌리면 LLM 출력이 1/2.5~1/3로 줄었습니다(M0 `gamemode_stt`). 그래서 게임 중에 LLM이 답을 만드는 동안에는 부분 전사를 멈추고(그동안 실시간 자막이 바뀌지 않음), 말이 끝난 뒤의 최종 전사는 기다리지 않고 바로 처리합니다. 게임이 없을 때는 LLM이 답하는 동안에도 부분 전사를 그대로 합니다(사용자 결정, 2026-11-10). 최종 전사가 부분 전사보다 먼저입니다. 멈추기로 한 것은 M0 `gamemode_tune` 측정 결과입니다(2026-11-11): 2초 간격은 37.5 tok/s, 음성 첫 문장 0.89초에 최종 전사 대기가 최대 1.2초였고, 멈추면 64.9 tok/s, 0.55초였습니다. 부분 전사를 멈췄을 때 beam 2~3 최종 전사와 긴 말의 실제 지연은 아직 재지 않았습니다([pc-features.md](pc-features.md#자동-조절-측정-m0-gamemode_tune-2026-11-11)).
|
||||
- **부분 전사는 2명씩만 묶음(M1 실측)**: Whisper 인코더는 말 길이와 상관없이 늘 30초 창을 계산해서, 묶어도 비용이 사람 수에 비례합니다(RTX 5050에서 1명 0.2초, 10명 2.1초). 10명분 부분 전사를 한 번에 돌리면 그동안 들어온 최종 전사가 2초 넘게 기다려서, 부분 전사는 한 번에 2명까지만 돌리고 그 사이에 최종 전사가 먼저 들어가게 했습니다. 여러 명이 함께 말하면 자막은 늦어지고 사람마다 가장 최근 소리만 전사합니다. 인코더 창을 줄이면 4~7배 빨라졌지만 같은 문장을 되풀이하는 오류가 생겨 쓰지 않습니다.
|
||||
- **호출어 힌트**: 등록한 호출어를 STT에 힌트로 넘겨 잘못 알아듣는 일을 줄입니다. 힌트만 쓰면 웃음소리에서 "자비스"를 지어내거나 실제 문장 끝에 "자비스"를 붙여서(M1 측정, 2026-11-11), 힌트가 있으면 같은 소리를 힌트 없이도 한 번 더 해석해 그 결과로 판단합니다. 힌트 결과는 호출어 개수가 힌트 없는 결과와 정확히 같을 때만 쓰므로, 힌트가 호출어를 더하거나 빼거나 비슷한 말("서비스", "자비수")을 호출어로 바꾸지 못합니다. "자비수" 같은 비슷한 말을 호출어로 볼지는 호출 판정(M4)이 정합니다.
|
||||
- **음량 맞추기**: 사람마다 목소리 크기가 달라도 같은 크기로 맞춰 STT에 넣습니다. 목소리가 있는 구간만 재서 -20dBFS로 맞추고(최대 +40dB, 낮은 웅웅거림 제거, 큰 소리는 찌그러지지 않게 부드럽게 눌러 줌), 클릭이나 노크 소리가 음량을 정하지 않게 합니다. 측정하면 -60dBFS 속삭임부터 찌그러질 만큼 큰 소리까지 똑같이 받아 적었습니다.
|
||||
- **음량 맞추기**: 사람마다 목소리 크기가 달라도 같은 크기로 맞춰 STT에 넣습니다. 목소리가 있는 구간만 재서 -20dBFS로 맞추고(최대 +40dB, 낮은 웅웅거림 제거, 큰 소리는 찌그러지지 않게 부드럽게 눌러 줌), 클릭이나 노크 소리가 음량을 정하지 않게 합니다. 측정하면 -60dBFS 속삭임부터 찌그러질 만큼 큰 소리까지 똑같이 받아 적었습니다. 음량을 재기 전에 1kHz 위 자음 대역("ㅈ", "ㅅ")을 12dB 올립니다. 마이크가 어둡거나 자음과 말끝을 흘리는 사람의 말끝("어때", "틀어줘")이 덜 빠집니다(실제 디스코드 음성 25개 5.04%→3.92%, FLEURS 한국어 382개 5.11%→4.85%). 첫 자음이 아예 안 들린 "아비스"는 그대로이고, 호출 감지의 한 글자 허용이 받아 줍니다.
|
||||
- **잡음 거르기와 헛 전사 막기**: 목소리가 분명한 구간(음성 확률 0.5 이상)이 0.25초 넘게 있어야 STT를 돌립니다. 키보드, 마우스, 발소리, 청소기 같은 잡음은 여기서 걸러집니다. 기침, 웃음처럼 목소리 같은 소리는 STT까지 가지만 결과의 토큰당 평균 확신도(-0.7 이상)와 반복 여부로 거릅니다. 실제 잡음 54개(ESC-50)를 원래 크기와 -25dBFS로 넣은 108개를 호출어 힌트를 켠 워커에 넣으니 103개는 STT까지 가지 않았고, STT까지 간 5개(기침, 웃음, 울음)도 모두 빈 결과였습니다. 그 잡음 위에 말한 문장 89개는 문자 오류율 평균 4.8%였고, 남은 문제는 웃음 직후 "감사합니다." 한 번(확신도가 기준선에 걸침), 시끄러운 잡음 속 짧은 단어 2개 누락, 같은 단어 세 번 반복 한 번입니다. 이 모델(large-v3-turbo)의 "말 없음" 확률은 늘 0이라 쓰지 않습니다.
|
||||
- **RealtimeSTT 사용 범위**: RealtimeSTT는 화자 하나에 인스턴스 하나 구조라 10명이면 모델을 10번 올립니다. 그래서 설계(부분/최종 전사, VAD 결합)만 참고하고, **모델 1개를 10명이 공유하는 배치 방식**으로 직접 구현합니다.
|
||||
- **선택지**: 더 낮은 지연이 필요하면 sherpa-onnx 스트리밍 모델을 "초고속" 옵션으로 검토합니다(한국어 정확도 확인 후).
|
||||
|
||||
@@ -35,3 +35,13 @@ def debug_log(message: str, category: str = "debug") -> None:
|
||||
print(f"[{category:^10}] {message}", file=sys.stderr)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def notice(message: str, category: str = "debug") -> None:
|
||||
"""A line that is written also without debug logging, to the process's original stderr, so it
|
||||
still reaches the app's log while the voice worker mutes the reply engine's output. It must carry
|
||||
no question, answer, place or other text from the conversation."""
|
||||
try:
|
||||
print(f"[{category:^10}] {message}", file=sys.__stderr__, flush=True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta, timezone
|
||||
|
||||
import requests
|
||||
from typing import Dict, Any, Optional
|
||||
from ...debug import debug_log
|
||||
from ...debug import debug_log, notice
|
||||
from ...utils.location import get_location_info
|
||||
from ..base import Tool, ToolContext
|
||||
from ..types import ToolExecutionResult
|
||||
@@ -674,8 +674,8 @@ class WeatherTool(Tool):
|
||||
rest = [off for off in offsets if off not in days]
|
||||
if rest:
|
||||
days.update(_open_meteo_days(lat, lon, rest))
|
||||
debug_log(f" 🌤️ forecast days {first}-{last}: {from_kma} from KMA, "
|
||||
f"{len(days) - from_kma} from open-meteo", "tools")
|
||||
# Which service gave the answer, in the app's log (no place: it comes from the question).
|
||||
notice(f"weather days {first}-{last}: {from_kma} from KMA, {len(days) - from_kma} from open-meteo", "llm")
|
||||
place = location_display.split(",")[0].strip() or location_display
|
||||
return [_day_sentence(off, days[off], place, detail) for off in offsets if off in days]
|
||||
|
||||
@@ -863,12 +863,12 @@ class WeatherTool(Tool):
|
||||
}
|
||||
|
||||
current: Dict[str, Any] = {}
|
||||
source = "KMA"
|
||||
kma_key = _kma_key_now()
|
||||
if kma_key and country_code == "KR":
|
||||
current = _kma_current(lat, lon, kma_key)
|
||||
if current:
|
||||
debug_log(" 🌤️ current weather from KMA", "tools")
|
||||
if not current:
|
||||
source = "open-meteo"
|
||||
try:
|
||||
weather_response = requests.get(weather_url, params=weather_params,
|
||||
timeout=_OPEN_METEO_TIMEOUT_SEC)
|
||||
@@ -877,12 +877,14 @@ class WeatherTool(Tool):
|
||||
except Exception as e:
|
||||
# Live 2026-11-18: the forecast server stopped answering while geocoding worked.
|
||||
debug_log(f"open-meteo forecast failed ({type(e).__name__}); trying met.no", "tools")
|
||||
source = "met.no"
|
||||
current = _met_no_current(lat, lon)
|
||||
if not current:
|
||||
return ToolExecutionResult(
|
||||
success=False,
|
||||
reply_text=f"Weather data temporarily unavailable for {location_display}."
|
||||
)
|
||||
notice(f"weather now: {source}", "llm")
|
||||
|
||||
# Extract current weather values
|
||||
temp_c = current.get("temperature_2m")
|
||||
|
||||
@@ -54,6 +54,12 @@ TARGET_DB = -20.0 # loudness every speaker is brought to, dBFS RMS over the
|
||||
MAX_GAIN_DB = 40.0 # a whisper at -60 dBFS still reaches the target; pure hiss is not blown up
|
||||
MIN_GAIN_DB = -20.0
|
||||
HIGHPASS_HZ = 60.0 # mains hum and desk rumble carry no speech
|
||||
# Consonants ("ㅈ", "ㅅ") and soft sentence ends live above 1 kHz and are what a dark microphone or a
|
||||
# swallowed syllable loses. Raised by a shelf that rises over one octave around HIGH_SHELF_HZ. Measured
|
||||
# with large-v3-turbo (voiced masks from Silero): FLEURS Korean test split (382 clips, held out) 5.11% ->
|
||||
# 4.85% CER, 25 live utterances of a dark speaker 5.04% -> 3.92%; 6 dB did little, 18-24 dB no better.
|
||||
HIGH_SHELF_HZ = 1000.0
|
||||
HIGH_SHELF_DB = 12.0
|
||||
_KNEE = 0.8 # soft limiter: peaks above this bend smoothly towards the ceiling instead of clipping
|
||||
_CEILING = 0.98
|
||||
_WINDOW = 512
|
||||
@@ -70,7 +76,10 @@ def loudness_equalise(x: np.ndarray, voiced: np.ndarray | None = None) -> np.nda
|
||||
if len(x) == 0:
|
||||
return x
|
||||
spec = np.fft.rfft(x.astype(np.float64))
|
||||
spec[np.fft.rfftfreq(len(x), 1 / TARGET_RATE) < HIGHPASS_HZ] = 0
|
||||
freqs = np.fft.rfftfreq(len(x), 1 / TARGET_RATE)
|
||||
spec[freqs < HIGHPASS_HZ] = 0
|
||||
rise = np.clip(np.log2(np.maximum(freqs, 1.0) / HIGH_SHELF_HZ) + 0.5, 0.0, 1.0)
|
||||
spec *= 10 ** (HIGH_SHELF_DB * rise / 20)
|
||||
y = np.fft.irfft(spec, len(x))
|
||||
n_win = -(-len(y) // _WINDOW)
|
||||
frames = np.pad(y, (0, n_win * _WINDOW - len(y))).reshape(n_win, _WINDOW)
|
||||
|
||||
@@ -24,12 +24,23 @@ import argparse
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
import types
|
||||
|
||||
MODEL_SPEED_MAX = 1.25
|
||||
|
||||
# MeloTTS's Korean front end (g2pkk) reads a number with native numerals only before these counters,
|
||||
# and only when MeCab tags the counter. Any other number is spelled out only when MeCab tags what follows
|
||||
# as a bound noun, which differs between MeCab builds (on Windows "60%" was read "육영퍼센트"); the rest
|
||||
# goes digit by digit. Its sentence splitter also breaks at every dot and comma ("4.2" as "사. 이").
|
||||
# Same list as g2pkk's BOUND_NOUNS: numbers before them are left for its counter rule.
|
||||
NATIVE_COUNTERS = tuple("군데 권 개 그루 닢 대 두 마리 모 모금 뭇 발 발짝 방 번 벌 보루 살 수 술 시 쌈 움큼 "
|
||||
"정 짝 채 척 첩 축 켤레 톨 통".split())
|
||||
_DIGITS = "영일이삼사오육칠팔구"
|
||||
_NUMBER = re.compile(r"(?<![\d.,])(\d{1,3}(?:,\d{3})+|\d+)(?:\.(\d+))?(?![\d,]\d)(?!\.\d)([가-힣]*)")
|
||||
|
||||
|
||||
def split_speed(speed: float) -> tuple[float, float]:
|
||||
"""(the model's speed, the stretch factor after it); their product is ``speed``."""
|
||||
@@ -65,6 +76,39 @@ def stretch(audio, factor: float, rate: int, frame_ms: float = 30.0, search_ms:
|
||||
return y[:n_out]
|
||||
|
||||
|
||||
def sino_korean(num: str) -> str:
|
||||
"""Sino-Korean reading of a whole number: 1234 is 천이백삼십사, 10000 is 만, 100000000 is 일억."""
|
||||
n = int(num)
|
||||
if n == 0:
|
||||
return "영"
|
||||
out = ""
|
||||
for power, big in reversed(list(enumerate(("", "만", "억", "조", "경")))):
|
||||
group = n // 10 ** (4 * power) % 10000
|
||||
if not group:
|
||||
continue
|
||||
part = ""
|
||||
for digit, unit in zip(f"{group:04d}", ("천", "백", "십", "")):
|
||||
d = int(digit)
|
||||
if d:
|
||||
part += ("" if d == 1 and unit else _DIGITS[d]) + unit
|
||||
out += ("" if part == "일" and big == "만" else part) + big
|
||||
return out
|
||||
|
||||
|
||||
def spell_numbers_kr(text: str) -> str:
|
||||
"""Spell out the numbers MeloTTS would misread: decimals ("4.2" is 사점이) and every whole number
|
||||
not followed by a native counter (those are left for MeloTTS, which reads "3시" as 세시)."""
|
||||
def spell(m: re.Match) -> str:
|
||||
whole, frac, after = m.group(1), m.group(2), m.group(3)
|
||||
if frac is None and after.startswith(NATIVE_COUNTERS):
|
||||
return m.group(0)
|
||||
spoken = sino_korean(whole.replace(",", ""))
|
||||
if frac is not None:
|
||||
spoken += "점" + "".join(_DIGITS[int(d)] for d in frac)
|
||||
return spoken + after
|
||||
return _NUMBER.sub(spell, text)
|
||||
|
||||
|
||||
def korean_only_patches() -> None:
|
||||
"""MeloTTS imports its Japanese front end (module-level MeCab.Tagger()) even for Korean, and on
|
||||
Windows g2pkk asks for ``eunjeon`` instead of python-mecab-ko. Same fix as the M0 kit."""
|
||||
@@ -132,7 +176,10 @@ def main() -> int:
|
||||
req = json.loads(line)
|
||||
rate = int(req["rate"])
|
||||
model_speed, factor = split_speed(float(req.get("speed", args.speed)))
|
||||
audio = model.tts_to_file(str(req["text"]), speaker, None, speed=model_speed, quiet=True)
|
||||
text = str(req["text"])
|
||||
if args.language == "KR":
|
||||
text = spell_numbers_kr(text)
|
||||
audio = model.tts_to_file(text, speaker, None, speed=model_speed, quiet=True)
|
||||
audio = stretch(audio, factor, native)
|
||||
if rate != native:
|
||||
from math import gcd
|
||||
|
||||
@@ -108,6 +108,18 @@ its own streaming Silero VAD (512-sample windows, state kept between frames).
|
||||
the gain kept between -20 and +40 dB, and peaks above 0.8 are soft-limited below 0.98 instead of
|
||||
clipping. Measured: speech from -60 dBFS to clipped shouting was transcribed equally well, and quiet
|
||||
speech under loud clicks or knocks better than with peak normalisation.
|
||||
Before the level is measured, the band where consonants such as "ㅈ" and "ㅅ" live is raised by
|
||||
12 dB: a shelf that rises over one octave from 707 Hz to 1.41 kHz (centred on 1 kHz) and stays
|
||||
flat above. A dark microphone, or a speaker who swallows consonants and sentence ends, loses that
|
||||
band first. Measured with large-v3-turbo, each clip levelled with its Silero voiced windows as a
|
||||
final is: on 32 real Discord utterances of such a speaker, 5.04% character errors (18 of 357) on
|
||||
the 25 whose words are sure, down to 3.92% (14), with sentence ends ("어때", "틀어줘") and words
|
||||
("연제구는") recovered and none lost; on FLEURS Korean, checked on the held-out test split (382
|
||||
clips), 5.11% to 4.85%. A wake word whose first consonant is not heard at all ("자비스" as
|
||||
"아비스" or "다비스") is not fixed by it (14 of 23 exact before and after); call detection's near
|
||||
match catches those one letter away. 6 dB changed little; 18 and 24 dB were no better on FLEURS
|
||||
and worse on the real speaker. The noise check below is unchanged with it (108 clips, none with
|
||||
text).
|
||||
|
||||
### Scheduling
|
||||
|
||||
@@ -180,6 +192,14 @@ is ready. Requests are served first come, first served by one TTS engine. `tts_c
|
||||
request's unsent sentences, and `tts_done` follows with `cancelled: true`. A sentence that fails to
|
||||
synthesise is reported with `error` (`code: "tts_failed"`) and the request ends with `failed: true`.
|
||||
|
||||
With `--melo-language KR` the MeloTTS child spells numbers out in Hangul before MeloTTS sees them,
|
||||
because its Korean front end misreads them: a number it cannot tag as a counter is read digit by digit
|
||||
(the tag depends on the MeCab build; on Windows "60%" was read "육영퍼센트"), and its own splitter
|
||||
breaks at every dot and comma ("4.2미터" as "사. 이미터"). Decimals are read with 점 and one name per
|
||||
digit after it (사점이), thousands commas are dropped, and every other whole number gets its
|
||||
Sino-Korean reading (육십, 이천이십육), except before a counter MeloTTS reads with native numerals
|
||||
(g2pkk's list: 시, 개, 마리, 살, ...), which stays for MeloTTS ("3시" is 세시).
|
||||
|
||||
Speed starts at `--melo-speed` and `tts_speed` changes it for every sentence made after it (a speed
|
||||
outside 0.5-2.0 or not a number is `bad_message` and the last good one stays). MeloTTS itself speaks
|
||||
up to 1.25: its own speed shortens every sound, and past that it drops them (five Korean sentences,
|
||||
@@ -298,7 +318,9 @@ which carry Discord's own time.
|
||||
highest chance of rain), then 중기예보 for the nearest of the KMA cities in `weather.py` and its region (중기기온,
|
||||
중기육상). Days KMA does not give, and every KMA failure, come from open-meteo (now: then
|
||||
met.no; later days: open-meteo's daily forecast only). The key is in KMA's URLs, so a failure is
|
||||
logged by its kind only. `detail` (only when the user asks for more detail) adds the
|
||||
logged by its kind only. Which service answered is printed without debug logging (category
|
||||
`llm`, no place and no key): `weather now: KMA` (or `open-meteo`, `met.no`) and
|
||||
`weather days <first>-<last>: <n> from KMA, <m> from open-meteo`. `detail` (only when the user asks for more detail) adds the
|
||||
humidity, the wind in m/s and the rain amount: now the last hour's rain (KMA 초단기실황 RN1,
|
||||
open-meteo `precipitation`; none from met.no), a 단기예보 day its mean humidity and strongest
|
||||
wind, an open-meteo day its strongest wind and rain total; 중기예보 has none of these. A dry
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from voice_worker.audio import InputConverter, loudness_equalise
|
||||
from voice_worker.audio import HIGH_SHELF_DB, HIGH_SHELF_HZ, InputConverter, loudness_equalise
|
||||
from voice_worker.protocol import (KIND_AUDIO, KIND_TTS, ProtocolError, decode_audio_frame, encode_audio_frame,
|
||||
encode_tts_frame, decode_tts_frame)
|
||||
|
||||
@@ -171,3 +171,16 @@ def test_low_rumble_is_removed_before_levelling():
|
||||
spec = np.abs(np.fft.rfft(y))
|
||||
freqs = np.fft.rfftfreq(len(y), 1 / 16000)
|
||||
assert spec[np.argmin(np.abs(freqs - 30))] < 0.01 * spec[np.argmin(np.abs(freqs - 220))]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_consonant_band_is_raised_against_the_vowel_band():
|
||||
"""A dark microphone (or a speaker who swallows consonants) loses the band above 1 kHz where
|
||||
"ㅈ" and "ㅅ" live; it is raised by the shelf, the band below it is left as it was."""
|
||||
t = np.arange(32000) / 16000
|
||||
low, high = HIGH_SHELF_HZ / 4, HIGH_SHELF_HZ * 4
|
||||
x = (0.05 * np.sin(2 * np.pi * low * t) + 0.05 * np.sin(2 * np.pi * high * t)).astype(np.float32)
|
||||
spec = np.abs(np.fft.rfft(loudness_equalise(x)))
|
||||
freqs = np.fft.rfftfreq(len(x), 1 / 16000)
|
||||
ratio_db = 20 * np.log10(spec[np.argmin(np.abs(freqs - high))] / spec[np.argmin(np.abs(freqs - low))])
|
||||
assert abs(ratio_db - HIGH_SHELF_DB) < 0.5
|
||||
|
||||
87
tests/test_voice_worker_melo_numbers.py
Normal file
87
tests/test_voice_worker_melo_numbers.py
Normal file
@@ -0,0 +1,87 @@
|
||||
"""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("<I", stream.read(4))
|
||||
header = json.loads(stream.read(n))
|
||||
stream.read(2 * header.get("samples", 0))
|
||||
return header
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_korean_child_gives_melo_the_spelled_text(tmp_path):
|
||||
(tmp_path / "melo").mkdir()
|
||||
(tmp_path / "melo" / "__init__.py").write_text("")
|
||||
(tmp_path / "melo" / "api.py").write_text(FAKE_MELO)
|
||||
log = tmp_path / "texts.txt"
|
||||
env = {**os.environ, "PYTHONPATH": str(tmp_path), "FAKE_MELO_LOG": str(log)}
|
||||
proc = subprocess.Popen([sys.executable, melo_child.__file__, "--language", "KR", "--device", "cpu",
|
||||
"--speed", "1.0"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL, env=env)
|
||||
try:
|
||||
assert read_frame(proc.stdout)["ready"] is True
|
||||
proc.stdin.write((json.dumps({"text": "바람 초속 4.2미터, 습도 60%", "rate": 48000}) + "\n").encode())
|
||||
proc.stdin.flush()
|
||||
assert read_frame(proc.stdout)["ok"] is True
|
||||
finally:
|
||||
proc.stdin.close()
|
||||
proc.wait(timeout=10)
|
||||
assert log.read_text(encoding="utf-8").splitlines()[-1] == "바람 초속 사점이미터, 습도 육십%"
|
||||
@@ -433,6 +433,29 @@ class TestWeatherTool:
|
||||
assert WMO_CODES_KO[80] in result.reply_text
|
||||
assert str(round(8.6)) in result.reply_text
|
||||
|
||||
@patch('requests.get')
|
||||
def test_the_log_names_met_no_when_it_gave_the_weather_now(self, mock_get, capfd):
|
||||
geo = Mock(status_code=200, raise_for_status=Mock())
|
||||
geo.json.return_value = {"results": [{"latitude": 37.57, "longitude": 126.98,
|
||||
"name": "서울", "country": "대한민국"}]}
|
||||
met = Mock(status_code=200, raise_for_status=Mock())
|
||||
met.json.return_value = {"properties": {"timeseries": [{"data": {
|
||||
"instant": {"details": {"air_temperature": 8.6}},
|
||||
"next_1_hours": {"summary": {"symbol_code": "cloudy"}}}}]}}
|
||||
|
||||
def get(url, *a, **k):
|
||||
if "geocoding" in url:
|
||||
return geo
|
||||
if "open-meteo" in url:
|
||||
raise requests.exceptions.Timeout("timed out")
|
||||
return met
|
||||
mock_get.side_effect = get
|
||||
|
||||
self.tool.run({"location": "Seoul"}, self.context)
|
||||
|
||||
err = capfd.readouterr().err
|
||||
assert "weather now: met.no" in err and "서울" not in err
|
||||
|
||||
@pytest.mark.parametrize("symbol", ["lightsleet", "sleet_day", "heavysleetshowers_night"])
|
||||
def test_met_no_sleet_stays_sleet_not_freezing_rain(self, symbol):
|
||||
from src.jarvis.tools.builtin.weather import _met_no_wmo
|
||||
@@ -722,6 +745,23 @@ class TestKmaWeather:
|
||||
assert len(kma) == 2 and all(p["authKey"] == self.KEY for p in kma)
|
||||
assert all((p["nx"], p["ny"]) == (60, 127) for p in kma)
|
||||
|
||||
@pytest.mark.parametrize("key, source", [(True, "KMA"), (False, "open-meteo")])
|
||||
@patch('requests.get')
|
||||
def test_the_log_names_the_service_that_gave_the_weather_now_and_not_the_place(
|
||||
self, mock_get, key, source, monkeypatch, capfd):
|
||||
"""Live 2026-11-18: "흐림" could have come from either service, and nothing said which."""
|
||||
if key:
|
||||
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||
else:
|
||||
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||
mock_get.side_effect = self._routes()
|
||||
|
||||
self.tool.run({"location": "Seoul"}, self.context)
|
||||
|
||||
err = capfd.readouterr().err
|
||||
assert f"weather now: {source}" in err
|
||||
assert "Seoul" not in err and self.KEY not in err
|
||||
|
||||
@patch('requests.get')
|
||||
def test_precipitation_wins_over_the_sky(self, mock_get, monkeypatch):
|
||||
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||
@@ -1053,6 +1093,15 @@ class TestForecast:
|
||||
assert "강수확률 80%" in result.reply_text
|
||||
assert not any(self.KEY in str(c) for c in log.call_args_list)
|
||||
|
||||
@pytest.mark.parametrize("fail_kma, counts", [(False, "1 from KMA, 0 from open-meteo"),
|
||||
(True, "0 from KMA, 1 from open-meteo")])
|
||||
def test_the_log_says_how_many_forecast_days_each_service_gave(self, fail_kma, counts, monkeypatch, capfd):
|
||||
self._run({"days_ahead": 1}, monkeypatch, fail_kma=fail_kma)
|
||||
|
||||
err = capfd.readouterr().err
|
||||
assert f"weather days 1-1: {counts}" in err
|
||||
assert "Seoul" not in err and self.KEY not in err
|
||||
|
||||
def test_outside_korea_the_forecast_is_open_meteos_daily_one(self, monkeypatch):
|
||||
result, calls = self._run({"days_ahead": 1}, monkeypatch, country_code="JP")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user