p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=SAMPLE_RATE, input=True, input_device_index=DEVICE_INDEX, frames_per_buffer=CHUNK) try: print("start ...") while True: # 250ms秒分のデータ読み込み data = stream.read(CHUNK) # numpy配列に変換 data = np.frombuffer(data, dtype="int16") # チャンネル 2ch -> 1ch data = data[0::2] # サンプルレート 32000Hz -> 8000Hz data = data[0::4] # byteに戻す data = data.tobytes() # Amazon Kinesis Data Streamsへの送信 producer.send(data) except: stream.stop_stream() stream.close() p.terminate()
parser.add_argument("--short-names", action="store_true", dest="short_names", default=False, required=False, help="Produce metric report with short names") args = parser.parse_args() collector = Collector(short_metrics_names=args.short_names) if args.sample_rate: count = int(args.number_samples) while True: count -= 1 # setup a loop to collect metric = collector.collect_metrics() producer = Producer() metric = metric.to_json_string() print (metric) producer.send(metric) if count == 0: break sleep(float(args.sample_rate)) else: metric = collector.collect_metrics() if args.max_list_size: metric.max_list_size = int(args.max_list_size) producer = Producer() metric = metric.to_json_string() print (metric)