refactor: extract get_stt_model_from_config helper to eliminate DRY violation
Duplicated YAML config parsing for stt.model existed in gateway/run.py and gateway/platforms/discord.py. Moved to a single helper in transcription_tools.py and added 5 tests covering all edge cases.
This commit is contained in:
parent
3260413cc7
commit
2c84979d77
4 changed files with 67 additions and 25 deletions
|
|
@ -880,18 +880,8 @@ class DiscordAdapter(BasePlatformAdapter):
|
|||
try:
|
||||
await asyncio.to_thread(VoiceReceiver.pcm_to_wav, pcm_data, wav_path)
|
||||
|
||||
from tools.transcription_tools import transcribe_audio
|
||||
# Read STT model from config.yaml
|
||||
stt_model = None
|
||||
try:
|
||||
import yaml as _y
|
||||
from pathlib import Path as _P
|
||||
_cfg = _P(os.getenv("HERMES_HOME", _P.home() / ".hermes")) / "config.yaml"
|
||||
if _cfg.exists():
|
||||
with open(_cfg) as _f:
|
||||
stt_model = (_y.safe_load(_f) or {}).get("stt", {}).get("model")
|
||||
except Exception:
|
||||
pass
|
||||
from tools.transcription_tools import transcribe_audio, get_stt_model_from_config
|
||||
stt_model = get_stt_model_from_config()
|
||||
result = await asyncio.to_thread(transcribe_audio, wav_path, model=stt_model)
|
||||
|
||||
if not result.get("success"):
|
||||
|
|
|
|||
|
|
@ -3323,20 +3323,10 @@ class GatewayRunner:
|
|||
Returns:
|
||||
The enriched message string with transcriptions prepended.
|
||||
"""
|
||||
from tools.transcription_tools import transcribe_audio
|
||||
from tools.transcription_tools import transcribe_audio, get_stt_model_from_config
|
||||
import asyncio
|
||||
|
||||
# Read STT model from config.yaml (same key the CLI uses)
|
||||
stt_model = None
|
||||
try:
|
||||
import yaml as _y
|
||||
_cfg = _hermes_home / "config.yaml"
|
||||
if _cfg.exists():
|
||||
with open(_cfg) as _f:
|
||||
_data = _y.safe_load(_f) or {}
|
||||
stt_model = _data.get("stt", {}).get("model")
|
||||
except Exception:
|
||||
pass
|
||||
stt_model = get_stt_model_from_config()
|
||||
|
||||
enriched_parts = []
|
||||
for path in audio_paths:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue