From 9774f103de7ee37f911c0031d14542e40a81a0e4 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 3 Jun 2013 13:07:59 +0200 Subject: [PATCH] init --- .gitignore | 3 +++ README | 1 + detector.py | 43 +++++++++++++++++++++++++++++++++++++++++++ run.sh | 2 ++ 4 files changed, 49 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100755 detector.py create mode 100755 run.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5885b32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.avi +*.mp4 +*.flv diff --git a/README b/README new file mode 100644 index 0000000..cac9fac --- /dev/null +++ b/README @@ -0,0 +1 @@ +Lab sentient companion diff --git a/detector.py b/detector.py new file mode 100755 index 0000000..b3ba384 --- /dev/null +++ b/detector.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +import pyaudio +import array +import time +import sys + +CHUNK = 1024 + +p = pyaudio.PyAudio() + +stream = p.open(format = pyaudio.paInt16, + channels = 1, + rate = 48000, + input = True, + frames_per_buffer = CHUNK, + input_device_index = 0) + +last = time.time() + +print 'pause' +sys.stdout.flush() + +while True: + try: + data = stream.read(CHUNK) + except: + stream.stop_stream() + stream.start_stream() + continue + data = array.array("h", data) + if last < time.time() - 1: + if max(data) < -32000: + last = time.time() + print 'pause' + sys.stdout.flush() + if min(data) > 32000: + last = time.time() + print 'pause' + sys.stdout.flush() + +stream.stop_stream() +stream.close() +p.terminate() diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..b894277 --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +./detector.py | mplayer -fs -vo directfb -slave $1 -loop 0