Spaces:
Building
Building
Update stt_google.py
Browse files- stt_google.py +17 -2
stt_google.py
CHANGED
@@ -110,6 +110,9 @@ class GoogleCloudSTT(STTInterface):
|
|
110 |
loop = asyncio.new_event_loop()
|
111 |
asyncio.set_event_loop(loop)
|
112 |
|
|
|
|
|
|
|
113 |
def request_generator():
|
114 |
"""Generate streaming requests"""
|
115 |
chunk_count = 0
|
@@ -151,11 +154,20 @@ class GoogleCloudSTT(STTInterface):
|
|
151 |
timestamp=datetime.now().timestamp()
|
152 |
)
|
153 |
|
154 |
-
# Put result in async queue -
|
155 |
-
loop.create_task(self._put_result(transcription))
|
|
|
156 |
|
157 |
log_debug(f"📝 STT result: {result.alternatives[0].transcript}, final: {result.is_final}")
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
except Exception as e:
|
160 |
error_msg = str(e)
|
161 |
log_error(f"❌ Google STT stream error", error=error_msg, traceback=traceback.format_exc())
|
@@ -169,6 +181,9 @@ class GoogleCloudSTT(STTInterface):
|
|
169 |
log_error(f"❌ Google STT timeout - possibly network issue or slow connection")
|
170 |
|
171 |
finally:
|
|
|
|
|
|
|
172 |
log_info("🎤 Google STT stream thread ended")
|
173 |
loop.close()
|
174 |
|
|
|
110 |
loop = asyncio.new_event_loop()
|
111 |
asyncio.set_event_loop(loop)
|
112 |
|
113 |
+
# Task listesi tut
|
114 |
+
pending_tasks = []
|
115 |
+
|
116 |
def request_generator():
|
117 |
"""Generate streaming requests"""
|
118 |
chunk_count = 0
|
|
|
154 |
timestamp=datetime.now().timestamp()
|
155 |
)
|
156 |
|
157 |
+
# Put result in async queue - create task and add to list
|
158 |
+
task = loop.create_task(self._put_result(transcription))
|
159 |
+
pending_tasks.append(task)
|
160 |
|
161 |
log_debug(f"📝 STT result: {result.alternatives[0].transcript}, final: {result.is_final}")
|
162 |
|
163 |
+
# ÖNEMLI: Final result'u loglayalım
|
164 |
+
if result.is_final:
|
165 |
+
log_info(f"🎯 FINAL STT RESULT: {result.alternatives[0].transcript}")
|
166 |
+
|
167 |
+
# Wait for all pending tasks before closing loop
|
168 |
+
if pending_tasks:
|
169 |
+
loop.run_until_complete(asyncio.gather(*pending_tasks, return_exceptions=True))
|
170 |
+
|
171 |
except Exception as e:
|
172 |
error_msg = str(e)
|
173 |
log_error(f"❌ Google STT stream error", error=error_msg, traceback=traceback.format_exc())
|
|
|
181 |
log_error(f"❌ Google STT timeout - possibly network issue or slow connection")
|
182 |
|
183 |
finally:
|
184 |
+
# Wait for remaining tasks
|
185 |
+
if pending_tasks:
|
186 |
+
loop.run_until_complete(asyncio.gather(*pending_tasks, return_exceptions=True))
|
187 |
log_info("🎤 Google STT stream thread ended")
|
188 |
loop.close()
|
189 |
|