ciyidogan commited on
Commit
488c215
·
verified ·
1 Parent(s): a8701f1

Delete realtime_stt_manager.py

Browse files
Files changed (1) hide show
  1. realtime_stt_manager.py +0 -104
realtime_stt_manager.py DELETED
@@ -1,104 +0,0 @@
1
- """
2
- Real-time STT Manager for streaming transcription
3
- """
4
- from typing import AsyncIterator, Optional, Dict, Any
5
- import asyncio
6
- from datetime import datetime
7
- import sys
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"""
15
-
16
- def __init__(self):
17
- self.stt_provider: Optional[STTInterface] = None
18
- self.is_streaming = False
19
- self.config = None
20
- self.accumulated_text = ""
21
- self.last_final_result = None
22
-
23
- async def initialize(self, stt_provider: STTInterface, config: Dict[str, Any]):
24
- """Initialize STT stream manager"""
25
- self.stt_provider = stt_provider
26
-
27
- # STTConfig objesi oluştur
28
- self.config = STTConfig(
29
- language=config.get("language", "tr-TR"),
30
- sample_rate=config.get("sample_rate", 16000),
31
- encoding=config.get("encoding", "WEBM_OPUS"),
32
- enable_punctuation=config.get("enable_punctuation", True),
33
- interim_results=config.get("interim_results", True),
34
- single_utterance=False, # Important for continuous listening
35
- speech_timeout_ms=config.get("speech_timeout_ms", 2000),
36
- vad_enabled=config.get("vad_enabled", True),
37
- noise_reduction_enabled=config.get("noise_reduction_enabled", True),
38
- noise_reduction_level=config.get("noise_reduction_level", 2),
39
- enable_word_timestamps=config.get("enable_word_timestamps", False),
40
- model=config.get("model", "latest_long"),
41
- use_enhanced=config.get("use_enhanced", True)
42
- )
43
-
44
- # Start streaming session - artık STTConfig objesi gönderiyoruz
45
- await self.stt_provider.start_streaming(self.config)
46
- self.is_streaming = True
47
- log_info("✅ STT stream manager initialized")
48
-
49
- async def process_chunk(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
50
- """Process audio chunk and yield transcription results"""
51
- if not self.is_streaming or not self.stt_provider:
52
- log_info("⚠️ STT not streaming or provider not initialized")
53
- return
54
-
55
- try:
56
- # Stream audio to STT provider
57
- async for result in self.stt_provider.stream_audio(audio_chunk):
58
- # Update accumulated text for final results
59
- if result.is_final:
60
- self.accumulated_text = result.text
61
- self.last_final_result = result
62
-
63
- yield result
64
-
65
- except Exception as e:
66
- log_error("❌ STT processing error", e)
67
- # Yield error result
68
- yield TranscriptionResult(
69
- text="",
70
- is_final=False,
71
- confidence=0.0,
72
- timestamp=datetime.now().timestamp(),
73
- is_interrupt=True
74
- )
75
-
76
- async def stop_streaming(self) -> Optional[TranscriptionResult]:
77
- """Stop streaming and get final result"""
78
- if not self.is_streaming or not self.stt_provider:
79
- return None
80
-
81
- try:
82
- self.is_streaming = False
83
- final_result = await self.stt_provider.stop_streaming()
84
-
85
- if final_result:
86
- self.accumulated_text = final_result.text
87
- self.last_final_result = final_result
88
-
89
- log_info("✅ STT streaming stopped")
90
- return final_result
91
-
92
- except Exception as e:
93
- log_error("❌ Error stopping STT stream", e)
94
- return None
95
-
96
- def reset(self):
97
- """Reset accumulated text and state"""
98
- self.accumulated_text = ""
99
- self.last_final_result = None
100
- log_info("🔄 STT stream manager reset")
101
-
102
- def get_accumulated_text(self) -> str:
103
- """Get all accumulated text from the session"""
104
- return self.accumulated_text