File size: 2,145 Bytes
0da26ae
e579c02
0da26ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e579c02
 
 
 
 
0da26ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
STT (Speech-to-Text) Interface for Flare
"""
from abc import ABC, abstractmethod
from typing import Optional, Dict, Any, AsyncIterator, List
from dataclasses import dataclass
from enum import Enum
import json

class STTEngineType(Enum):
    NO_STT = "no_stt"
    GOOGLE = "google"
    AZURE = "azure"
    AMAZON = "amazon"
    FLICKER = "flicker"

@dataclass
class STTConfig:
    """STT configuration parameters"""
    language: str = "tr-TR"
    sample_rate: int = 16000
    encoding: str = "WEBM_OPUS"
    enable_punctuation: bool = True
    enable_word_timestamps: bool = False
    model: str = "latest_long"
    use_enhanced: bool = True
    single_utterance: bool = False
    interim_results: bool = True
    
    # Voice Activity Detection
    vad_enabled: bool = True
    speech_timeout_ms: int = 2000
    
    # Noise reduction
    noise_reduction_enabled: bool = True
    noise_reduction_level: int = 2

@dataclass
class TranscriptionResult:
    """Result from STT engine"""
    text: str
    is_final: bool
    confidence: float
    timestamp: float
    word_timestamps: Optional[List[Dict]] = None
    language: Optional[str] = None
    is_interrupt: bool = False

class STTInterface(ABC):
    """Abstract base class for STT providers"""
    
    @abstractmethod
    async def start_streaming(self, config: STTConfig) -> None:
        """Start streaming session"""
        pass
    
    @abstractmethod
    async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
        """Stream audio chunk and get transcription results"""
        pass
    
    @abstractmethod
    async def stop_streaming(self) -> Optional[TranscriptionResult]:
        """Stop streaming and get final result"""
        pass
    
    @abstractmethod
    def supports_realtime(self) -> bool:
        """Check if provider supports real-time streaming"""
        pass
    
    @abstractmethod
    def get_supported_languages(self) -> List[str]:
        """Get list of supported language codes"""
        pass
    
    @abstractmethod
    def get_provider_name(self) -> str:
        """Get provider name for logging"""
        pass