Spaces:
Building
Building
Update stt_google.py
Browse files- stt_google.py +18 -9
stt_google.py
CHANGED
@@ -94,6 +94,10 @@ class GoogleCloudSTT(STTInterface):
|
|
94 |
try:
|
95 |
log_info("π€ Google STT stream thread started")
|
96 |
|
|
|
|
|
|
|
|
|
97 |
def request_generator():
|
98 |
"""Generate streaming requests"""
|
99 |
while not self.stop_event.is_set():
|
@@ -117,17 +121,17 @@ class GoogleCloudSTT(STTInterface):
|
|
117 |
|
118 |
for result in response.results:
|
119 |
if result.alternatives:
|
120 |
-
#
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
timestamp=datetime.now().timestamp()
|
127 |
-
)),
|
128 |
-
asyncio.get_event_loop()
|
129 |
)
|
130 |
|
|
|
|
|
|
|
131 |
log_debug(f"π STT result: {result.alternatives[0].transcript}, final: {result.is_final}")
|
132 |
|
133 |
except Exception as e:
|
@@ -142,6 +146,11 @@ class GoogleCloudSTT(STTInterface):
|
|
142 |
|
143 |
finally:
|
144 |
log_info("π€ Google STT stream thread ended")
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
147 |
"""Stream audio chunk and get transcription results"""
|
|
|
94 |
try:
|
95 |
log_info("π€ Google STT stream thread started")
|
96 |
|
97 |
+
# Create a new event loop for this thread
|
98 |
+
loop = asyncio.new_event_loop()
|
99 |
+
asyncio.set_event_loop(loop)
|
100 |
+
|
101 |
def request_generator():
|
102 |
"""Generate streaming requests"""
|
103 |
while not self.stop_event.is_set():
|
|
|
121 |
|
122 |
for result in response.results:
|
123 |
if result.alternatives:
|
124 |
+
# Create transcription result
|
125 |
+
transcription = TranscriptionResult(
|
126 |
+
text=result.alternatives[0].transcript,
|
127 |
+
is_final=result.is_final,
|
128 |
+
confidence=result.alternatives[0].confidence if result.alternatives[0].confidence else 0.0,
|
129 |
+
timestamp=datetime.now().timestamp()
|
|
|
|
|
|
|
130 |
)
|
131 |
|
132 |
+
# Put result in async queue - use loop.create_task
|
133 |
+
loop.create_task(self._put_result(transcription))
|
134 |
+
|
135 |
log_debug(f"π STT result: {result.alternatives[0].transcript}, final: {result.is_final}")
|
136 |
|
137 |
except Exception as e:
|
|
|
146 |
|
147 |
finally:
|
148 |
log_info("π€ Google STT stream thread ended")
|
149 |
+
loop.close()
|
150 |
+
|
151 |
+
async def _put_result(self, result: TranscriptionResult):
|
152 |
+
"""Helper to put result in queue"""
|
153 |
+
await self.responses_queue.put(result)
|
154 |
|
155 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
156 |
"""Stream audio chunk and get transcription results"""
|