Spaces:
Paused
Paused
rick
commited on
... not done...
Browse files- core/text_to_speech.py +8 -6
core/text_to_speech.py
CHANGED
|
@@ -39,7 +39,7 @@ class openai_tts(object):
|
|
| 39 |
|
| 40 |
def set_tts_speed(self, speed):
|
| 41 |
if not (0.25 <= speed <= 4.0):
|
| 42 |
-
raise ValueError(f"
|
| 43 |
else:
|
| 44 |
self.speed = speed
|
| 45 |
return self
|
|
@@ -47,14 +47,14 @@ class openai_tts(object):
|
|
| 47 |
def set_tts_voice(self, voice):
|
| 48 |
voix_valides = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
|
| 49 |
if voice not in voix_valides:
|
| 50 |
-
raise ValueError(f"Invalid TTS voice: {voice}. Valid voices are: {', '.join(voix_valides)}.")
|
| 51 |
else:
|
| 52 |
self.tts_voice = voice
|
| 53 |
return self
|
| 54 |
|
| 55 |
def set_tts_model(self, model):
|
| 56 |
if model not in ["tts-1", "tts-1-hd"]:
|
| 57 |
-
raise ValueError(f"Invalid TTS model: {model}. Valid models are 'tts-1' and 'tts-1-hd'.")
|
| 58 |
else:
|
| 59 |
self.tts_model = model
|
| 60 |
return self
|
|
@@ -65,7 +65,7 @@ class openai_tts(object):
|
|
| 65 |
|
| 66 |
def set_response_format(self, format: str):
|
| 67 |
if format not in self.supported_formats:
|
| 68 |
-
raise ValueError(f"Unsupported format: {format}. Supported formats are: {', '.join(self.supported_formats)}")
|
| 69 |
else:
|
| 70 |
self.response_format = format
|
| 71 |
return self
|
|
@@ -85,11 +85,13 @@ class openai_tts(object):
|
|
| 85 |
input_text (str): Le texte à convertir en parole.
|
| 86 |
|
| 87 |
Returns:
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
"""
|
| 90 |
response = self.client.audio.speech.create(
|
| 91 |
model=self.tts_model,
|
| 92 |
-
voice=self.tts_voice
|
| 93 |
input=input_text,
|
| 94 |
response_format=self.response_format,
|
| 95 |
speed=self.speed
|
|
|
|
| 39 |
|
| 40 |
def set_tts_speed(self, speed):
|
| 41 |
if not (0.25 <= speed <= 4.0):
|
| 42 |
+
raise ValueError(f"[TTS] - Speed must be between 0.25 and 4.0. Provided value: {speed}")
|
| 43 |
else:
|
| 44 |
self.speed = speed
|
| 45 |
return self
|
|
|
|
| 47 |
def set_tts_voice(self, voice):
|
| 48 |
voix_valides = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
|
| 49 |
if voice not in voix_valides:
|
| 50 |
+
raise ValueError(f"[TTS] - Invalid TTS voice: {voice}. Valid voices are: {', '.join(voix_valides)}.")
|
| 51 |
else:
|
| 52 |
self.tts_voice = voice
|
| 53 |
return self
|
| 54 |
|
| 55 |
def set_tts_model(self, model):
|
| 56 |
if model not in ["tts-1", "tts-1-hd"]:
|
| 57 |
+
raise ValueError(f"[TTS] - Invalid TTS model: {model}. Valid models are 'tts-1' and 'tts-1-hd'.")
|
| 58 |
else:
|
| 59 |
self.tts_model = model
|
| 60 |
return self
|
|
|
|
| 65 |
|
| 66 |
def set_response_format(self, format: str):
|
| 67 |
if format not in self.supported_formats:
|
| 68 |
+
raise ValueError(f"[TTS] - Unsupported format: {format}. Supported formats are: {', '.join(self.supported_formats)}")
|
| 69 |
else:
|
| 70 |
self.response_format = format
|
| 71 |
return self
|
|
|
|
| 85 |
input_text (str): Le texte à convertir en parole.
|
| 86 |
|
| 87 |
Returns:
|
| 88 |
+
Dict[str, Union[float, str]]: Un dictionnaire contenant:
|
| 89 |
+
- 'audio_duration' (float): La durée de l'audio en secondes.
|
| 90 |
+
- 'data_bytes' (str): Les données audio encodées en base64.
|
| 91 |
"""
|
| 92 |
response = self.client.audio.speech.create(
|
| 93 |
model=self.tts_model,
|
| 94 |
+
voice=self.tts_voice,
|
| 95 |
input=input_text,
|
| 96 |
response_format=self.response_format,
|
| 97 |
speed=self.speed
|