File size: 617 Bytes
bea8b31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from smolagents import Tool


class KokoroText2Speech(Tool):
    name = "KokoroText2Speech"
    description = "This is a tool that returns audio data from text."
    inputs = {
        "input_text": {
            "type": "string",
            "description": "Text that you want to convert",
        }
    }
    output_type = "array"

    def forward(self, input_text: str) -> str:
        from kokoro import KPipeline
        generator = KPipeline(lang_code='a')(
            input_text, voice='af_heart', 
            speed=1, split_pattern=r'\n+'
        )
        _, _, audio = next(generator)
        return audio