Spaces:
Paused
Paused
Update stt/stt_deepgram.py
Browse files- stt/stt_deepgram.py +49 -35
stt/stt_deepgram.py
CHANGED
@@ -110,11 +110,12 @@ class DeepgramSTT(STTInterface):
|
|
110 |
options = LiveOptions(
|
111 |
language="tr",
|
112 |
model="nova-2",
|
113 |
-
encoding="
|
114 |
sample_rate=16000,
|
115 |
-
interim_results=True,
|
116 |
-
utterance_end_ms=1000,
|
117 |
punctuate=True,
|
|
|
118 |
)
|
119 |
|
120 |
log_info(f"π§ Deepgram options: language=tr, model=nova-2, encoding=opus, interim_results=True")
|
@@ -167,44 +168,57 @@ class DeepgramSTT(STTInterface):
|
|
167 |
return
|
168 |
|
169 |
# Results handler - handles transcription results
|
170 |
-
def
|
|
|
171 |
try:
|
172 |
-
|
173 |
-
|
174 |
-
# Extract transcription
|
175 |
-
channel = result.get("channel", {})
|
176 |
-
alternatives = channel.get("alternatives", [])
|
177 |
|
178 |
-
if
|
179 |
-
|
180 |
-
|
181 |
-
is_final = result.get("is_final", False)
|
182 |
-
|
183 |
-
log_info(f"π Transcript: '{transcript}' (is_final: {is_final}, confidence: {confidence})")
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
193 |
|
194 |
-
#
|
195 |
-
|
196 |
-
self.responses_queue.put(transcription_result)
|
197 |
-
if is_final:
|
198 |
-
self.final_result_received = True
|
199 |
-
log_info(f"π― FINAL RESULT queued: '{transcript}'")
|
200 |
-
else:
|
201 |
-
log_debug(f"π Interim result: '{transcript}'")
|
202 |
-
except queue.Full:
|
203 |
-
log_warning("β οΈ Response queue full")
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
except Exception as e:
|
206 |
-
log_error(f"β Error
|
207 |
-
log_error(f"β
|
|
|
|
|
|
|
208 |
|
209 |
# Speech started handler
|
210 |
def on_speech_started(self, speech_started, **kwargs):
|
|
|
110 |
options = LiveOptions(
|
111 |
language="tr",
|
112 |
model="nova-2",
|
113 |
+
encoding="linear16", # β
Change from opus to linear16
|
114 |
sample_rate=16000,
|
115 |
+
interim_results=True,
|
116 |
+
utterance_end_ms=1000,
|
117 |
punctuate=True,
|
118 |
+
channels=1,
|
119 |
)
|
120 |
|
121 |
log_info(f"π§ Deepgram options: language=tr, model=nova-2, encoding=opus, interim_results=True")
|
|
|
168 |
return
|
169 |
|
170 |
# Results handler - handles transcription results
|
171 |
+
def _on_transcript(self, *args, **kwargs):
|
172 |
+
"""Handle transcript event - SDK calls this method directly"""
|
173 |
try:
|
174 |
+
# SDK passes the result as second argument
|
175 |
+
result = args[1] if len(args) > 1 else kwargs.get("result")
|
|
|
|
|
|
|
176 |
|
177 |
+
if not result:
|
178 |
+
log_warning("β οΈ No result in transcript event")
|
179 |
+
return
|
|
|
|
|
|
|
180 |
|
181 |
+
# Access properties directly from the result object
|
182 |
+
is_final = result.is_final
|
183 |
+
|
184 |
+
# Get transcript from channel alternatives
|
185 |
+
if hasattr(result, 'channel') and result.channel:
|
186 |
+
alternatives = result.channel.alternatives
|
187 |
+
if alternatives and len(alternatives) > 0:
|
188 |
+
transcript = alternatives[0].transcript
|
189 |
+
confidence = alternatives[0].confidence
|
190 |
|
191 |
+
# Log all transcripts for debugging
|
192 |
+
log_debug(f"π Raw transcript: '{transcript}' (is_final: {is_final}, confidence: {confidence})")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
+
if transcript and transcript.strip(): # Only process non-empty transcripts
|
195 |
+
transcription_result = TranscriptionResult(
|
196 |
+
text=transcript,
|
197 |
+
is_final=is_final,
|
198 |
+
confidence=confidence,
|
199 |
+
timestamp=datetime.now().timestamp()
|
200 |
+
)
|
201 |
+
|
202 |
+
# Queue result
|
203 |
+
try:
|
204 |
+
self.responses_queue.put(transcription_result)
|
205 |
+
if is_final:
|
206 |
+
self.final_result_received = True
|
207 |
+
log_info(f"π― FINAL TRANSCRIPT: '{transcript}' (confidence: {confidence:.2f})")
|
208 |
+
else:
|
209 |
+
log_info(f"π Interim transcript: '{transcript}'")
|
210 |
+
except queue.Full:
|
211 |
+
log_warning("β οΈ Response queue full")
|
212 |
+
else:
|
213 |
+
if is_final:
|
214 |
+
log_warning(f"β οΈ Empty final transcript received")
|
215 |
+
|
216 |
except Exception as e:
|
217 |
+
log_error(f"β Error processing transcript: {e}")
|
218 |
+
log_error(f"β Args: {args}")
|
219 |
+
log_error(f"β Kwargs: {kwargs}")
|
220 |
+
import traceback
|
221 |
+
log_error(f"β Traceback: {traceback.format_exc()}")
|
222 |
|
223 |
# Speech started handler
|
224 |
def on_speech_started(self, speech_started, **kwargs):
|