Tomtom84 commited on
Commit
dd69770
·
verified ·
1 Parent(s): 6a70709

Update engines/orpheus_engine.py

Browse files
Files changed (1) hide show
  1. engines/orpheus_engine.py +39 -43
engines/orpheus_engine.py CHANGED
@@ -22,24 +22,11 @@ START_TOKEN_ID = 128259
22
  END_TOKEN_IDS = [128009, 128260, 128261, 128257]
23
  CUSTOM_TOKEN_PREFIX = "<custom_token_"
24
 
25
-
26
  class OrpheusVoice:
27
- """
28
- Represents the configuration for an Orpheus voice.
29
-
30
- Attributes:
31
- name (str): The name of the voice. Must be one of the AVAILABLE_VOICES.
32
-
33
- Raises:
34
- ValueError: If the voice name provided is not in AVAILABLE_VOICES.
35
- """
36
- def __init__(self, name: str):
37
- # if name not in AVAILABLE_VOICES:
38
- # raise ValueError(f"Invalid voice '{name}'. Available voices: {AVAILABLE_VOICES}")
39
- self.name = name
40
 
41
- def __repr__(self):
42
- return f"OrpheusVoice(name='{self.name}')"
43
 
44
 
45
  class OrpheusEngine(BaseEngine):
@@ -319,34 +306,43 @@ class OrpheusEngine(BaseEngine):
319
  logging.info("Returning None after failed conversion.")
320
  return None
321
 
322
- def get_voices(self):
323
- """
324
- Retrieve the list of available voices.
325
 
326
- Returns:
327
- list: A list of OrpheusVoice instances for each available voice.
328
- """
329
- return [OrpheusVoice(name) for name in AVAILABLE_VOICES]
330
-
331
- def set_voice(self, voice: Union[str, OrpheusVoice]):
332
- """
333
- Set the current voice for synthesis.
334
-
335
- Args:
336
- voice (Union[str, OrpheusVoice]): The voice name or an OrpheusVoice instance.
337
-
338
- Raises:
339
- ValueError: If the provided voice name is invalid.
340
- TypeError: If the voice argument is neither a string nor an OrpheusVoice instance.
341
- """
342
- if isinstance(voice, str):
343
- # if voice not in AVAILABLE_VOICES:
344
- # raise ValueError(f"Invalid voice '{voice}'")
345
- self.voice = OrpheusVoice(voice)
346
- elif isinstance(voice, OrpheusVoice):
347
- self.voice = voice
348
- else:
349
- raise TypeError("Voice must be a string or an OrpheusVoice instance.")
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  def set_voice_parameters(self, **kwargs):
352
  """
 
22
  END_TOKEN_IDS = [128009, 128260, 128261, 128257]
23
  CUSTOM_TOKEN_PREFIX = "<custom_token_"
24
 
 
25
  class OrpheusVoice:
26
+ def __init__(self, name: str, gender: str | None = None):
27
+ self.name = name
28
+ self.gender = gender # optional, falls du es anzeigen willst
 
 
 
 
 
 
 
 
 
 
29
 
 
 
30
 
31
 
32
  class OrpheusEngine(BaseEngine):
 
306
  logging.info("Returning None after failed conversion.")
307
  return None
308
 
 
 
 
309
 
310
+ _SPEAKERS = [
311
+ # männlich
312
+ OrpheusVoice("Jakob", "m"),
313
+ OrpheusVoice("Anton", "m"),
314
+ OrpheusVoice("Julian", "m"),
315
+ OrpheusVoice("Jan", "m"),
316
+ OrpheusVoice("Alexander", "m"),
317
+ OrpheusVoice("Emil", "m"),
318
+ OrpheusVoice("Ben", "m"),
319
+ OrpheusVoice("Elias", "m"),
320
+ OrpheusVoice("Felix", "m"),
321
+ OrpheusVoice("Jonas", "m"),
322
+ OrpheusVoice("Noah", "m"),
323
+ OrpheusVoice("Maximilian", "m"),
324
+ # weiblich
325
+ OrpheusVoice("Sophie", "f"),
326
+ OrpheusVoice("Marie", "f"),
327
+ OrpheusVoice("Mia", "f"),
328
+ OrpheusVoice("Maria", "f"),
329
+ OrpheusVoice("Sophia", "f"),
330
+ OrpheusVoice("Lina", "f"),
331
+ OrpheusVoice("Lea", "f"),
332
+ ]
333
+
334
+ # -----------------------------------------------------------
335
+ # Public API, damit das FastAPI-Backend sie abfragen kann
336
+ # -----------------------------------------------------------
337
+ def get_voices(self) -> list[OrpheusVoice]:
338
+ """Return a list of available voices for the Kartoffel checkpoint."""
339
+ return self._SPEAKERS
340
+
341
+ # In set_voice() akzeptieren wir einfach den Namen:
342
+ def set_voice(self, voice_name: str) -> None:
343
+ if voice_name not in [v.name for v in self._SPEAKERS]:
344
+ raise ValueError(f"Unknown Orpheus speaker '{voice_name}'")
345
+ self.current_voice = voice_name
346
 
347
  def set_voice_parameters(self, **kwargs):
348
  """