benderrodriguez commited on
Commit
77965f0
·
verified ·
1 Parent(s): 96c182f

Upload tts_providers/soniox.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. tts_providers/soniox.py +51 -0
tts_providers/soniox.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Soniox TTS provider."""
2
+
3
+ import os
4
+ import requests
5
+ from . import TTSProvider
6
+
7
+
8
+ class SonioxProvider(TTSProvider):
9
+
10
+ MODELS = {
11
+ "soniox": {
12
+ "name": "Soniox",
13
+ "is_open": False,
14
+ "model_url": "https://soniox.com/",
15
+ },
16
+ }
17
+
18
+ _DEFAULT_VOICE = "Maya"
19
+
20
+ @property
21
+ def file_extension(self) -> str:
22
+ return "wav"
23
+
24
+ def synthesize(self, text: str, model_id: str) -> bytes:
25
+ api_key = os.getenv("SONIOX_API_KEY")
26
+ if not api_key:
27
+ raise RuntimeError("SONIOX_API_KEY not set")
28
+
29
+ voice = os.getenv("SONIOX_VOICE", self._DEFAULT_VOICE)
30
+
31
+ response = requests.post(
32
+ "https://tts-rt.soniox.com/tts",
33
+ headers={
34
+ "Authorization": f"Bearer {api_key}",
35
+ "Content-Type": "application/json",
36
+ },
37
+ json={
38
+ "model": "tts-rt-v1-preview",
39
+ "language": "he",
40
+ "voice": voice,
41
+ "audio_format": "wav",
42
+ "text": text,
43
+ "sample_rate": 24000,
44
+ },
45
+ timeout=60,
46
+ )
47
+ if not response.ok:
48
+ raise RuntimeError(
49
+ f"Soniox API error {response.status_code}: {response.text[:500]}"
50
+ )
51
+ return response.content