@@ -0,0 +1,1909 @@
+#!/usr/bin/env python%0A%0Aimport sys%0Aimport os%0Aimport time%0Aimport getopt%0Aimport atexit%0Aimport alsaaudio%0Afrom daemon import Daemon%0A%0Adef get_fname():%0A    prefix = %22/root/audio/output/recording_%22%0A    return prefix + time.strftime(%22%25d-%25m-%25y_%25H-%25M%22, time.gmtime()) + '.wav'%0A%0Adef shutdown(daemon, pipename):%0A    daemon.cleanup()%0A    os.remove(pipename)%0A    print(%22Shutting down%22)%0A    %0Aclass Recording(Daemon):%0A    def cleanup(self):%0A        # convert to mp3 and die%0A        pass%0A%0A    def run(self):%0A        card = 'default'%0A        f = open(get_fname(), 'wb')%0A%0A        inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card)%0A%0A        # Set attributes: Mono, 44100 Hz, 16 bit little endian samples%0A        inp.setchannels(1)%0A        inp.setrate(44100)%0A        inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)%0A%0A        inp.setperiodsize(160)%0A        while True:%0A           # Read data from device%0A            l, data = inp.read()%0A          %0A            if l:%0A                f.write(data)%0A                time.sleep(.001)%0A        f.close()%0A%0Aif __name__ == %22__main__%22:%0A    named_pipe = '/tmp/osp.fifo'%0A    command = ''%0A    daemon = Recording('/tmp/recording_daemon.pid')%0A%0A    try:%0A        os.mkfifo(named_pipe)%0A    except OSError:%0A        print(%22Error creating pipe, guess it exists%22)%0A        #sys.exit(1)%0A%0A    while command != 'shutdown':%0A        pipe = open(named_pipe, 'r')%0A        command = pipe.read()%5B:-1%5D%0A        print(%22command received: %25s%22 %25 command)%0A        if command == 'start':%0A            print(%22starting recording%22)%0A            a = os.fork()%0A            if a == 0:%0A                daemon.start()%0A        if command == 'stop':%0A            print(%22stopping recording%22)%0A            daemon.stop()%0A        if command == 'shutdown':%0A            print(%22stopping recording%22)%0A            os.kill(a, 0)%0A            daemon.stop()%0A            pipe.close()%0A%0A    atexit.register(shutdown, daemon, named_pipe)%0A%0A

Create audio_daemon.py