Beispiel #1
0
def getNoiseLevel():
    buf = upmMicrophone.uint16Array(128)
    buflen = myMic.getSampledWindow(2, 128, buf)
    if buflen:
        thresh = myMic.findThreshold(threshContext, 30, buf, buflen)
        if(thresh):
            return thresh
Beispiel #2
0
 def __init__(self, refresh=1, port=3, averageReading=0, runningAverage=0, averagedOver=2,  *args, **kwargs):
     super(SoundSensor, self).__init__(refresh=refresh, *args, **kwargs)
     self.upm_sensor = mic.Microphone(port)
     self.threshContext = mic.thresholdContext()
     self.threshContext.averageReading = averageReading
     self.threshContext.runningAverage = runningAverage
     self.threshContext.averagedOver = averagedOver
     self.buffer = mic.uint16Array(128)
def get_sound():
    buffer = upmMicrophone.uint16Array(128)
    len = myMic.getSampledWindow(2, 128, buffer);
    if len:
        thresh = myMic.findThreshold(threshContext, 30, buffer, len)
        if(thresh):
            print "Threshold is ", thresh
    return thresh
Beispiel #4
0
 def getLoudness(self):
     buffer = upmMicrophone.uint16Array(128)
     len = self.mic.getSampledWindow(2, 128, buffer)
     thresh = 0
     if len:
         thresh = self.mic.findThreshold(self.threshContext, 30, buffer,
                                         len)
     return thresh
Beispiel #5
0
def Yelled(mic):
    buffer = upmMicrophone.uint16Array(128)
    len = myMic.getSampledWindow(2, 128, buffer);
    if len:
        thresh = myMic.findThreshold(threshContext, 30, buffer, len)
        # myMic.printGraph(threshContext)
        if(thresh):
            print (thresh / averageThreshold)
            return (thresh / averageThreshold) > 1
Beispiel #6
0
	def readData(self):
		while(1):
			buffer = upmMicrophone.uint16Array(128)
			len = self.soundSensor.getSampledWindow(2, 128, buffer);
			if len:
				thresh = self.soundSensor.findThreshold(self.threshContext, 30, buffer, len)
				if(thresh):
					self.data=thresh
					return self.data
        def get_value(self):
            sample_buffer = pyupm_mic.uint16Array(self.samples)
            s_num = self.actuator.getSampledWindow(self._sample_rate,
                                                   self.samples, sample_buffer)
            if s_num:
                db = self.actuator.findThreshold(self.ctx, self.threshold,
                                                 sample_buffer, self.samples)
                return db

            logger.info('No actual data from microphone')
            return False
    def getSound(self):
        myMic = upmMicrophone.Microphone(int(self.port))
        threshContext = upmMicrophone.thresholdContext()
        threshContext.averageReading = 0
        threshContext.runningAverage = 0
        threshContext.averagedOver = 2

        buffer = upmMicrophone.uint16Array(128)
        len = myMic.getSampledWindow(2, 128, buffer)
        if len:
            thresh = myMic.findThreshold(threshContext, 30, buffer, len)
            #myMic.printGraph(threshContext)
            if (thresh):
                print "Threshold is ", thresh
                self.info["soundLevel"] = str(thresh)
                del myMic
                return self.info
        def get_value(self):
            sample_buffer = pyupm_mic.uint16Array(self.samples)
            s_num = self.actuator.getSampledWindow(
                    self._sample_rate,
                    self.samples,
                    sample_buffer
            )
            if s_num:
                db = self.actuator.findThreshold(
                        self.ctx,
                        self.threshold,
                        sample_buffer,
                        self.samples
                )
                return db

            logger.info('No actual data from microphone')
            return False
 def getNoiseState(self):
     buffer = upmMicrophone.uint16Array(128)
     len = self.myMic.getSampledWindow(100, 128, buffer)
     
     threshContext = upmMicrophone.thresholdContext()
     threshContext.averageReading = 0
     threshContext.runningAverage = 0
     threshContext.averagedOver = 1
     
     self.thresh = self.myMic.findThreshold(threshContext, 30, buffer, len)
     
     if self.thresh<=115:
         self.state = 0
     elif self.thresh>115 and self.thresh<self.threshold-self.threshold/7:
         self.state = 1
     elif self.thresh>=self.threshold-self.threshold/7 and self.thresh<=self.threshold:
         self.state = 2
     elif self.thresh>self.threshold:
         self.state = 3
     else:
         '''Smth wrong!'''
Beispiel #11
0
    def getNoiseState(self):
        buffer = upmMicrophone.uint16Array(128)
        len = self.myMic.getSampledWindow(100, 128, buffer)

        threshContext = upmMicrophone.thresholdContext()
        threshContext.averageReading = 0
        threshContext.runningAverage = 0
        threshContext.averagedOver = 1

        self.thresh = self.myMic.findThreshold(threshContext, 30, buffer, len)

        if self.thresh <= 115:
            self.state = 0
        elif self.thresh > 115 and self.thresh < self.threshold - self.threshold / 7:
            self.state = 1
        elif self.thresh >= self.threshold - self.threshold / 7 and self.thresh <= self.threshold:
            self.state = 2
        elif self.thresh > self.threshold:
            self.state = 3
        else:
            '''Smth wrong!'''
