ciyidogan commited on
Commit
6472323
·
verified ·
1 Parent(s): 1340afa

Update stt/stt_deepgram.py

Browse files
Files changed (1) hide show
  1. stt/stt_deepgram.py +25 -25
stt/stt_deepgram.py CHANGED
@@ -262,49 +262,49 @@ class DeepgramSTT(STTInterface):
262
  """Stream audio chunk and get transcription results"""
263
  if not self.is_streaming or not self.live_connection:
264
  raise RuntimeError("Streaming not started. Call start_streaming() first.")
265
-
266
- # Don't send audio if final result already received
267
- if self.final_result_received:
268
- log_debug("Final result already received, ignoring audio chunk")
269
- return
270
-
271
  try:
272
- # İlk birkaç chunk için audio formatını analiz et
273
  if self.total_chunks < 3:
274
- # Linear16 formatı kontrolü
275
  if len(audio_chunk) >= 4:
276
- # İlk 2 byte'ı int16 olarak oku
277
  import struct
278
  try:
279
- # Linear16 ise ilk sample'ı okuyabilmeliyiz
280
  first_sample = struct.unpack('<h', audio_chunk[:2])[0]
281
  log_info(f"🔊 Audio format check - Chunk #{self.total_chunks}: First sample={first_sample}, Size={len(audio_chunk)} bytes")
282
-
283
- # Eğer WebM/Opus ise magic bytes farklı olur
284
- if audio_chunk[:4] == b'webm' or audio_chunk[:4] == b'\x1a\x45\xdf\xa3':
285
- log_error("❌ WebM format detected instead of Linear16!")
286
  except:
287
  log_warning("⚠️ Could not parse as Linear16")
288
-
289
- # Send audio to Deepgram
290
- self.live_connection.send(audio_chunk)
291
-
292
- self.total_chunks += 1
293
- self.total_audio_bytes += len(audio_chunk)
294
 
295
- # Log progress
296
- if self.total_chunks % 50 == 0:
297
- log_debug(f"📊 Listening... {self.total_chunks} chunks, {self.total_audio_bytes/1024:.1f}KB")
 
 
 
 
 
 
 
 
298
 
299
- # Check for final results
300
  while True:
301
  try:
302
  result = self.responses_queue.get_nowait()
 
 
 
 
303
  if result.is_final:
 
 
 
 
 
304
  yield result
 
305
  except queue.Empty:
306
  break
307
-
308
  except Exception as e:
309
  log_error(f"❌ Error streaming audio", error=str(e))
310
  self.is_streaming = False
 
262
  """Stream audio chunk and get transcription results"""
263
  if not self.is_streaming or not self.live_connection:
264
  raise RuntimeError("Streaming not started. Call start_streaming() first.")
265
+
 
 
 
 
 
266
  try:
267
+ # İlk birkaç chunk için audio formatını analiz et
268
  if self.total_chunks < 3:
 
269
  if len(audio_chunk) >= 4:
 
270
  import struct
271
  try:
 
272
  first_sample = struct.unpack('<h', audio_chunk[:2])[0]
273
  log_info(f"🔊 Audio format check - Chunk #{self.total_chunks}: First sample={first_sample}, Size={len(audio_chunk)} bytes")
 
 
 
 
274
  except:
275
  log_warning("⚠️ Could not parse as Linear16")
 
 
 
 
 
 
276
 
277
+ # Final result geldiyse audio gönderme ama queue'yu kontrol et
278
+ if not self.final_result_received:
279
+ # Send audio to Deepgram
280
+ self.live_connection.send(audio_chunk)
281
+
282
+ self.total_chunks += 1
283
+ self.total_audio_bytes += len(audio_chunk)
284
+
285
+ # Log progress
286
+ if self.total_chunks % 50 == 0:
287
+ log_debug(f"📊 Listening... {self.total_chunks} chunks, {self.total_audio_bytes/1024:.1f}KB")
288
 
289
+ # Her zaman queue'yu kontrol et ve result'ları yield et
290
  while True:
291
  try:
292
  result = self.responses_queue.get_nowait()
293
+
294
+ # Log for debugging
295
+ log_debug(f"🎯 Yielding result: is_final={result.is_final}, text='{result.text}'")
296
+
297
  if result.is_final:
298
+ self.final_result_received = True
299
+ yield result # ✅ Final result'ı yield et
300
+ # Artık yeni audio kabul etme
301
+ elif not self.final_result_received:
302
+ # Final gelmeden önce interim'leri yield et
303
  yield result
304
+
305
  except queue.Empty:
306
  break
307
+
308
  except Exception as e:
309
  log_error(f"❌ Error streaming audio", error=str(e))
310
  self.is_streaming = False