ciyidogan commited on
Commit
2955a8f
·
verified ·
1 Parent(s): 872bc77

Update stt_google.py

Browse files
Files changed (1) hide show
  1. stt_google.py +23 -13
stt_google.py CHANGED
@@ -109,8 +109,16 @@ class GoogleCloudSTT(STTInterface):
109
  def request_generator():
110
  """Generate streaming requests"""
111
  chunk_count = 0
 
 
112
  while not self.stop_event.is_set():
113
  try:
 
 
 
 
 
 
114
  # Get audio chunk with timeout
115
  chunk = self.audio_queue.get(timeout=0.1)
116
  if chunk is None: # Poison pill
@@ -122,7 +130,7 @@ class GoogleCloudSTT(STTInterface):
122
  if chunk_count == 1:
123
  log_info(f"📤 First chunk sent to Google STT, size: {len(chunk)} bytes")
124
  elif chunk_count % 100 == 0:
125
- log_info(f"📤 Sent {chunk_count} chunks to Google STT")
126
 
127
  yield speech.StreamingRecognizeRequest(audio_content=chunk)
128
  except queue.Empty:
@@ -154,7 +162,7 @@ class GoogleCloudSTT(STTInterface):
154
  # Boş response'ları say ama loglama
155
  if not response.results:
156
  empty_response_count += 1
157
- if empty_response_count % 50 == 0: # 10'dan 50'ye çıkardım
158
  log_warning(f"⚠️ Received {empty_response_count} empty responses from Google STT")
159
  continue
160
 
@@ -175,7 +183,7 @@ class GoogleCloudSTT(STTInterface):
175
  timestamp=datetime.now().timestamp()
176
  )
177
 
178
- # Put result in queue - direkt koy, task yaratma
179
  self._put_result(transcription)
180
 
181
  # SADECE final result'ları logla
@@ -186,30 +194,32 @@ class GoogleCloudSTT(STTInterface):
186
 
187
  except Exception as e:
188
  error_msg = str(e)
189
- log_error(f"❌ Google STT stream error: {error_msg}")
190
 
191
  # Detaylı hata mesajları
192
  if "Exceeded maximum allowed stream duration" in error_msg:
193
- log_error(" Stream duration limit exceeded (5 minutes). Need to restart stream.")
 
194
  elif "Bad language code" in error_msg:
195
  log_error(f"❌ Invalid language code in STT config. Check locale settings.")
196
  elif "invalid_argument" in error_msg:
197
  log_error(f"❌ Invalid STT configuration. Check encoding and sample rate.")
198
  elif "Deadline Exceeded" in error_msg:
199
  log_error(f"❌ Google STT timeout - possibly network issue or slow connection")
 
 
200
 
201
  except Exception as e:
202
  log_error(f"❌ Fatal error in STT stream thread", error=str(e), traceback=traceback.format_exc())
203
  finally:
204
  log_info("🎤 Google STT stream thread ended")
205
-
206
- def _put_result(self, result: TranscriptionResult):
207
- """Helper to put result in queue"""
208
- try:
209
- self.responses_queue.put(result)
210
- # Debug log'u kaldırdık
211
- except Exception as e:
212
- log_error(f"❌ Error queuing result: {e}")
213
 
214
  async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
215
  """Stream audio chunk and get transcription results"""
 
109
  def request_generator():
110
  """Generate streaming requests"""
111
  chunk_count = 0
112
+ start_time = datetime.now()
113
+
114
  while not self.stop_event.is_set():
115
  try:
116
+ # 5 dakika sınırına yaklaşıyorsak stream'i sonlandır
117
+ elapsed = (datetime.now() - start_time).total_seconds()
118
+ if elapsed > 280: # 4 dakika 40 saniye - güvenli margin
119
+ log_warning(f"⚠️ Approaching 5-minute limit ({elapsed:.1f}s), ending stream gracefully")
120
+ break
121
+
122
  # Get audio chunk with timeout
123
  chunk = self.audio_queue.get(timeout=0.1)
124
  if chunk is None: # Poison pill
 
130
  if chunk_count == 1:
131
  log_info(f"📤 First chunk sent to Google STT, size: {len(chunk)} bytes")
132
  elif chunk_count % 100 == 0:
133
+ log_info(f"📤 Sent {chunk_count} chunks to Google STT (elapsed: {elapsed:.1f}s)")
134
 
135
  yield speech.StreamingRecognizeRequest(audio_content=chunk)
136
  except queue.Empty:
 
162
  # Boş response'ları say ama loglama
163
  if not response.results:
164
  empty_response_count += 1
165
+ if empty_response_count % 50 == 0:
166
  log_warning(f"⚠️ Received {empty_response_count} empty responses from Google STT")
167
  continue
168
 
 
183
  timestamp=datetime.now().timestamp()
184
  )
185
 
186
+ # Put result in queue
187
  self._put_result(transcription)
188
 
189
  # SADECE final result'ları logla
 
194
 
195
  except Exception as e:
196
  error_msg = str(e)
 
197
 
198
  # Detaylı hata mesajları
199
  if "Exceeded maximum allowed stream duration" in error_msg:
200
+ log_warning("⚠️ Stream duration limit exceeded (5 minutes). This is expected for long sessions.")
201
+ # Bu bir error değil, normal davranış - result queue'ya error koymuyoruz
202
  elif "Bad language code" in error_msg:
203
  log_error(f"❌ Invalid language code in STT config. Check locale settings.")
204
  elif "invalid_argument" in error_msg:
205
  log_error(f"❌ Invalid STT configuration. Check encoding and sample rate.")
206
  elif "Deadline Exceeded" in error_msg:
207
  log_error(f"❌ Google STT timeout - possibly network issue or slow connection")
208
+ else:
209
+ log_error(f"❌ Google STT stream error: {error_msg}")
210
 
211
  except Exception as e:
212
  log_error(f"❌ Fatal error in STT stream thread", error=str(e), traceback=traceback.format_exc())
213
  finally:
214
  log_info("🎤 Google STT stream thread ended")
215
+
216
+ def _put_result(self, result: TranscriptionResult):
217
+ """Helper to put result in queue"""
218
+ try:
219
+ self.responses_queue.put(result)
220
+ # Debug log'u kaldırdık
221
+ except Exception as e:
222
+ log_error(f"❌ Error queuing result: {e}")
223
 
224
  async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
225
  """Stream audio chunk and get transcription results"""