File size: 1,238 Bytes
f68f12f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from pathlib import Path
import argparse,json
import soundfile as sf
from gooya_tts import GooyaTTS
def main():
parser=argparse.ArgumentParser(description='Standalone Persian text-to-speech; all weights loaded from this package.')
source=parser.add_mutually_exclusive_group(required=True);source.add_argument('--text');source.add_argument('--text-file',type=Path)
parser.add_argument('--model-dir',type=Path,default=Path(__file__).resolve().parent);parser.add_argument('--output',type=Path,default=Path('output.wav'));parser.add_argument('--device',default='cpu');parser.add_argument('--threads',type=int,default=4)
args=parser.parse_args();text=args.text if args.text is not None else args.text_file.read_text(encoding='utf-8')
model=GooyaTTS(args.model_dir,device=args.device,num_threads=args.threads);wave,details=model.synthesize(text,return_details=True)
args.output.parent.mkdir(parents=True,exist_ok=True);sf.write(args.output,wave,model.sample_rate,subtype='FLOAT');args.output.with_suffix('.json').write_text(json.dumps(details,ensure_ascii=False,indent=2),encoding='utf-8');print(f'Wrote {args.output} ({details["duration_seconds"]:.2f} seconds, {model.sample_rate} Hz)')
if __name__=='__main__':main()
|