(self)
| 45 | return score |
| 46 | |
| 47 | def fetchThreshold(self): |
| 48 | |
| 49 | # TODO: Consolidate variables from the next three functions |
| 50 | THRESHOLD_MULTIPLIER = 1.8 |
| 51 | RATE = 16000 |
| 52 | CHUNK = 1024 |
| 53 | |
| 54 | # number of seconds to allow to establish threshold |
| 55 | THRESHOLD_TIME = 1 |
| 56 | |
| 57 | # prepare recording stream |
| 58 | stream = self._audio.open(format=pyaudio.paInt16, |
| 59 | channels=1, |
| 60 | rate=RATE, |
| 61 | input=True, |
| 62 | frames_per_buffer=CHUNK) |
| 63 | |
| 64 | # stores the audio data |
| 65 | frames = [] |
| 66 | |
| 67 | # stores the lastN score values |
| 68 | lastN = [i for i in range(20)] |
| 69 | |
| 70 | # calculate the long run average, and thereby the proper threshold |
| 71 | for i in range(0, RATE / CHUNK * THRESHOLD_TIME): |
| 72 | |
| 73 | data = stream.read(CHUNK) |
| 74 | frames.append(data) |
| 75 | |
| 76 | # save this data point as a score |
| 77 | lastN.pop(0) |
| 78 | lastN.append(self.getScore(data)) |
| 79 | average = sum(lastN) / len(lastN) |
| 80 | |
| 81 | stream.stop_stream() |
| 82 | stream.close() |
| 83 | |
| 84 | # this will be the benchmark to cause a disturbance over! |
| 85 | THRESHOLD = average * THRESHOLD_MULTIPLIER |
| 86 | |
| 87 | return THRESHOLD |
| 88 | |
| 89 | def passiveListen(self, PERSONA): |
| 90 | """ |
no test coverage detected