|
|
@@ -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(
|