Audio support for PyRadmon

More
10 years 2 weeks ago - 9 years 11 months ago #151 by ThibmoRozier
This topic will handle the addition of audio within PyRadmon.

Project moved to SourceForge!
SourceForge project page: PyRadmon Reborn

I will be using either PyAudio for this script.

Installation:
1> Use your package manager to install PortAudio. ( http://www.portaudio.com/ )
2> Install PyAudio ( http://people.csail.mit.edu/hubert/pyaudio )
3> Run PyRadmon.py once (python ./pyradmon.py)
4> Configure all the settings in config.txt
5> Run PyRadmon.py again and monitor. :) (python ./pyradmon.py)

Download:
Single counter:

File Attachment:

File Name: AudioPyRadmon.zip
File Size:6 KB

Two counters:

File Attachment:

File Name: AudioMulti...dmon.zip
File Size:7 KB


Other:
Fully functional now, a great shout-out to Dan for initial help and hints.
Thanks to PyAudio, Python and Russell Borogove @ Stack Overflow for the library's and good passive help.
Attachments:
Last edit: 9 years 11 months ago by ThibmoRozier.
The following user(s) said Thank You: mw0uzo

Please Log in or Create an account to join the conversation.

More
10 years 2 weeks ago #152 by mw0uzo
Replied by mw0uzo on topic Audio support for PyRadmon
I can help.
When I run the script for the first time I get
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\Daniel>cd Desktop

C:\Users\Daniel\Desktop>MultiPyRadmon.py
  File "C:\Users\Daniel\Desktop\MultiPyRadmon.py", line 826
    for n in range(0, n < bytesrecorded; n = n + 2):
                                       ^
SyntaxError: invalid syntax

C:\Users\Daniel\Desktop>

Please Log in or Create an account to join the conversation.

More
10 years 2 weeks ago #153 by mw0uzo
Replied by mw0uzo on topic Audio support for PyRadmon
'deadticker' needs to be initialised to 1 or pulse detection won't work properly

Please Log in or Create an account to join the conversation.

More
10 years 2 weeks ago #154 by ThibmoRozier
My bad. ^_^

Please Log in or Create an account to join the conversation.

More
10 years 2 weeks ago #155 by ThibmoRozier
-Deep zen sigh- Soo, basically I am stuck on this:
Problem with audio port => geiger 1:

	'float' object is not iterable 

Exiting

I fixed all other tinyminy issues. ^_^
Forgot to format some C# parts to python before.
Updated file is up now, helpies? Q.Q

Please Log in or Create an account to join the conversation.

More
10 years 2 weeks ago #156 by ThibmoRozier
So, basically I need a helping hand on this total confusion of a logic....
(No idea who made it up but it got me and a math freak brain-fart. :P )
Problem section:
...
self.amplitudebuffer=None
        self.envelope = float(0)
        self.detectwidthcounter = 0
        self.lastrisingedge = float(0)
        self.lastfallingedge = float(0)
        self.lastdeadtimeedge = float(0)
        self.lastminwidthedge = float(0)
        self.last = False
        self.onecaptured = False
        self.deadticker = 1
        cpm=25
        stream = self.p.open(format=self.FORMAT, channels=self.CHANNELS, rate=self.RATE, input=True, frames_per_buffer=self.CHUNK)
        frames = []
        for i in range(0, int(self.RATE / self.CHUNK * self.RECORD_SECONDS)):
            dataAudio = stream.read(self.CHUNK)
            frames.append(dataAudio)
        try:
            bytesrecorded = self.CHUNK * self.RECORD_SECONDS
            
            sampletime = float(float(1.0) / float(self.RATE))
            detectlevel = float(0.025)
            
            minwidth = int(math.fsum((float(5) / float(1000)) / sampletime))
            deadtime = int(math.fsum((float(5) / float(1000)) / sampletime))
            
            radcount = 0
            
            self.lastrisingedge = -1
            self.lastfallingedge = -1
            self.lastdeadtimeedge = -1
            self.lastminwidthedge = -1

            arrayptr = 0

            value = 0.0
            attack = 0.001
            release = 0.004
            ga = math.exp(-1 / (self.RATE * attack))
            gr = math.exp(-1 / (self.RATE * release))

            self.onecaptured = False

            svalue=0
            for n in range(0, bytesrecorded):
                # get your data into 'input'
                svalue = (frames[n + 1] < 8) or frames[n] # Used to be svalue = (short)((e.Buffer[n + 1] << 8) | e.Buffer[n]);

                if svalue == (-32768):
                    svalue = (-32767)

                if svalue > 0:
                    value = math.fabs(svalue) / float(32767)

                if svalue < 0:
                    value = math.fabs(svalue) / float(32768)

                if self.envelope < value:
                    self.envelope *= ga
                    self.envelope += (1.0 - ga) * value
                else:
                    self.envelope *= gr
                    self.envelope += (1.0 - gr) * value
                    
                self.amplitudebuffer[arrayptr] = math.floor(self.envelope)
                
                if self.amplitudebuffer[arrayptr] >= detectlevel:
                    if self.detectwidthcounter == 0:
                        self.lastrisingedge = arrayptr * sampletime
                    self.detectwidthcounter = self.detectwidthcounter + 1
                    if self.detectwidthcounter >= minwidth:
                        radcount = radcount + 1
                        self.onecaptured = True
                        self.lastminwidthedge = arrayptr * sampletime
                    self.last = True
                else:
                    if self.last==True:
                        self.lastfallingedge = arrayptr * sampletime
                        self.deadticker = deadtime
                    self.detectwidthcounter = 0
                    self.deadticker = self.deadticker - 1
                    self.last = False
                if self.deadticker == 0:
                    self.lastdeadtimeedge = arrayptr * sampletime
                arrayptr = arrayptr + 1

                n = n + 2
		
                cpm = radcount
		
        except Exception as ex:
            print "Problem with audio port => geiger 1:\r\n\t", str(ex),"\r\nExiting\r\n"
            stream.stop_stream()
            stream.close()
            self.p.terminate()
            self.stop()
            sys.exit(1)
...

Please Log in or Create an account to join the conversation.

Moderators: Gamma-Man
Time to create page: 0.175 seconds
Powered by Kunena Forum
Everything's free. Please support us by considering a donation. Log in first!
Solar powered Raspberry Pi 4 server stats: CPU 39% Memory 17% Swap 2% CPU temp=54.0'C Uptime 1 Days