Download tools/make_prompt.py from RightNowAI/duplex-v0: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/RightNowAI/duplex-v0/resolve/main/tools/make_prompt.py
- Command line
-
hf download hf://RightNowAI/duplex-v0/tools/make_prompt.py
-
curl -L -o make_prompt.py https://huggingface.co/RightNowAI/duplex-v0/resolve/main/tools/make_prompt.py
1.34 kB
| """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() | |