diff --git a/vz_acoustic_scene_analysis/CMakeLists.txt b/vz_acoustic_scene_analysis/CMakeLists.txt index feee399..657b90d 100644 --- a/vz_acoustic_scene_analysis/CMakeLists.txt +++ b/vz_acoustic_scene_analysis/CMakeLists.txt @@ -143,7 +143,7 @@ include_directories( ## Declare a C++ executable ## With catkin_make all packages are built within a single CMake context ## The recommended prefix ensures that target names across packages don't collide -add_executable(audio_capture scripts/audio_capture.cpp) +# add_executable(audio_capture scripts/audio_capture.cpp) ## Rename C++ executable without prefix @@ -154,14 +154,14 @@ add_executable(audio_capture scripts/audio_capture.cpp) ## Add cmake target dependencies of the executable ## same as for the library above -add_dependencies(audio_capture ${catkin_EXPORTED_TARGETS}) +# add_dependencies(audio_capture ${catkin_EXPORTED_TARGETS}) ## Specify libraries to link a library or executable target against -target_link_libraries(audio_capture - ${catkin_LIBRARIES} - ${GST1.0_LIBRARIES} - ${Boost_LIBRARIES} -) +# target_link_libraries(audio_capture +# ${catkin_LIBRARIES} +# ${GST1.0_LIBRARIES} +# ${Boost_LIBRARIES} +# ) ############# @@ -180,9 +180,9 @@ target_link_libraries(audio_capture ## Mark executables for installation ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html -install(TARGETS audio_capture - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -) +# install(TARGETS audio_capture +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) ## Mark libraries for installation ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html diff --git a/vz_acoustic_scene_analysis/config/audio_params.yaml b/vz_acoustic_scene_analysis/config/audio_params.yaml new file mode 100644 index 0000000..6c875c1 --- /dev/null +++ b/vz_acoustic_scene_analysis/config/audio_params.yaml @@ -0,0 +1,11 @@ +--- +TIMEOUT: 100000 +VENDOR_ID: 0x2886 +PRODUCT_ID: 0x0018 +RESPEAKER_RATE: 16000 +RESPEAKER_CHANNELS: 6 # must flash 6_channels_firmware.bin first +RESPEAKER_WIDTH: 2 +RESPEAKER_INDEX: get_respeaker_device_id() +CHUNK: 1024 +chunk_size: 0.5 +seconds: 5 \ No newline at end of file diff --git a/vz_acoustic_scene_analysis/launch/wav_audio.launch b/vz_acoustic_scene_analysis/launch/wav_audio.launch index 663bb49..9f442a5 100644 --- a/vz_acoustic_scene_analysis/launch/wav_audio.launch +++ b/vz_acoustic_scene_analysis/launch/wav_audio.launch @@ -1,4 +1,4 @@ - - + + \ No newline at end of file diff --git a/vz_acoustic_scene_analysis/msg/MyAudioData.msg b/vz_acoustic_scene_analysis/msg/MyAudioData.msg index 1735052..ccfdc58 100644 --- a/vz_acoustic_scene_analysis/msg/MyAudioData.msg +++ b/vz_acoustic_scene_analysis/msg/MyAudioData.msg @@ -1 +1 @@ -uint8[] data \ No newline at end of file +string[] data \ No newline at end of file diff --git a/vz_acoustic_scene_analysis/package.xml b/vz_acoustic_scene_analysis/package.xml index 9385210..3ac87f4 100644 --- a/vz_acoustic_scene_analysis/package.xml +++ b/vz_acoustic_scene_analysis/package.xml @@ -82,4 +82,4 @@ - + \ No newline at end of file diff --git a/vz_acoustic_scene_analysis/scripts/stretch_audio.py b/vz_acoustic_scene_analysis/scripts/stretch_audio.py index 14768db..14bd207 100755 --- a/vz_acoustic_scene_analysis/scripts/stretch_audio.py +++ b/vz_acoustic_scene_analysis/scripts/stretch_audio.py @@ -4,6 +4,7 @@ from __future__ import print_function import pyaudio import wave import numpy as np +from sympy import re import usb.core import struct import time @@ -13,6 +14,7 @@ import rospy from contextlib import contextmanager import stretch_body.hello_utils as hu hu.print_stretch_re_use() +from vz_acoustic_scene_analysis.msg import MyAudioData # what does this mean @contextmanager @@ -185,11 +187,11 @@ def get_respeaker_device_id(): return device_id -RESPEAKER_RATE = 16000 -RESPEAKER_CHANNELS = 6 # must flash 6_channels_firmware.bin first -RESPEAKER_WIDTH = 2 +RESPEAKER_RATE = 16000 #rospy.get_param("/RESPEAKER_RATE") #16000 +RESPEAKER_CHANNELS = rospy.get_param("/RESPEAKER_CHANNELS") # 6 must flash 6_channels_firmware.bin first +RESPEAKER_WIDTH = rospy.get_param("/RESPEAKER_WIDTH") # 2 RESPEAKER_INDEX = get_respeaker_device_id() -CHUNK = 1024 +CHUNK = rospy.get_param("/RESPEAKER_RATE") # 1024 class Audio: @@ -198,17 +200,22 @@ class Audio: self.wav_list = [] self.record_count = 0 # Count how many times we've recorded f seconds of audio self.file_name = "/home/hello-robot/Desktop/output_audio.wav" + self.secs = rospy.get_param("/seconds") + self.chunk_size = rospy.get_param("/chunk_size") # Publisher for Audio Data - # self.audio_data_pub = rospy.Publisher("/wav_data", ) + self.audio_data_pub = rospy.Publisher("/wav_data", MyAudioData, queue_size=10) def get_audio(self): - recorded_frames = self.record_audio(.2) # set param here chunk size + recorded_frames = self.record_audio(self.chunk_size) # set param here chunk size + # print(str(recorded_frames)) + self.audio_data_pub.publish(recorded_frames) self.wav_list.append(recorded_frames) self.record_count += 1 # Every 5 seconds for - if ((self.record_count % 2) == 0): # set param sequence size + if ((self.record_count % (self.secs/self.chunk_size)) == 0): # set param sequence size return_list = self.wav_list - # Remove the first object (0.2 seconds of audio data) + # Remove 0.2 seconds of audio data + self.wav_list.pop(0) self.wav_list.pop(0) # send the frames at the beginning of the list (save as wav for now) return return_list @@ -240,7 +247,6 @@ class Audio: def process_audio_loop(self): rospy.init_node("audio_capture") - rospy.param audio_count = 0 dev = usb.core.find(idVendor=0x2886, idProduct=0x0018) try: