Spaces:
Building
Building
Update tts_interface.py
Browse files- tts_interface.py +20 -1
tts_interface.py
CHANGED
@@ -46,13 +46,29 @@ class ElevenLabsTTS(TTSInterface):
|
|
46 |
self.base_url = "https://api.elevenlabs.io/v1"
|
47 |
self.default_voice_id = "2thYbn2sOGtiTwd9QwWH" # Avencia
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
masked_key = f"{api_key[:4]}...{api_key[-4:]}" if len(api_key) > 8 else "***"
|
51 |
log(f"🔑 ElevenLabsTTS initialized with key: {masked_key}")
|
52 |
|
53 |
async def synthesize(self, text: str, voice_id: Optional[str] = None, **kwargs) -> bytes:
|
54 |
"""Convert text to speech using ElevenLabs API"""
|
55 |
try:
|
|
|
|
|
|
|
|
|
|
|
56 |
voice = voice_id or self.default_voice_id
|
57 |
url = f"{self.base_url}/text-to-speech/{voice}"
|
58 |
|
@@ -114,6 +130,9 @@ class ElevenLabsTTS(TTSInterface):
|
|
114 |
"yoZ06aMxZJJ28mfd3POQ": "Sam (Male)",
|
115 |
}
|
116 |
|
|
|
|
|
|
|
117 |
|
118 |
class BlazeTTS(TTSInterface):
|
119 |
"""Placeholder for future Blaze TTS implementation"""
|
|
|
46 |
self.base_url = "https://api.elevenlabs.io/v1"
|
47 |
self.default_voice_id = "2thYbn2sOGtiTwd9QwWH" # Avencia
|
48 |
|
49 |
+
# ElevenLabs için preprocessing gereken alanlar
|
50 |
+
self.preprocessing_flags = {
|
51 |
+
TTSPreprocessor.PREPROCESS_NUMBERS, # Büyük sayılar
|
52 |
+
TTSPreprocessor.PREPROCESS_CURRENCY, # Para birimleri
|
53 |
+
TTSPreprocessor.PREPROCESS_TIME, # Saat formatı
|
54 |
+
TTSPreprocessor.PREPROCESS_CODES, # PNR kodları
|
55 |
+
TTSPreprocessor.PREPROCESS_PERCENTAGE # Yüzdeler
|
56 |
+
}
|
57 |
+
|
58 |
+
self.preprocessor = TTSPreprocessor(language="tr")
|
59 |
+
|
60 |
+
# Debug log
|
61 |
masked_key = f"{api_key[:4]}...{api_key[-4:]}" if len(api_key) > 8 else "***"
|
62 |
log(f"🔑 ElevenLabsTTS initialized with key: {masked_key}")
|
63 |
|
64 |
async def synthesize(self, text: str, voice_id: Optional[str] = None, **kwargs) -> bytes:
|
65 |
"""Convert text to speech using ElevenLabs API"""
|
66 |
try:
|
67 |
+
# Apply preprocessing if not disabled
|
68 |
+
if kwargs.get("disable_preprocessing", False) != True:
|
69 |
+
text = self.preprocessor.preprocess(text, self.preprocessing_flags)
|
70 |
+
log(f"📝 Preprocessed text: {text[:100]}...")
|
71 |
+
|
72 |
voice = voice_id or self.default_voice_id
|
73 |
url = f"{self.base_url}/text-to-speech/{voice}"
|
74 |
|
|
|
130 |
"yoZ06aMxZJJ28mfd3POQ": "Sam (Male)",
|
131 |
}
|
132 |
|
133 |
+
def get_preprocessing_flags(self) -> Set[str]:
|
134 |
+
"""Get preprocessing flags for ElevenLabs"""
|
135 |
+
return self.preprocessing_flags
|
136 |
|
137 |
class BlazeTTS(TTSInterface):
|
138 |
"""Placeholder for future Blaze TTS implementation"""
|