fix(melo-test): use subscript on spk2id (HParams has no .get)

`model.hps.data.spk2id` is a MeloTTS `HParams` instance, not a dict.
It exposes `__contains__` and `__getitem__` but not `.get()`, so the
previous lookup blew up at lifespan startup with
`AttributeError: 'HParams' object has no attribute 'get'`.

Switch to `spk["KR"] if "KR" in spk else next(iter(spk.values()))`.
This commit is contained in:
Claude Owner
2026-05-26 20:49:19 +09:00
parent 2bed5f38b7
commit 106915b55b

View File

@@ -35,8 +35,10 @@ async def lifespan(_: FastAPI):
device = os.environ.get("MELO_DEVICE", "auto")
model = TTS(language="KR", device=device)
spk = model.hps.data.spk2id
# 한국어 모델은 보통 {"KR": 0}
speaker_id = spk.get("KR", next(iter(spk.values())))
# 한국어 모델은 보통 {"KR": 0}.
# spk2id 는 dict 가 아니라 MeloTTS 의 HParams 인스턴스라
# `.get()` 이 없고 `__contains__` / `__getitem__` 만 지원함.
speaker_id = spk["KR"] if "KR" in spk else next(iter(spk.values()))
state["model"] = model
state["speaker_id"] = speaker_id
log.info("모델 로딩 완료 (%.1fs). speakers=%s, 사용=%s",