Spaces:
Paused
Paused
Update tts_preprocessor.py
Browse files- tts_preprocessor.py +2 -28
tts_preprocessor.py
CHANGED
|
@@ -7,6 +7,7 @@ import json
|
|
| 7 |
from typing import Dict, Set, Optional
|
| 8 |
from num2words import num2words
|
| 9 |
from pathlib import Path
|
|
|
|
| 10 |
|
| 11 |
class TTSPreprocessor:
|
| 12 |
"""Text preprocessor for TTS providers with multilingual support"""
|
|
@@ -21,34 +22,7 @@ class TTSPreprocessor:
|
|
| 21 |
|
| 22 |
def __init__(self, language: str = "tr"):
|
| 23 |
self.language = language
|
| 24 |
-
self.locale_data =
|
| 25 |
-
|
| 26 |
-
def _load_locale(self, language: str) -> Dict:
|
| 27 |
-
"""Load locale data from JSON file"""
|
| 28 |
-
locale_path = Path(__file__).parent / "locales" / f"{language}.json"
|
| 29 |
-
|
| 30 |
-
# Fallback to English if locale not found
|
| 31 |
-
if not locale_path.exists():
|
| 32 |
-
print(f"⚠️ Locale file not found for {language}, falling back to English")
|
| 33 |
-
locale_path = Path(__file__).parent / "locales" / "en.json"
|
| 34 |
-
|
| 35 |
-
try:
|
| 36 |
-
with open(locale_path, 'r', encoding='utf-8') as f:
|
| 37 |
-
return json.load(f)
|
| 38 |
-
except Exception as e:
|
| 39 |
-
print(f"❌ Error loading locale {language}: {e}")
|
| 40 |
-
# Return minimal default structure
|
| 41 |
-
return {
|
| 42 |
-
"language_code": language,
|
| 43 |
-
"currency": {"symbols": {}, "codes": {}},
|
| 44 |
-
"months": {},
|
| 45 |
-
"numbers": {
|
| 46 |
-
"decimal_separator": ".",
|
| 47 |
-
"thousands_separator": ",",
|
| 48 |
-
"decimal_word": "point"
|
| 49 |
-
},
|
| 50 |
-
"small_number_threshold": 100
|
| 51 |
-
}
|
| 52 |
|
| 53 |
def preprocess(self, text: str, flags: Set[str]) -> str:
|
| 54 |
"""Apply preprocessing based on flags"""
|
|
|
|
| 7 |
from typing import Dict, Set, Optional
|
| 8 |
from num2words import num2words
|
| 9 |
from pathlib import Path
|
| 10 |
+
from locale_manager import LocaleManager
|
| 11 |
|
| 12 |
class TTSPreprocessor:
|
| 13 |
"""Text preprocessor for TTS providers with multilingual support"""
|
|
|
|
| 22 |
|
| 23 |
def __init__(self, language: str = "tr"):
|
| 24 |
self.language = language
|
| 25 |
+
self.locale_data = LocaleManager.get_locale(language)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def preprocess(self, text: str, flags: Set[str]) -> str:
|
| 28 |
"""Apply preprocessing based on flags"""
|