diff --git a/vz_acoustic_scene_analysis/CMakeLists.txt b/vz_acoustic_scene_analysis/CMakeLists.txt index 657b90d..bb85832 100644 --- a/vz_acoustic_scene_analysis/CMakeLists.txt +++ b/vz_acoustic_scene_analysis/CMakeLists.txt @@ -28,7 +28,7 @@ find_package(Boost REQUIRED COMPONENTS thread) ## Uncomment this if the package has a setup.py. This macro ensures ## modules and global scripts declared therein get installed ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html -# catkin_python_setup() +catkin_python_setup() ################################################ ## Declare ROS messages, services and actions ## diff --git a/vz_acoustic_scene_analysis/models/cough_classification_scaler b/vz_acoustic_scene_analysis/models/cough_classification_scaler new file mode 100644 index 0000000..e4bf27a Binary files /dev/null and b/vz_acoustic_scene_analysis/models/cough_classification_scaler differ diff --git a/vz_acoustic_scene_analysis/models/cough_classifier b/vz_acoustic_scene_analysis/models/cough_classifier new file mode 100644 index 0000000..0bcbe52 Binary files /dev/null and b/vz_acoustic_scene_analysis/models/cough_classifier differ diff --git a/vz_acoustic_scene_analysis/scripts/stretch_audio.py b/vz_acoustic_scene_analysis/scripts/stretch_audio.py index 9004cac..fd0ee16 100755 --- a/vz_acoustic_scene_analysis/scripts/stretch_audio.py +++ b/vz_acoustic_scene_analysis/scripts/stretch_audio.py @@ -8,22 +8,31 @@ from sympy import re import usb.core import struct import time +import sys import os import rospy +import pickle from contextlib import contextmanager import stretch_body.hello_utils as hu hu.print_stretch_re_use() from vz_acoustic_scene_analysis.msg import MyAudioData from rospy.numpy_msg import numpy_msg -# Utku's script -# import segmentation as seg -import sys -sys.path.append('/home/hello-robot/vz_modules/NEU_VZ_ASA/MehrshadTesting/codes/A_CoughDetection/src') -import feature_class -import DSP +import NEU_VZ_ASA.MehrshadTesting.codes.A_CoughDetection.src.DSP as dsp + +model_path = '/home/hello-robot/clone/Robot_Autonomous_Navigation/catkin_ws/src/stretch_ros/vz_acoustic_scene_analysis/models/' +cough_classifier_file = model_path + 'cough_classifier' +cough_classifier_scaler = model_path + 'cough_classification_scaler' +loaded_model = pickle.load(open(cough_classifier_file, 'rb')) +loaded_scaler = pickle.load(open(cough_classifier_scaler, 'rb')) + +# model_loc = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +# print(model_loc) +from models import cough_classifier, cough_classification_scaler +# Import Utku's script +# from vz_acoustic_scene_analysis.models import cough_classifier as classifier +# from vz_acoustic_scene_analysis.models import cough_classification_scaler as scaler -# what does this mean @contextmanager def ignore_stderr(): devnull = None @@ -206,7 +215,9 @@ class ROSInterface: self.respeaker = Tuning() # Publisher for Audio Data self.audio_data_pub = rospy.Publisher("/wav_data", numpy_msg(MyAudioData), queue_size=10) - # Connect to Utku's code + # For Utku's code: float of cough probabilty from sample + self.cough_prob = 0 + def get_audio(self): recorded_frames = self.record_audio(self.chunk_size) # set param here chunk size @@ -271,6 +282,8 @@ class ROSInterface: flat_list = [item for sublist in wav_data for item in sublist] print(type(flat_list[0])) # Call of Utku's function + self.cough_prob = dsp.classify_cough(flat_list, RESPEAKER_RATE) + print(self.cough_prob) # asa_out = process_wav(wav_data, asa_params) # Convert asa_out to ROS message audio_count += 1 diff --git a/vz_acoustic_scene_analysis/setup.py b/vz_acoustic_scene_analysis/setup.py new file mode 100644 index 0000000..e898f98 --- /dev/null +++ b/vz_acoustic_scene_analysis/setup.py @@ -0,0 +1,8 @@ +from distutils.core import setup +from catkin_pkg.python_setup import generate_distutils_setup + +d = generate_distutils_setup( + packages=['vz_acoustic_scene_analysis'], + package_dir={'': 'scripts'} +) +setup(**d) \ No newline at end of file