소스 검색

Display Whisper issue fix

Benjamin Harris 1 개월 전
부모
커밋
90b7022593
3개의 변경된 파일26개의 추가작업 그리고 33개의 파일을 삭제
  1. 11 5
      bridge/admin.py
  2. 15 6
      bridge/bridge.py
  3. 0 22
      bridge/display.py

+ 11 - 5
bridge/admin.py

@@ -569,7 +569,9 @@ HTML = """<!DOCTYPE html>
     <thead>
       <tr>
         <th>Speaker ID</th>
-        <th>Friendly Name</th>
+        <th>Initials</th>
+        <th>Name</th>
+        <th>Locality</th>
         <th>Voice Sample</th>
         <th>Actions</th>
       </tr>
@@ -671,14 +673,18 @@ HTML = """<!DOCTYPE html>
     <div class="field">
       <label>Speaker ID
         <span style="color:#64748b;font-weight:normal;font-size:.8rem">
-          (e.g. SPEAKER_00, or any unique key)
+          (e.g. SPK_00, or any unique key)
         </span>
       </label>
-      <input id="new-id" placeholder="SPEAKER_00">
+      <input id="new-id" placeholder="SPK_00">
     </div>
     <div class="field">
-      <label>Friendly Name</label>
-      <input id="new-name" placeholder="Pastor John">
+      <label>Initials</label>
+      <input id="new-initials" placeholder="J.B.B">
+    </div>
+    <div class="field">
+      <label>Name</label>
+      <input id="new-name" placeholder="John Brown">
     </div>
     <div class="modal-actions">
       <button class="btn btn-ghost" onclick="closeAddModal()">Cancel</button>

+ 15 - 6
bridge/bridge.py

@@ -281,13 +281,22 @@ async def audio_processor_loop(state: BridgeState, mqtt_client: mqtt.Client, eng
     results_generator  = await audio_processor.create_tasks()
 
     async def _receive_results():
+        # FrontData.lines is a cumulative list of committed Segment objects.
+        # Track how many we've already processed so we only push new ones.
+        seen_lines = 0
         async for response in results_generator:
-            text     = (getattr(response, "text", None) or getattr(response, "buffer_transcription", None) or "").strip()
-            is_final = getattr(response, "is_final", False) or getattr(response, "end_of_segment", False)
-            speaker  = getattr(response, "speaker", None)
-            if is_final and text:
-                print(f"[Whisper] ({speaker or '?'}) {text}")
-                state.push_final(text, speaker, mqtt_client)
+            lines = response.lines or []
+            # Guard against unexpected shrink (e.g. processor reset)
+            if len(lines) < seen_lines:
+                seen_lines = 0
+            for seg in lines[seen_lines:]:
+                text = (seg.text or "").strip()
+                if text and not seg.is_silence():
+                    spk = seg.speaker
+                    speaker_id = f"SPEAKER_{spk:02d}" if isinstance(spk, int) and spk >= 0 else None
+                    print(f"[Whisper] ({speaker_id or '?'}) {text}")
+                    state.push_final(text, speaker_id, mqtt_client)
+            seen_lines = len(lines)
 
     async def _send_audio():
         with sd.InputStream(

+ 0 - 22
bridge/display.py

@@ -1,22 +0,0 @@
-#!/usr/bin/env python3
-"""
-display.py — Live Transcription Display
-
-Local web interface for displaying live transcription for use by deaf individuals.
-Runs on port 8002 alongside bridge.py
-
-Access at: http://localhost:8002/display
-"""
-
-import asyncio
-import json
-import shutil
-from pathlib import Path
-
-from fastapi import FastAPI, HTTPException, UploadFile, File
-from fastapi.responses import HTMLResponse, FileResponse
-from pydantic import BaseModel
-import uvicorn
-import websockets
-
-SPEAKERS_FILE       = Path(__file__).parent / "speakers.json"