Spaces:
Running
Running
Update stt/stt_google.py
Browse files- stt/stt_google.py +29 -68
stt/stt_google.py
CHANGED
@@ -105,83 +105,44 @@ class GoogleCloudSTT(STTInterface):
|
|
105 |
raise
|
106 |
|
107 |
async def stop_streaming(self) -> Optional[TranscriptionResult]:
|
108 |
-
"""Stop streaming and
|
109 |
-
if not self.is_streaming
|
110 |
-
log_debug("Already stopped, nothing to do")
|
111 |
return None
|
112 |
-
|
113 |
try:
|
114 |
-
log_info(
|
115 |
-
|
116 |
-
# Flag'i hemen kapat
|
117 |
self.is_streaming = False
|
118 |
self.stop_event.set()
|
119 |
-
|
120 |
-
# Send poison pill to
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
pass
|
126 |
-
|
127 |
-
# Thread'i durdur
|
128 |
-
if self.stream_thread and self.stream_thread.is_alive():
|
129 |
-
log_info("⏳ Waiting for stream thread to finish...")
|
130 |
self.stream_thread.join(timeout=5.0)
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
138 |
final_result = None
|
139 |
-
|
140 |
-
while not self.responses_queue.empty():
|
141 |
-
try:
|
142 |
-
result = self.responses_queue.get_nowait()
|
143 |
-
if result.is_final:
|
144 |
-
final_result = result
|
145 |
-
except:
|
146 |
-
pass
|
147 |
-
|
148 |
-
# Client'ı kapat
|
149 |
-
if self.client:
|
150 |
try:
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
except Exception as e:
|
159 |
-
log_warning(f"⚠️ Error closing Google client: {e}")
|
160 |
-
finally:
|
161 |
-
self.client = None
|
162 |
-
|
163 |
-
# Queue'ları None yap
|
164 |
-
self.audio_queue = None
|
165 |
-
self.responses_queue = None
|
166 |
-
|
167 |
-
# Diğer değişkenleri resetle
|
168 |
-
self.stream_thread = None
|
169 |
-
self.streaming_config = None
|
170 |
-
self.stop_event.clear()
|
171 |
-
|
172 |
-
log_info(f"✅ Google STT streaming session #{self.session_id} stopped and cleaned")
|
173 |
return final_result
|
174 |
-
|
175 |
except Exception as e:
|
176 |
-
log_error(f"❌
|
177 |
-
# Force cleanup on error
|
178 |
-
self.is_streaming = False
|
179 |
-
self.stream_thread = None
|
180 |
-
self.client = None
|
181 |
-
self.streaming_config = None
|
182 |
-
self.stop_event.clear()
|
183 |
-
self.audio_queue = None
|
184 |
-
self.responses_queue = None
|
185 |
return None
|
186 |
|
187 |
def supports_realtime(self) -> bool:
|
|
|
105 |
raise
|
106 |
|
107 |
async def stop_streaming(self) -> Optional[TranscriptionResult]:
|
108 |
+
"""Stop streaming and get final result"""
|
109 |
+
if not self.is_streaming:
|
|
|
110 |
return None
|
111 |
+
|
112 |
try:
|
113 |
+
log_info("🛑 Stopping Google STT streaming...")
|
114 |
+
|
|
|
115 |
self.is_streaming = False
|
116 |
self.stop_event.set()
|
117 |
+
|
118 |
+
# Send poison pill to queue
|
119 |
+
self.audio_queue.put(None)
|
120 |
+
|
121 |
+
# Wait for thread to finish
|
122 |
+
if self.stream_thread:
|
|
|
|
|
|
|
|
|
|
|
123 |
self.stream_thread.join(timeout=5.0)
|
124 |
+
|
125 |
+
# Clear queues
|
126 |
+
while not self.audio_queue.empty():
|
127 |
+
try:
|
128 |
+
self.audio_queue.get_nowait()
|
129 |
+
except queue.Empty:
|
130 |
+
break
|
131 |
+
|
132 |
final_result = None
|
133 |
+
while not self.responses_queue.empty():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
try:
|
135 |
+
result = self.responses_queue.get_nowait() # ✅ get_nowait() kullan, await değil
|
136 |
+
if result.is_final:
|
137 |
+
final_result = result
|
138 |
+
except queue.Empty:
|
139 |
+
break
|
140 |
+
|
141 |
+
log_info("✅ Google STT streaming stopped")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
return final_result
|
143 |
+
|
144 |
except Exception as e:
|
145 |
+
log_error(f"❌ Failed to stop Google STT streaming", error=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
return None
|
147 |
|
148 |
def supports_realtime(self) -> bool:
|