Beispiel #12
0
def alertSound(message, buffer):
    global Alert
    global mymic
    global t
    global reset
    buf = upmMicrophone.uint16Array(32)
    len = mymic.getSampledWindow(2, 32, buf)
    if len:
        thresh = mymic.findThreshold(threshContext, 30, buf, len)
    buffer.append(str(thresh) + ",")
    if thresh > VOLUME_THRES:
        if reset:
            t = time.time()
            reset = False
        else:
            dt = time.time() - t
            if (dt > 10):
                message.append(Alert.BARKING)
                reset = True
        return True
    else:
        return False
Beispiel #13
0
def alertSound(message, buffer):
    global Alert
    global mymic
    global t
    global reset
    buf = upmMicrophone.uint16Array(32)
    len = mymic.getSampledWindow(2, 32, buf)
    if len:
        thresh = mymic.findThreshold(threshContext, 30, buf, len)
    buffer.append(str(thresh) + ",")
    if thresh > VOLUME_THRES:
        if reset:
            t = time.time()
            reset = False
        else:
            dt = time.time() - t
            if( dt > 10 ) :
                message.append(Alert.BARKING)
                reset = True
        return True
    else:
        return False
Beispiel #14
0
def read_sound_sensor():
    global average, clap, values

    buffer = microphone.uint16Array(128)
    length = mic.getSampledWindow(2, 128, buffer)
    if length:
        thresh = mic.findThreshold(threshContext, 30, buffer, length)
        print thresh
        mic.printGraph(threshContext)
        if thresh:
            if average > 0 and thresh > average * 1.1 and not clap:
                print "clap"
                clap = True
                try:
                    requests.get("http://172.20.10.1:12345/clap")
                except:
                    pass
            values.append(thresh)
            if len(values) >= 2:
                if values[-1] == values[-2]:
                    print "threshold established: %d" % values[-1]
                    average = values[-1]
                    clap = False
Beispiel #15
0
def main():
    # Attach microphone to analog port A0
    myMic = upmMicrophone.Microphone(2)
    threshContext = upmMicrophone.thresholdContext()
    threshContext.averageReading = 0
    threshContext.runningAverage = 0
    threshContext.averagedOver = 2

    # Infinite loop, ends when script is cancelled
    # Repeatedly, take a sample every 2 microseconds;
    # find the average of 128 samples; and
    # print a running graph of dots as averages
    while (1):
        buffer = upmMicrophone.uint16Array(128)
        len = myMic.getSampledWindow(2, 128, buffer)
        if len:
            thresh = myMic.findThreshold(threshContext, 30, buffer, len)
            myMic.printGraph(threshContext)
            if (thresh):
                print("Threshold is ", thresh)

    # Delete the upmMicrophone object
    del myMic
Beispiel #16
0
def WelcomAndSetupMic(lcd, delay, myMic):
    global averageThreshold
    lcd.write("Que pedo morro")
    i = delay
    threshSum = 0
    while i >= 0:
        lcd.setColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        time.sleep(0.2)
        i -= 1

        buffer = upmMicrophone.uint16Array(128)
        len = myMic.getSampledWindow(2, 128, buffer);
        if len:
            thresh = myMic.findThreshold(threshContext, 30, buffer, len)
            # myMic.printGraph(threshContext)
            if(thresh):
                # print(thresh)
                threshSum += thresh

    # print threshSum
    averageThreshold = threshSum/float(delay)
    averageThreshold *= 2
    print averageThreshold
Beispiel #17
0
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import time
import pyupm_mic as upmMicrophone

# Attach microphone to analog port A0
myMic = upmMicrophone.Microphone(0)
threshContext = upmMicrophone.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

# Infinite loop, ends when script is cancelled
# Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of dots as averages
while (1):
    buffer = upmMicrophone.uint16Array(128)
    len = myMic.getSampledWindow(2, 128, buffer)
    if len:
        thresh = myMic.findThreshold(threshContext, 30, buffer, len)
        myMic.printGraph(threshContext)
        if (thresh):
            print "Threshold is ", thresh

# Delete the upmMicrophone object
del myMic
Beispiel #18
0
import time
import pyupm_mic as upmMicrophone 

# Attach microphone to analog port A0
myMic = upmMicrophone.Microphone(2)
threshContext = upmMicrophone.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

# Infinite loop, ends when script is cancelled
# Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of dots as averages
while(1):
    buffer = upmMicrophone.uint16Array(128)
    len = myMic.getSampledWindow(2, 128, buffer);
    if len:
        thresh = myMic.findThreshold(threshContext, 30, buffer, len)
        myMic.printGraph(threshContext)
        if(thresh):
            print "Threshold is ", thresh
            print "Value is", myMic.value()

# Delete the upmMicrophone object
del myMic
Beispiel #19
0
# Author: Brendan Le Foll <*****@*****.**>
# Copyright (c) 2014 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

import pyupm_mic

mymic = pyupm_mic.Microphone(1)
# careful this is an unitialised array with no bounds checking!
x = pyupm_mic.uint16Array(3)
mymic.getSampledWindow(100, 3, x)