Spaces:
Building
Building
Update realtime_stt_manager.py
Browse files- realtime_stt_manager.py +7 -7
realtime_stt_manager.py
CHANGED
@@ -8,7 +8,7 @@ import sys
|
|
8 |
|
9 |
from stt_interface import STTInterface, STTConfig, TranscriptionResult
|
10 |
from config_provider import ConfigProvider
|
11 |
-
from
|
12 |
|
13 |
class STTStreamManager:
|
14 |
"""Manages real-time STT streaming"""
|
@@ -39,12 +39,12 @@ class STTStreamManager:
|
|
39 |
# Start streaming session
|
40 |
await self.stt_provider.start_streaming(self.config)
|
41 |
self.is_streaming = True
|
42 |
-
|
43 |
|
44 |
async def process_chunk(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
45 |
"""Process audio chunk and yield transcription results"""
|
46 |
if not self.is_streaming or not self.stt_provider:
|
47 |
-
|
48 |
return
|
49 |
|
50 |
try:
|
@@ -58,7 +58,7 @@ class STTStreamManager:
|
|
58 |
yield result
|
59 |
|
60 |
except Exception as e:
|
61 |
-
|
62 |
# Yield error result
|
63 |
yield TranscriptionResult(
|
64 |
text="",
|
@@ -81,18 +81,18 @@ class STTStreamManager:
|
|
81 |
self.accumulated_text = final_result.text
|
82 |
self.last_final_result = final_result
|
83 |
|
84 |
-
|
85 |
return final_result
|
86 |
|
87 |
except Exception as e:
|
88 |
-
|
89 |
return None
|
90 |
|
91 |
def reset(self):
|
92 |
"""Reset accumulated text and state"""
|
93 |
self.accumulated_text = ""
|
94 |
self.last_final_result = None
|
95 |
-
|
96 |
|
97 |
def get_accumulated_text(self) -> str:
|
98 |
"""Get all accumulated text from the session"""
|
|
|
8 |
|
9 |
from stt_interface import STTInterface, STTConfig, TranscriptionResult
|
10 |
from config_provider import ConfigProvider
|
11 |
+
from logger import log_info, log_error, log_warning, log_debug
|
12 |
|
13 |
class STTStreamManager:
|
14 |
"""Manages real-time STT streaming"""
|
|
|
39 |
# Start streaming session
|
40 |
await self.stt_provider.start_streaming(self.config)
|
41 |
self.is_streaming = True
|
42 |
+
log_info("β
STT stream manager initialized")
|
43 |
|
44 |
async def process_chunk(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
45 |
"""Process audio chunk and yield transcription results"""
|
46 |
if not self.is_streaming or not self.stt_provider:
|
47 |
+
log_info("β οΈ STT not streaming or provider not initialized")
|
48 |
return
|
49 |
|
50 |
try:
|
|
|
58 |
yield result
|
59 |
|
60 |
except Exception as e:
|
61 |
+
log_error("β STT processing error", e)
|
62 |
# Yield error result
|
63 |
yield TranscriptionResult(
|
64 |
text="",
|
|
|
81 |
self.accumulated_text = final_result.text
|
82 |
self.last_final_result = final_result
|
83 |
|
84 |
+
log_info("β
STT streaming stopped")
|
85 |
return final_result
|
86 |
|
87 |
except Exception as e:
|
88 |
+
log_error("β Error stopping STT stream", e)
|
89 |
return None
|
90 |
|
91 |
def reset(self):
|
92 |
"""Reset accumulated text and state"""
|
93 |
self.accumulated_text = ""
|
94 |
self.last_final_result = None
|
95 |
+
log_info("π STT stream manager reset")
|
96 |
|
97 |
def get_accumulated_text(self) -> str:
|
98 |
"""Get all accumulated text from the session"""
|