Spaces:
Building
Building
Update stt/stt_google.py
Browse files- stt/stt_google.py +38 -14
stt/stt_google.py
CHANGED
@@ -290,21 +290,36 @@ class GoogleSTT(STTInterface):
|
|
290 |
|
291 |
def _audio_generator(self):
|
292 |
"""Generator that yields audio chunks for streaming"""
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
break
|
300 |
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
310 |
"""Stream audio chunk and get transcription results"""
|
@@ -312,6 +327,15 @@ class GoogleSTT(STTInterface):
|
|
312 |
raise RuntimeError("Streaming not started. Call start_streaming() first.")
|
313 |
|
314 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
# Add audio to queue for background thread
|
316 |
self.audio_queue.put(audio_chunk)
|
317 |
|
|
|
290 |
|
291 |
def _audio_generator(self):
|
292 |
"""Generator that yields audio chunks for streaming"""
|
293 |
+
chunk_count = 0
|
294 |
+
try:
|
295 |
+
while not self.stop_event.is_set():
|
296 |
+
try:
|
297 |
+
# Get audio chunk with timeout
|
298 |
+
chunk = self.audio_queue.get(timeout=0.1)
|
|
|
299 |
|
300 |
+
if chunk is None: # Sentinel value
|
301 |
+
log_debug("🔚 Audio generator received sentinel, stopping")
|
302 |
+
break
|
303 |
+
|
304 |
+
# ✅ Debug için chunk bilgisi
|
305 |
+
chunk_count += 1
|
306 |
+
if chunk_count <= 5: # İlk 5 chunk için detaylı log
|
307 |
+
log_debug(f"🎵 Audio generator yielding chunk #{chunk_count}, size: {len(chunk)} bytes")
|
308 |
+
# Chunk'ın byte tipinde olduğundan emin ol
|
309 |
+
if not isinstance(chunk, bytes):
|
310 |
+
log_error(f"❌ Chunk is not bytes! Type: {type(chunk)}")
|
311 |
+
continue
|
312 |
+
|
313 |
+
# ✅ Google API'nin beklediği format
|
314 |
+
yield chunk
|
315 |
+
|
316 |
+
except queue.Empty:
|
317 |
+
continue
|
318 |
+
except Exception as e:
|
319 |
+
log_error(f"❌ Audio generator error: {str(e)}")
|
320 |
+
break
|
321 |
+
finally:
|
322 |
+
log_debug(f"🎙️ Audio generator stopped after {chunk_count} chunks")
|
323 |
|
324 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
325 |
"""Stream audio chunk and get transcription results"""
|
|
|
327 |
raise RuntimeError("Streaming not started. Call start_streaming() first.")
|
328 |
|
329 |
try:
|
330 |
+
# ✅ Audio chunk tipini kontrol et
|
331 |
+
if not isinstance(audio_chunk, bytes):
|
332 |
+
log_error(f"❌ Audio chunk is not bytes! Type: {type(audio_chunk)}")
|
333 |
+
raise TypeError(f"Expected bytes, got {type(audio_chunk)}")
|
334 |
+
|
335 |
+
# ✅ Chunk boyutunu logla
|
336 |
+
if self.total_chunks < 5:
|
337 |
+
log_debug(f"📦 Adding audio chunk #{self.total_chunks} to queue, size: {len(audio_chunk)} bytes")
|
338 |
+
|
339 |
# Add audio to queue for background thread
|
340 |
self.audio_queue.put(audio_chunk)
|
341 |
|