forked from tanishaness/SPROCTOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated and Handled all python files (tanishaness#31)
* Update audio.py * Update detection.py * Update face-rec.py * Update graph.py * Update head_pose.py * Update peer_comparison_tool.py * Update processes.py * Update pyaudio_test.py * Update run.py * Update screen_recorder.py
- Loading branch information
1 parent
72b8a82
commit dba4662
Showing
10 changed files
with
538 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,81 @@ | ||
import sounddevice as sd | ||
import numpy as np | ||
import logging | ||
|
||
# place holders and global variables | ||
# Configure logging | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
# Placeholders and global variables | ||
SOUND_AMPLITUDE = 0 | ||
AUDIO_CHEAT = 0 | ||
|
||
# sound variables | ||
# SUS means next sound packet is worth analyzing | ||
CALLBACKS_PER_SECOND = 38 # callbacks per sec(system dependent) | ||
SUS_FINDING_FREQUENCY = 2 # calculates SUS *n* times every sec | ||
SOUND_AMPLITUDE_THRESHOLD = 20 # amplitude considered for SUS calc | ||
# Sound variables | ||
CALLBACKS_PER_SECOND = 38 # Callbacks per sec (system dependent) | ||
SUS_FINDING_FREQUENCY = 2 # Calculates SUS *n* times every sec | ||
SOUND_AMPLITUDE_THRESHOLD = 20 # Amplitude considered for SUS calc | ||
|
||
# packing *n* frames to calculate SUS | ||
# Packing *n* frames to calculate SUS | ||
FRAMES_COUNT = int(CALLBACKS_PER_SECOND/SUS_FINDING_FREQUENCY) | ||
AMPLITUDE_LIST = list([0]*FRAMES_COUNT) | ||
AMPLITUDE_LIST = list([0] * FRAMES_COUNT) | ||
SUS_COUNT = 0 | ||
count = 0 | ||
|
||
def print_sound(indata, outdata, frames, time, status): | ||
avg_amp = 0 | ||
global SOUND_AMPLITUDE, SUS_COUNT, count, SOUND_AMPLITUDE_THRESHOLD, AUDIO_CHEAT | ||
vnorm = int(np.linalg.norm(indata)*10) | ||
AMPLITUDE_LIST.append(vnorm) | ||
count += 1 | ||
AMPLITUDE_LIST.pop(0) | ||
if count == FRAMES_COUNT: | ||
avg_amp = sum(AMPLITUDE_LIST)/FRAMES_COUNT | ||
SOUND_AMPLITUDE = avg_amp | ||
if SUS_COUNT >= 2: | ||
#print("!!!!!!!!!!!! FBI OPEN UP !!!!!!!!!!!!") | ||
AUDIO_CHEAT = 1 | ||
SUS_COUNT = 0 | ||
if avg_amp > SOUND_AMPLITUDE_THRESHOLD: | ||
SUS_COUNT += 1 | ||
#print("Sus...", SUS_COUNT) | ||
else: | ||
SUS_COUNT = 0 | ||
AUDIO_CHEAT = 0 | ||
count = 0 | ||
|
||
try: | ||
vnorm = int(np.linalg.norm(indata) * 10) | ||
AMPLITUDE_LIST.append(vnorm) | ||
count += 1 | ||
AMPLITUDE_LIST.pop(0) | ||
|
||
if count == FRAMES_COUNT: | ||
avg_amp = sum(AMPLITUDE_LIST) / FRAMES_COUNT | ||
SOUND_AMPLITUDE = avg_amp | ||
|
||
if SUS_COUNT >= 2: | ||
AUDIO_CHEAT = 1 | ||
SUS_COUNT = 0 | ||
|
||
if avg_amp > SOUND_AMPLITUDE_THRESHOLD: | ||
SUS_COUNT += 1 | ||
else: | ||
SUS_COUNT = 0 | ||
AUDIO_CHEAT = 0 | ||
|
||
count = 0 | ||
except Exception as e: | ||
logging.error(f"Error in print_sound: {e}") | ||
# Optionally notify the user | ||
print("An error occurred while processing audio input. Please check the logs.") | ||
|
||
def sound(): | ||
with sd.Stream(callback=print_sound): | ||
sd.sleep(-1) | ||
try: | ||
with sd.Stream(callback=print_sound): | ||
sd.sleep(-1) | ||
except Exception as e: | ||
logging.error(f"Error in sound function: {e}") | ||
print("An error occurred while starting the audio stream. Please check the logs.") | ||
|
||
def sound_analysis(): | ||
global AMPLITUDE_LIST, FRAMES_COUNT, SOUND_AMPLITUDE | ||
while True: | ||
AMPLITUDE_LIST.append(SOUND_AMPLITUDE) | ||
AMPLITUDE_LIST.pop(0) | ||
try: | ||
AMPLITUDE_LIST.append(SOUND_AMPLITUDE) | ||
AMPLITUDE_LIST.pop(0) | ||
|
||
avg_amp = sum(AMPLITUDE_LIST)/FRAMES_COUNT | ||
avg_amp = sum(AMPLITUDE_LIST) / FRAMES_COUNT | ||
|
||
if avg_amp > 10: | ||
print("Sus...") | ||
if avg_amp > 10: | ||
print("Sus...") | ||
except Exception as e: | ||
logging.error(f"Error in sound_analysis: {e}") | ||
print("An error occurred during sound analysis. Please check the logs.") | ||
|
||
if __name__ == "__main__": | ||
sound() | ||
try: | ||
sound() | ||
except KeyboardInterrupt: | ||
logging.info("Sound analysis interrupted by user.") | ||
print("Terminated sound analysis.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.