Spaces:
Building
Building
Update stt_factory.py
Browse files- stt_factory.py +9 -9
stt_factory.py
CHANGED
@@ -3,7 +3,7 @@ STT Provider Factory for Flare
|
|
3 |
"""
|
4 |
from typing import Optional
|
5 |
from stt_interface import STTInterface, STTEngineType
|
6 |
-
from
|
7 |
from stt_google import GoogleCloudSTT
|
8 |
from config_provider import ConfigProvider
|
9 |
from stt_interface import STTInterface
|
@@ -15,19 +15,19 @@ try:
|
|
15 |
from stt_google import GoogleCloudSTT
|
16 |
stt_providers['google'] = GoogleCloudSTT
|
17 |
except ImportError:
|
18 |
-
|
19 |
|
20 |
try:
|
21 |
from stt_azure import AzureSTT
|
22 |
stt_providers['azure'] = AzureSTT
|
23 |
except ImportError:
|
24 |
-
|
25 |
|
26 |
try:
|
27 |
from stt_flicker import FlickerSTT
|
28 |
stt_providers['flicker'] = FlickerSTT
|
29 |
except ImportError:
|
30 |
-
|
31 |
|
32 |
class NoSTT(STTInterface):
|
33 |
"""Dummy STT provider when STT is disabled"""
|
@@ -61,7 +61,7 @@ class STTFactory:
|
|
61 |
cfg = ConfigProvider.get()
|
62 |
stt_engine = cfg.global_config.stt_engine
|
63 |
|
64 |
-
|
65 |
|
66 |
if stt_engine == "no_stt":
|
67 |
return NoSTT()
|
@@ -69,14 +69,14 @@ class STTFactory:
|
|
69 |
# Get provider class
|
70 |
provider_class = stt_providers.get(stt_engine)
|
71 |
if not provider_class:
|
72 |
-
|
73 |
return NoSTT()
|
74 |
|
75 |
# Get API key or credentials
|
76 |
api_key = cfg.global_config.get_stt_api_key()
|
77 |
|
78 |
if not api_key:
|
79 |
-
|
80 |
return NoSTT()
|
81 |
|
82 |
# Create provider instance
|
@@ -87,7 +87,7 @@ class STTFactory:
|
|
87 |
# For Azure, parse the key format
|
88 |
parts = api_key.split('|')
|
89 |
if len(parts) != 2:
|
90 |
-
|
91 |
return NoSTT()
|
92 |
return provider_class(subscription_key=parts[0], region=parts[1])
|
93 |
elif stt_engine == "flicker":
|
@@ -96,7 +96,7 @@ class STTFactory:
|
|
96 |
return provider_class(api_key=api_key)
|
97 |
|
98 |
except Exception as e:
|
99 |
-
|
100 |
return NoSTT()
|
101 |
|
102 |
@staticmethod
|
|
|
3 |
"""
|
4 |
from typing import Optional
|
5 |
from stt_interface import STTInterface, STTEngineType
|
6 |
+
from logger import log_info, log_error, log_warning, log_debug
|
7 |
from stt_google import GoogleCloudSTT
|
8 |
from config_provider import ConfigProvider
|
9 |
from stt_interface import STTInterface
|
|
|
15 |
from stt_google import GoogleCloudSTT
|
16 |
stt_providers['google'] = GoogleCloudSTT
|
17 |
except ImportError:
|
18 |
+
log_info("⚠️ Google Cloud STT not available")
|
19 |
|
20 |
try:
|
21 |
from stt_azure import AzureSTT
|
22 |
stt_providers['azure'] = AzureSTT
|
23 |
except ImportError:
|
24 |
+
log_error("⚠️ Azure STT not available")
|
25 |
|
26 |
try:
|
27 |
from stt_flicker import FlickerSTT
|
28 |
stt_providers['flicker'] = FlickerSTT
|
29 |
except ImportError:
|
30 |
+
log_error("⚠️ Flicker STT not available")
|
31 |
|
32 |
class NoSTT(STTInterface):
|
33 |
"""Dummy STT provider when STT is disabled"""
|
|
|
61 |
cfg = ConfigProvider.get()
|
62 |
stt_engine = cfg.global_config.stt_engine
|
63 |
|
64 |
+
log_info(f"🎤 Creating STT provider: {stt_engine}")
|
65 |
|
66 |
if stt_engine == "no_stt":
|
67 |
return NoSTT()
|
|
|
69 |
# Get provider class
|
70 |
provider_class = stt_providers.get(stt_engine)
|
71 |
if not provider_class:
|
72 |
+
log_info(f"⚠️ STT provider '{stt_engine}' not available")
|
73 |
return NoSTT()
|
74 |
|
75 |
# Get API key or credentials
|
76 |
api_key = cfg.global_config.get_stt_api_key()
|
77 |
|
78 |
if not api_key:
|
79 |
+
log_info(f"⚠️ No API key configured for {stt_engine}")
|
80 |
return NoSTT()
|
81 |
|
82 |
# Create provider instance
|
|
|
87 |
# For Azure, parse the key format
|
88 |
parts = api_key.split('|')
|
89 |
if len(parts) != 2:
|
90 |
+
log_info("⚠️ Invalid Azure STT key format. Expected: subscription_key|region")
|
91 |
return NoSTT()
|
92 |
return provider_class(subscription_key=parts[0], region=parts[1])
|
93 |
elif stt_engine == "flicker":
|
|
|
96 |
return provider_class(api_key=api_key)
|
97 |
|
98 |
except Exception as e:
|
99 |
+
log_error("❌ Failed to create STT provider", e)
|
100 |
return NoSTT()
|
101 |
|
102 |
@staticmethod
|