Spaces:
Building
Building
Update stt/stt_interface.py
Browse files- stt/stt_interface.py +64 -79
stt/stt_interface.py
CHANGED
@@ -1,80 +1,65 @@
|
|
1 |
-
"""
|
2 |
-
STT (Speech-to-Text) Interface for Flare
|
3 |
-
"""
|
4 |
-
from abc import ABC, abstractmethod
|
5 |
-
from typing import Optional,
|
6 |
-
from dataclasses import dataclass
|
7 |
-
from enum import Enum
|
8 |
-
|
9 |
-
|
10 |
-
class STTEngineType(Enum):
|
11 |
-
NO_STT = "no_stt"
|
12 |
-
GOOGLE = "google"
|
13 |
-
AZURE = "azure"
|
14 |
-
AMAZON = "amazon"
|
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 |
-
pass
|
56 |
-
|
57 |
-
@abstractmethod
|
58 |
-
|
59 |
-
"""
|
60 |
-
pass
|
61 |
-
|
62 |
-
@abstractmethod
|
63 |
-
|
64 |
-
"""
|
65 |
-
pass
|
66 |
-
|
67 |
-
@abstractmethod
|
68 |
-
def supports_realtime(self) -> bool:
|
69 |
-
"""Check if provider supports real-time streaming"""
|
70 |
-
pass
|
71 |
-
|
72 |
-
@abstractmethod
|
73 |
-
def get_supported_languages(self) -> List[str]:
|
74 |
-
"""Get list of supported language codes"""
|
75 |
-
pass
|
76 |
-
|
77 |
-
@abstractmethod
|
78 |
-
def get_provider_name(self) -> str:
|
79 |
-
"""Get provider name for logging"""
|
80 |
pass
|
|
|
1 |
+
"""
|
2 |
+
STT (Speech-to-Text) Interface for Flare - Simple Batch Mode
|
3 |
+
"""
|
4 |
+
from abc import ABC, abstractmethod
|
5 |
+
from typing import Optional, List
|
6 |
+
from dataclasses import dataclass
|
7 |
+
from enum import Enum
|
8 |
+
|
9 |
+
|
10 |
+
class STTEngineType(Enum):
|
11 |
+
NO_STT = "no_stt"
|
12 |
+
GOOGLE = "google"
|
13 |
+
AZURE = "azure"
|
14 |
+
AMAZON = "amazon"
|
15 |
+
DEEPGRAM = "deepgram"
|
16 |
+
|
17 |
+
|
18 |
+
@dataclass
|
19 |
+
class STTConfig:
|
20 |
+
"""STT configuration parameters"""
|
21 |
+
language: str = "tr-TR"
|
22 |
+
sample_rate: int = 16000
|
23 |
+
encoding: str = "LINEAR16"
|
24 |
+
enable_punctuation: bool = True
|
25 |
+
enable_word_timestamps: bool = False
|
26 |
+
model: str = "latest_long"
|
27 |
+
use_enhanced: bool = True
|
28 |
+
|
29 |
+
|
30 |
+
@dataclass
|
31 |
+
class TranscriptionResult:
|
32 |
+
"""Result from STT engine"""
|
33 |
+
text: str
|
34 |
+
confidence: float
|
35 |
+
timestamp: float
|
36 |
+
language: Optional[str] = None
|
37 |
+
word_timestamps: Optional[List[dict]] = None
|
38 |
+
|
39 |
+
|
40 |
+
class STTInterface(ABC):
|
41 |
+
"""Abstract base class for STT providers - Simple batch mode"""
|
42 |
+
|
43 |
+
@abstractmethod
|
44 |
+
async def transcribe(self, audio_data: bytes, config: STTConfig) -> Optional[TranscriptionResult]:
|
45 |
+
"""
|
46 |
+
Transcribe audio data
|
47 |
+
|
48 |
+
Args:
|
49 |
+
audio_data: Raw PCM audio data (LINEAR16 format)
|
50 |
+
config: STT configuration
|
51 |
+
|
52 |
+
Returns:
|
53 |
+
TranscriptionResult or None if no speech detected
|
54 |
+
"""
|
55 |
+
pass
|
56 |
+
|
57 |
+
@abstractmethod
|
58 |
+
def get_supported_languages(self) -> List[str]:
|
59 |
+
"""Get list of supported language codes"""
|
60 |
+
pass
|
61 |
+
|
62 |
+
@abstractmethod
|
63 |
+
def get_provider_name(self) -> str:
|
64 |
+
"""Get provider name for logging"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
pass
|