| """Live-style local example. Input: your own mono 16 kHz English WAV.""" | |
| import argparse | |
| import json | |
| import soundfile as sf | |
| from streampa import StreamPAPipeline | |
| p=argparse.ArgumentParser() | |
| p.add_argument('--bundle-dir',required=True); p.add_argument('--audio',required=True) | |
| p.add_argument('--device',default='cpu') | |
| a=p.parse_args() | |
| pipeline=StreamPAPipeline(a.bundle_dir,device=a.device) | |
| session=pipeline.create_session() | |
| with sf.SoundFile(a.audio) as audio: | |
| if audio.samplerate!=16000 or audio.channels!=1: raise ValueError('Expected mono 16-kHz WAV') | |
| while True: | |
| block=audio.read(1600,dtype='float32') | |
| if not len(block): break | |
| for result in session.append(block): print(json.dumps(result)) | |
| print(json.dumps(session.finish())) | |
| session.reset() | |
| assert session.current() is None and session.state is None | |