pingo-ptbr / inference.py
itxtoledo's picture
Add pingo-ptbr: 0.87 MB pt-BR TTS (MLX + ONNX + web demo)
27d8618 verified
Raw History Blame Contribute Delete
1.63 kB
"""Command-line entry point, same shape as PiVo's:
python inference.py synthesize --voice F_s4 --text "Olá! Esta é a voz da SemFence." --output hello.wav
python inference.py synthesize --model weights/pingo-ptbr-w96.bin --voice M_sm4 --text-file text.txt --speed 1.1 --output out.wav
"""
import argparse, sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE / "pingo"))
import soundfile as sf
import speak
def main():
ap = argparse.ArgumentParser(description="pingo-ptbr: Brazilian Portuguese text-to-speech in under 1 MB")
sub = ap.add_subparsers(dest="command", required=True)
s = sub.add_parser("synthesize", help="text -> wav (16 kHz, mono)")
s.add_argument("--model", default=str(HERE / "weights" / "pingo-ptbr.bin"))
s.add_argument("--voice", choices=list(speak.VOICES), default="F_s4")
s.add_argument("--text"); s.add_argument("--text-file")
s.add_argument("--speed", type=float, default=1.0, help="0.5 to 2.0; larger is faster")
s.add_argument("--no-respelling", action="store_true", help="do not rewrite English words (see pingo/pronunciation.py)")
s.add_argument("--output", "-o", default="out.wav")
a = ap.parse_args()
if bool(a.text) == bool(a.text_file):
ap.error("pass exactly one of --text or --text-file")
text = Path(a.text_file).read_text() if a.text_file else a.text
audio = speak.speak(speak.Pingo(a.model), text, a.voice, a.speed, not a.no_respelling)
sf.write(a.output, audio, speak.RATE)
print(f"{a.output}: {len(audio) / speak.RATE:.2f} s")
if __name__ == "__main__":
main()