def generator(w, s, num_iterations, output_file): try: for i in range(num_iterations): w = wave.open(input_file, 'rb') start_time = time.time() yield jasr.StreamingRecognizeRequest(streaming_config=s) num_requests = 0 while 1: d = w.readframes(CHUNK) if len(d) <= 0: break num_requests += 1 if simulate_realtime: time_to_sleep = max( 0.0, CHUNK / rate * num_requests - (time.time() - start_time)) time.sleep(time_to_sleep) yield jasr.StreamingRecognizeRequest(audio_content=d) w.close() except Exception as e: print(e)
def main(): args = get_args() if args.list_devices: p = pyaudio.PyAudio() for i in range(p.get_device_count()): info = p.get_device_info_by_index(i) if info['maxInputChannels'] < 1: continue print(f"{info['index']}: {info['name']}") sys.exit(0) channel = grpc.insecure_channel(args.server) client = jasr_srv.JarvisASRStub(channel) config = jasr.RecognitionConfig( encoding=ja.AudioEncoding.LINEAR_PCM, sample_rate_hertz=RATE, language_code="en-US", max_alternatives=1, enable_automatic_punctuation=True, ) streaming_config = jasr.StreamingRecognitionConfig(config=config, interim_results=True) with MicrophoneStream(RATE, CHUNK, device=args.input_device) as stream: audio_generator = stream.generator() requests = (jasr.StreamingRecognizeRequest(audio_content=content) for content in audio_generator) def build_generator(cfg, gen): yield jasr.StreamingRecognizeRequest(streaming_config=cfg) for x in gen: yield x responses = client.StreamingRecognize( build_generator(streaming_config, requests)) listen_print_loop(responses)
def build_generator(cfg, gen): yield jasr.StreamingRecognizeRequest(streaming_config=cfg) for x in gen: yield x
def generator(w, s): yield jasr.StreamingRecognizeRequest(streaming_config=s) d = w.readframes(CHUNK) while len(d) > 0: yield jasr.StreamingRecognizeRequest(audio_content=d) d = w.readframes(CHUNK)