blackhole1218 commited on
Commit
733799a
·
1 Parent(s): 10333ff

Add Supertone TTS support

Browse files
Files changed (2) hide show
  1. models.py +10 -0
  2. tts.py +44 -0
models.py CHANGED
@@ -573,6 +573,7 @@ def insert_initial_models():
573
  has_openai = bool(os.getenv("OPENAI_API_KEY"))
574
  has_elevenlabs = bool(os.getenv("ELEVENLABS_API_KEY"))
575
  has_google = bool(os.getenv("GOOGLE_API_KEY"))
 
576
 
577
  tts_models = [
578
  # 채널톡 TTS (한국어 특화) - 항상 활성화
@@ -627,6 +628,15 @@ def insert_initial_models():
627
  is_active=has_google,
628
  model_url="https://cloud.google.com/text-to-speech",
629
  ),
 
 
 
 
 
 
 
 
 
630
  ]
631
 
632
  for model in tts_models:
 
573
  has_openai = bool(os.getenv("OPENAI_API_KEY"))
574
  has_elevenlabs = bool(os.getenv("ELEVENLABS_API_KEY"))
575
  has_google = bool(os.getenv("GOOGLE_API_KEY"))
576
+ has_supertone = bool(os.getenv("SUPERTONE_API_KEY"))
577
 
578
  tts_models = [
579
  # 채널톡 TTS (한국어 특화) - 항상 활성화
 
628
  is_active=has_google,
629
  model_url="https://cloud.google.com/text-to-speech",
630
  ),
631
+ # Supertone TTS (한국어 특화) - API 키 있을 때만 활성화
632
+ Model(
633
+ id="supertone-sona",
634
+ name="Supertone Sona",
635
+ model_type=ModelType.TTS,
636
+ is_open=False,
637
+ is_active=has_supertone,
638
+ model_url="https://supertone.ai/",
639
+ ),
640
  ]
641
 
642
  for model in tts_models:
tts.py CHANGED
@@ -22,6 +22,9 @@ CHANNEL_TTS_URL = os.getenv(
22
  ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
23
  ELEVENLABS_VOICE_ID = os.getenv("ELEVENLABS_VOICE_ID", "21m00Tcm4TlvDq8ikWAM") # Rachel (기본)
24
 
 
 
 
25
  model_mapping = {
26
  # 채널톡 TTS (한국어 특화)
27
  "channel-hana": {
@@ -53,6 +56,11 @@ model_mapping = {
53
  "provider": "google",
54
  "voice": "ko-KR-Neural2-A",
55
  },
 
 
 
 
 
56
  }
57
 
58
 
@@ -133,6 +141,39 @@ def predict_openai_tts(text: str, model: str = "tts-1", voice: str = "alloy") ->
133
  return f.name
134
 
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  def predict_google_tts(text: str, voice: str = "ko-KR-Wavenet-A") -> str:
137
  """Google Cloud TTS API 호출"""
138
  api_key = os.getenv("GOOGLE_API_KEY")
@@ -202,6 +243,9 @@ def predict_tts(text: str, model: str) -> str:
202
  elif provider == "elevenlabs":
203
  return predict_elevenlabs_tts(text, config.get("model", "eleven_multilingual_v2"))
204
 
 
 
 
205
  else:
206
  raise ValueError(f"알 수 없는 provider: {provider}")
207
 
 
22
  ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
23
  ELEVENLABS_VOICE_ID = os.getenv("ELEVENLABS_VOICE_ID", "21m00Tcm4TlvDq8ikWAM") # Rachel (기본)
24
 
25
+ SUPERTONE_API_KEY = os.getenv("SUPERTONE_API_KEY")
26
+ SUPERTONE_VOICE_ID = os.getenv("SUPERTONE_VOICE_ID", "91992bbd4758bdcf9c9b01") # 기본 보이스
27
+
28
  model_mapping = {
29
  # 채널톡 TTS (한국어 특화)
30
  "channel-hana": {
 
56
  "provider": "google",
57
  "voice": "ko-KR-Neural2-A",
58
  },
59
+ # Supertone TTS (한국어 특화)
60
+ "supertone-sona": {
61
+ "provider": "supertone",
62
+ "model": "sona_speech_1",
63
+ },
64
  }
65
 
66
 
 
141
  return f.name
142
 
143
 
144
+ def predict_supertone_tts(text: str, model: str = "sona_speech_1") -> str:
145
+ """Supertone TTS API 호출"""
146
+ api_key = SUPERTONE_API_KEY
147
+ if not api_key:
148
+ raise ValueError("SUPERTONE_API_KEY 환경 변수가 설정되지 않았습니다.")
149
+
150
+ voice_id = SUPERTONE_VOICE_ID
151
+
152
+ response = requests.post(
153
+ f"https://api.supertone.ai/v1/text-to-speech/{voice_id}?output_format=wav",
154
+ headers={
155
+ "x-sup-api-key": api_key,
156
+ "Content-Type": "application/json",
157
+ },
158
+ json={
159
+ "text": text,
160
+ "language": "ko",
161
+ "model": model,
162
+ "voice_settings": {
163
+ "pitch_shift": 0,
164
+ "pitch_variance": 1,
165
+ "speed": 1,
166
+ },
167
+ },
168
+ timeout=60,
169
+ )
170
+ response.raise_for_status()
171
+
172
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
173
+ f.write(response.content)
174
+ return f.name
175
+
176
+
177
  def predict_google_tts(text: str, voice: str = "ko-KR-Wavenet-A") -> str:
178
  """Google Cloud TTS API 호출"""
179
  api_key = os.getenv("GOOGLE_API_KEY")
 
243
  elif provider == "elevenlabs":
244
  return predict_elevenlabs_tts(text, config.get("model", "eleven_multilingual_v2"))
245
 
246
+ elif provider == "supertone":
247
+ return predict_supertone_tts(text, config.get("model", "sona_speech_1"))
248
+
249
  else:
250
  raise ValueError(f"알 수 없는 provider: {provider}")
251