File size: 1,344 Bytes
f730521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Make the voice prompt for the released token2wav decoder from a synthetic voice
(a Kokoro voice pack), so the reply voice is not conditioned on a recording of a person.

  python -m tools.make_prompt --voice af_heart --out runs/prompt_af_heart.wav
"""
import argparse

import torch

from duplex.spec import write_wav

TEXT = ("Hello, and thanks for calling. I can help you with bookings, questions about your account, "
        "and most everyday requests. Tell me what you need, and we will sort it out together.")


SHORT_TEXT = "Hello, and thanks for calling. How can I help you today?"


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--voice", default="af_heart")
    ap.add_argument("--short", action="store_true", help="one sentence (about 3.5 s): every decode call attends to the whole prompt")
    ap.add_argument("--out", required=True)
    args = ap.parse_args()
    from kokoro import KPipeline
    pipe = KPipeline(lang_code=args.voice[0], repo_id="hexgrad/Kokoro-82M", device="cpu")
    audio = torch.cat([torch.as_tensor(a).float().flatten() for _, _, a in pipe(SHORT_TEXT if args.short else TEXT, voice=args.voice, speed=1.0) if a is not None])
    write_wav(args.out, audio.numpy(), 24000)
    print(f"{args.out}: {len(audio) / 24000:.1f} s, voice {args.voice}")


if __name__ == "__main__":
    main()