From 58c3e25db6d08b0e3ae8f0038e92266eeda2cb5e Mon Sep 17 00:00:00 2001 From: Mahdi Date: Tue, 22 Sep 2026 12:24:53 +0330 Subject: [PATCH] Correcting the speech-to-text output --- apps/api/src/ai/ai-stt.service.ts | 10 ++++++++-- apps/stt/main.py | 8 +++++++- deploy/ecosystem.config.cjs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/api/src/ai/ai-stt.service.ts b/apps/api/src/ai/ai-stt.service.ts index beb7b09..03c3792 100644 --- a/apps/api/src/ai/ai-stt.service.ts +++ b/apps/api/src/ai/ai-stt.service.ts @@ -51,9 +51,15 @@ export class AiSttService { body: form, signal: AbortSignal.timeout(timeoutMs), }); - } catch { + } catch (e) { + const name = e instanceof Error ? e.name : ''; + if (name === 'TimeoutError' || name === 'AbortError') { + throw new ServiceUnavailableException( + 'زمان تبدیل صوت تمام شد. اگر تازه مدل عوض شده، چند دقیقه صبر کنید تا دانلود شود و دوباره امتحان کنید.', + ); + } throw new ServiceUnavailableException( - 'سرویس تبدیل صوت در دسترس نیست. Pipecat STT را اجرا کنید.', + 'سرویس تبدیل صوت خاموش است. مدل medium معمولاً حافظهٔ سرور را پر می‌کند و پروسه را می‌کشد. در apps/stt/.env مقدار STT_MODEL=small بگذارید و pm2 restart mento-stt بزنید.', ); } diff --git a/apps/stt/main.py b/apps/stt/main.py index d4eea58..696f35f 100644 --- a/apps/stt/main.py +++ b/apps/stt/main.py @@ -97,7 +97,13 @@ def _get_model() -> WhisperModel: compute = _env("STT_COMPUTE_TYPE", "int8") or "int8" logger.info("Loading Faster-Whisper model=%s device=%s compute=%s", name, device, compute) try: - loaded = WhisperModel(name, device=device, compute_type=compute) + loaded = WhisperModel( + name, + device=device, + compute_type=compute, + cpu_threads=2, + num_workers=1, + ) except Exception as exc: _model_error = str(exc) logger.exception("Whisper model load failed") diff --git a/deploy/ecosystem.config.cjs b/deploy/ecosystem.config.cjs index c2c7ba4..4e2af76 100644 --- a/deploy/ecosystem.config.cjs +++ b/deploy/ecosystem.config.cjs @@ -29,7 +29,7 @@ module.exports = { interpreter: "none", instances: 1, exec_mode: "fork", - max_memory_restart: "500M", + max_memory_restart: "1500M", time: true, }, ],