ciyidogan commited on
Commit
89a643d
·
verified ·
1 Parent(s): daf71d1

Update stt/stt_google.py

Browse files
Files changed (1) hide show
  1. stt/stt_google.py +59 -44
stt/stt_google.py CHANGED
@@ -367,10 +367,6 @@ class GoogleCloudSTT(STTInterface):
367
  log_info(f"📤 First chunk - size: {len(chunk)} bytes")
368
  if len(chunk) >= 4 and chunk[:4] == b'\x1a\x45\xdf\xa3':
369
  log_info("✅ Valid WEBM header detected")
370
- else:
371
- log_error(f"❌ Invalid audio format, first 4 bytes: {chunk[:4].hex()}")
372
- # Format hatalıysa devam et, Google STT düzeltebilir
373
- # break
374
 
375
  # Her 50 chunk'ta durum raporu
376
  if chunk_count % 50 == 0:
@@ -391,6 +387,7 @@ class GoogleCloudSTT(STTInterface):
391
  log_info("🎤 Creating Google STT streaming client...")
392
 
393
  try:
 
394
  responses = self.client.streaming_recognize(
395
  self.streaming_config,
396
  requests,
@@ -402,52 +399,68 @@ class GoogleCloudSTT(STTInterface):
402
  # Process responses
403
  response_count = 0
404
  result_count = 0
 
405
 
406
- for response in responses:
407
- response_count += 1
408
-
409
- if response_count == 1:
410
- log_info(f"📨 First response received from Google STT")
 
 
 
411
 
412
- if self.stop_event.is_set():
413
- log_info("🛑 Stop event detected")
414
- break
 
415
 
416
- # Process results
417
- if not response.results:
418
- log_debug(f"📭 Response #{response_count} has no results")
419
- continue
420
 
421
- for result in response.results:
422
- result_count += 1
423
-
424
- if not result.alternatives:
425
  continue
426
 
427
- alternative = result.alternatives[0]
428
-
429
- if alternative.transcript.strip():
430
- # Create transcription result
431
- transcription = TranscriptionResult(
432
- text=alternative.transcript,
433
- is_final=result.is_final,
434
- confidence=getattr(alternative, 'confidence', 0.0),
435
- timestamp=datetime.now().timestamp()
436
- )
437
-
438
- # Put result in queue
439
- self._put_result(transcription)
440
-
441
- if result.is_final:
442
- log_info(f"🎯 FINAL TRANSCRIPT: '{alternative.transcript}'")
443
-
444
- # Single utterance modunda Google STT otomatik kapanır
445
- if self.streaming_config.single_utterance:
446
- log_info("✅ Single utterance mode - Stream will end")
447
- # Google stream'i kapatacak, biz de çıkalım
448
- return
449
- else:
450
- log_debug(f"📝 Interim: '{alternative.transcript}'")
 
 
 
 
 
 
 
 
 
 
 
 
 
451
 
452
  log_info(f"📊 Google STT stream ended. Responses: {response_count}, Results: {result_count}")
453
 
@@ -459,6 +472,8 @@ class GoogleCloudSTT(STTInterface):
459
  log_info("✅ Stream ended normally")
460
  elif "Exceeded maximum allowed stream duration" in error_msg:
461
  log_warning("⚠️ Stream duration limit (5 min)")
 
 
462
  else:
463
  log_error(f"❌ Google STT error: {error_msg}")
464
 
 
367
  log_info(f"📤 First chunk - size: {len(chunk)} bytes")
368
  if len(chunk) >= 4 and chunk[:4] == b'\x1a\x45\xdf\xa3':
369
  log_info("✅ Valid WEBM header detected")
 
 
 
 
370
 
371
  # Her 50 chunk'ta durum raporu
372
  if chunk_count % 50 == 0:
 
387
  log_info("🎤 Creating Google STT streaming client...")
388
 
389
  try:
390
+ # Start streaming
391
  responses = self.client.streaming_recognize(
392
  self.streaming_config,
393
  requests,
 
399
  # Process responses
400
  response_count = 0
401
  result_count = 0
402
+ last_log_time = time.time()
403
 
404
+ # Response iterator'ı başlat
405
+ try:
406
+ for response in responses:
407
+ response_count += 1
408
+
409
+ # İlk response'u logla
410
+ if response_count == 1:
411
+ log_info(f"📨 First response received from Google STT")
412
 
413
+ # Her 5 saniyede bir durum logu
414
+ if time.time() - last_log_time > 5:
415
+ log_info(f"📊 Still listening... Responses: {response_count}, Results: {result_count}")
416
+ last_log_time = time.time()
417
 
418
+ if self.stop_event.is_set():
419
+ log_info("🛑 Stop event detected")
420
+ break
 
421
 
422
+ # Process results
423
+ if not response.results:
424
+ log_debug(f"📭 Response #{response_count} has no results")
 
425
  continue
426
 
427
+ for result in response.results:
428
+ result_count += 1
429
+
430
+ if not result.alternatives:
431
+ continue
432
+
433
+ alternative = result.alternatives[0]
434
+
435
+ # Log all transcripts, even empty ones
436
+ log_debug(f"📝 Transcript: '{alternative.transcript}' (is_final: {result.is_final})")
437
+
438
+ if alternative.transcript.strip():
439
+ # Create transcription result
440
+ transcription = TranscriptionResult(
441
+ text=alternative.transcript,
442
+ is_final=result.is_final,
443
+ confidence=getattr(alternative, 'confidence', 0.0),
444
+ timestamp=datetime.now().timestamp()
445
+ )
446
+
447
+ # Put result in queue
448
+ self._put_result(transcription)
449
+
450
+ if result.is_final:
451
+ log_info(f"🎯 FINAL TRANSCRIPT: '{alternative.transcript}'")
452
+
453
+ # Single utterance modunda Google STT otomatik kapanır
454
+ if self.streaming_config.single_utterance:
455
+ log_info("✅ Single utterance completed - Stream ending")
456
+ return
457
+ else:
458
+ log_debug(f"📝 Interim: '{alternative.transcript}'")
459
+
460
+ except StopIteration:
461
+ log_info("✅ Google STT stream ended (StopIteration)")
462
+ except Exception as e:
463
+ log_error(f"❌ Error processing responses: {e}")
464
 
465
  log_info(f"📊 Google STT stream ended. Responses: {response_count}, Results: {result_count}")
466
 
 
472
  log_info("✅ Stream ended normally")
473
  elif "Exceeded maximum allowed stream duration" in error_msg:
474
  log_warning("⚠️ Stream duration limit (5 min)")
475
+ elif "InvalidArgument" in error_msg:
476
+ log_error(f"❌ Invalid STT configuration: {error_msg}")
477
  else:
478
  log_error(f"❌ Google STT error: {error_msg}")
479