https://hf.co/hexgrad/Kokoro-82M
Python
Allow pipeline to take a voice style tensor directly. (#93)
RobViren330d110c0585
diff --git a/README.md b/README.mdindex 2734d53..d19f1c6 100644--- a/README.md+++ b/README.md@@ -21,6 +21,7 @@ You can run this cell on [Google Colab](https://colab.research.google.com/). [Lifrom kokoro import KPipelinefrom IPython.display import display, Audioimport soundfile as sf+import torch# πΊπΈ 'a' => American English, π¬π§ 'b' => British English# π―π΅ 'j' => Japanese: pip install misaki[ja]# π¨π³ 'z' => Mandarin Chinese: pip install misaki[zh]@@ -49,6 +50,14 @@ generator = pipeline(text, voice='af_heart', # <= change voice herespeed=1, split_pattern=r'\n+')++# Alternatively, load voice tensor directly:+voice_tensor = torch.load('path/to/voice.pt', weights_only=True)+generator = pipeline(+ text, voice=voice_tensor,+ speed=1, split_pattern=r'\n+'+)+for i, (gs, ps, audio) in enumerate(generator):print(i) # i => indexprint(gs) # gs => graphemes/textdiff --git a/kokoro/pipeline.py b/kokoro/pipeline.pyindex bc099fd..66f4c01 100644--- a/kokoro/pipeline.py+++ b/kokoro/pipeline.py@@ -146,7 +146,9 @@ class KPipeline:If multiple voices are requested, they are averaged.Delimiter is optional and defaults to ','."""- def load_voice(self, voice: str, delimiter: str = ",") -> torch.FloatTensor:+ def load_voice(self, voice: Union[str, torch.FloatTensor], delimiter: str = ",") -> torch.FloatTensor:+ if isinstance(voice, torch.FloatTensor):+ return voiceif voice in self.voices:return self.voices[voice]logger.debug(f"Loading voice: {voice}")