Skip to content

Commit 1acb78f

Browse files
committed
fix tts replay, self-rating button, phase0 prefill, tts cache
1 parent 319f002 commit 1acb78f

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

backend/app/agents/screening_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ def choose_opening_question(worker_name: str, assignment: str, locale: str = "en
298298
PHASE0_FIELDS = ["name", "age", "sex", "address", "tradeRaw", "yearsExp"]
299299

300300

301-
def init_phase0_profile(worker_name: str, trade_raw: str) -> dict:
301+
def init_phase0_profile(worker_name: str, trade_raw: str, experience_years: int | None = None) -> dict:
302302
return {
303303
"name": worker_name.strip() if worker_name else "",
304304
"age": None,
305305
"sex": None,
306306
"address": None,
307307
"tradeRaw": trade_raw.strip() if trade_raw else "",
308-
"yearsExp": None,
308+
"yearsExp": experience_years if experience_years is not None else None,
309309
}
310310

311311

backend/app/api/routes/sessions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ async def start_session(
337337
assignment = ASSIGNMENT_TEMPLATES.get(domain, DEFAULT_ASSIGNMENT)
338338

339339
first_question = choose_opening_question(worker.name, assignment, locale, domain)
340-
phase0_profile = init_phase0_profile(worker.name, worker.specialization)
340+
phase0_profile = init_phase0_profile(worker.name, worker.specialization, worker.experience_years)
341341
phase0_completed = len(phase0_missing_fields(phase0_profile)) == 0
342342

343343
session = Session(

backend/app/api/routes/speech.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import hashlib
23

34
import httpx
45
from fastapi import APIRouter, File, HTTPException, UploadFile
@@ -9,6 +10,9 @@
910

1011
router = APIRouter(tags=["speech"])
1112

13+
# In-memory TTS cache: (text, language) hash -> WAV bytes
14+
_tts_cache: dict[str, bytes] = {}
15+
1216
@router.post("/speech/stt")
1317
async def speech_to_text(file: UploadFile = File(...)):
1418
audio_bytes = await file.read()
@@ -27,6 +31,10 @@ class TtsRequest(BaseModel):
2731

2832
@router.post("/speech/tts")
2933
async def text_to_speech(payload: TtsRequest):
34+
cache_key = hashlib.md5(f"{payload.text}|{payload.language}".encode()).hexdigest()
35+
if cache_key in _tts_cache:
36+
return Response(content=_tts_cache[cache_key], media_type="audio/wav")
37+
3038
headers = sarvam_headers()
3139

3240
async with httpx.AsyncClient(timeout=30) as client:
@@ -51,4 +59,5 @@ async def text_to_speech(payload: TtsRequest):
5159
raise HTTPException(status_code=502, detail="No audio returned from TTS")
5260

5361
audio_bytes = base64.b64decode(audios[0])
62+
_tts_cache[cache_key] = audio_bytes
5463
return Response(content=audio_bytes, media_type="audio/wav")

frontend/src/pages/ScreeningRoomPage.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,15 @@ export default function ScreeningRoomPage() {
16161616
<p style={{ fontSize: "clamp(13px,1.6vw,15px)", color: "#71675d", lineHeight: 1.75, margin: 0, minHeight: 42 }}>
16171617
{currentQuestion || (session ? copy.waiting_ai : copy.setup_to_begin)}
16181618
</p>
1619+
{currentQuestion && !aiSpeaking && (
1620+
<button
1621+
onClick={() => speakAi(currentQuestion)}
1622+
title="Replay question"
1623+
style={{ marginTop: 6, background: "none", border: "none", cursor: "pointer", color: "rgba(59,130,246,0.7)", fontSize: 18, padding: "2px 6px" }}
1624+
>
1625+
🔊
1626+
</button>
1627+
)}
16191628
{session && (
16201629
<p style={{ margin: "8px 0 0", fontSize: 11, color: "#64748b" }}>
16211630
{session.phase0_completed ? "Phase 0 intake complete" : "Phase 0 intake in progress"}
@@ -1685,7 +1694,7 @@ export default function ScreeningRoomPage() {
16851694
))}
16861695
</div>
16871696
<div style={{ display: "flex", justifyContent: "flex-end", marginTop: 8 }}>
1688-
<button onClick={saveSelfRatings} style={{ ...iconBtn(false, "#3b82f6"), padding: "6px 10px" }}>
1697+
<button onClick={saveSelfRatings} style={{ background: "rgba(59,130,246,0.12)", color: "#1e3a8a", border: "1px solid rgba(59,130,246,0.25)", borderRadius: 8, padding: "6px 14px", fontSize: 12, fontWeight: 700, cursor: "pointer" }}>
16891698
{copy.self_rate_send}
16901699
</button>
16911700
</div>

0 commit comments

Comments
 (0)