Spaces:
Running
Running
Update stt/stt_google.py
Browse files- stt/stt_google.py +58 -2
stt/stt_google.py
CHANGED
@@ -91,7 +91,10 @@ class GoogleCloudSTT(STTInterface):
|
|
91 |
"OGG_OPUS": speech.RecognitionConfig.AudioEncoding.OGG_OPUS,
|
92 |
}
|
93 |
return encoding_map.get(encoding_str, speech.RecognitionConfig.AudioEncoding.WEBM_OPUS)
|
94 |
-
|
|
|
|
|
|
|
95 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncGenerator[TranscriptionResult, None]:
|
96 |
"""Stream audio chunk and get results"""
|
97 |
if not self.is_streaming:
|
@@ -428,4 +431,57 @@ class GoogleCloudSTT(STTInterface):
|
|
428 |
|
429 |
# Log response
|
430 |
has_results = len(response.results) > 0 if hasattr(response, 'results') else False
|
431 |
-
log_info(f"π¨ Google STT Response #{response_count}: has_results={has_results}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
"OGG_OPUS": speech.RecognitionConfig.AudioEncoding.OGG_OPUS,
|
92 |
}
|
93 |
return encoding_map.get(encoding_str, speech.RecognitionConfig.AudioEncoding.WEBM_OPUS)
|
94 |
+
|
95 |
+
# Alias for compatibility
|
96 |
+
_get_google_encoding = _get_encoding
|
97 |
+
|
98 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncGenerator[TranscriptionResult, None]:
|
99 |
"""Stream audio chunk and get results"""
|
100 |
if not self.is_streaming:
|
|
|
431 |
|
432 |
# Log response
|
433 |
has_results = len(response.results) > 0 if hasattr(response, 'results') else False
|
434 |
+
log_info(f"π¨ Google STT Response #{response_count}: has_results={has_results}")
|
435 |
+
|
436 |
+
if not response.results:
|
437 |
+
continue
|
438 |
+
|
439 |
+
# Process results
|
440 |
+
for result_idx, result in enumerate(response.results):
|
441 |
+
# Check result type
|
442 |
+
result_type = "π INTERIM" if not result.is_final else "β
FINAL"
|
443 |
+
stability = getattr(result, 'stability', 0.0)
|
444 |
+
|
445 |
+
log_info(f"{result_type} Result #{result_idx}: "
|
446 |
+
f"alternatives={len(result.alternatives)}, "
|
447 |
+
f"stability={stability:.3f}")
|
448 |
+
|
449 |
+
if result.alternatives:
|
450 |
+
best_alternative = result.alternatives[0]
|
451 |
+
transcript = best_alternative.transcript
|
452 |
+
confidence = best_alternative.confidence if result.is_final else stability
|
453 |
+
|
454 |
+
# Log transcript
|
455 |
+
if result.is_final:
|
456 |
+
log_info(f"β
FINAL TRANSCRIPT: '{transcript}' "
|
457 |
+
f"(confidence: {confidence:.3f})")
|
458 |
+
else:
|
459 |
+
log_info(f"π INTERIM TRANSCRIPT: '{transcript[:100]}...' "
|
460 |
+
f"(stability: {stability:.3f})")
|
461 |
+
|
462 |
+
# Queue result
|
463 |
+
result_obj = TranscriptionResult(
|
464 |
+
text=transcript,
|
465 |
+
is_final=result.is_final,
|
466 |
+
confidence=confidence,
|
467 |
+
timestamp=datetime.utcnow()
|
468 |
+
)
|
469 |
+
|
470 |
+
self.responses_queue.put(result_obj)
|
471 |
+
log_info(f"π₯ {'FINAL' if result.is_final else 'INTERIM'} result queued")
|
472 |
+
|
473 |
+
# Log completion
|
474 |
+
if response_count == 0:
|
475 |
+
log_error("β Google STT stream ended without ANY responses!")
|
476 |
+
else:
|
477 |
+
log_info(f"β
Google STT stream ended normally after {response_count} responses")
|
478 |
+
|
479 |
+
except Exception as e:
|
480 |
+
log_error(f"β Google STT error: {e}")
|
481 |
+
if hasattr(e, 'details'):
|
482 |
+
log_error(f"Error details: {e.details}")
|
483 |
+
self.error_message = str(e)
|
484 |
+
finally:
|
485 |
+
log_info("π€ Google STT stream thread ended")
|
486 |
+
with self.lock:
|
487 |
+
self.is_streaming = False
|