From 9556cd6917071a37bdd7095a9a4f41c3a728ace9 Mon Sep 17 00:00:00 2001 From: Hongyu Li Date: Tue, 22 Mar 2022 17:33:34 -0400 Subject: [PATCH] Fixed chunk in param --- .../config/audio_params.yaml | 1 - .../launch/wav_audio.launch | 4 ++-- .../msg/MyAudioData.msg | 2 +- .../scripts/stretch_audio.py | 22 +++++++++---------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/vz_acoustic_scene_analysis/config/audio_params.yaml b/vz_acoustic_scene_analysis/config/audio_params.yaml index 6c875c1..4f25a13 100644 --- a/vz_acoustic_scene_analysis/config/audio_params.yaml +++ b/vz_acoustic_scene_analysis/config/audio_params.yaml @@ -1,4 +1,3 @@ ---- TIMEOUT: 100000 VENDOR_ID: 0x2886 PRODUCT_ID: 0x0018 diff --git a/vz_acoustic_scene_analysis/launch/wav_audio.launch b/vz_acoustic_scene_analysis/launch/wav_audio.launch index 9f442a5..62d5536 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 ccfdc58..38c1e43 100644 --- a/vz_acoustic_scene_analysis/msg/MyAudioData.msg +++ b/vz_acoustic_scene_analysis/msg/MyAudioData.msg @@ -1 +1 @@ -string[] data \ No newline at end of file +uint16[] data \ 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 14bd207..d4ddbb4 100755 --- a/vz_acoustic_scene_analysis/scripts/stretch_audio.py +++ b/vz_acoustic_scene_analysis/scripts/stretch_audio.py @@ -187,12 +187,11 @@ def get_respeaker_device_id(): return device_id -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_RATE = rospy.get_param("/RESPEAKER_RATE", 16000) +RESPEAKER_CHANNELS = rospy.get_param("/RESPEAKER_CHANNELS", 6) # 6 must flash 6_channels_firmware.bin first +RESPEAKER_WIDTH = rospy.get_param("/RESPEAKER_WIDTH", 2) RESPEAKER_INDEX = get_respeaker_device_id() -CHUNK = rospy.get_param("/RESPEAKER_RATE") # 1024 - +CHUNK = rospy.get_param("/CHUNK", 1024) class Audio: def __init__(self): @@ -207,8 +206,9 @@ class Audio: def get_audio(self): recorded_frames = self.record_audio(self.chunk_size) # set param here chunk size - # print(str(recorded_frames)) - self.audio_data_pub.publish(recorded_frames) + audio = MyAudioData() + audio.data = np.array(recorded_frames, dtype=np.uint16) + self.audio_data_pub.publish(audio) self.wav_list.append(recorded_frames) self.record_count += 1 # Every 5 seconds for @@ -256,15 +256,15 @@ class Audio: if respeaker.is_voice() == 1: # wav_data = list of lists of bytes wav_data = self.get_audio() - if (str(type(wav_data)) == ""): - # Maybe publish wav_data as ROS message? - pass + # if (str(type(wav_data)) == ""): + # # Maybe publish wav_data as ROS message? + # pass # publish_wav(wav_data) # lol # Call of Utku's function # asa_out = process_wav(wav_data, asa_params) # Convert asa_out to ROS message audio_count += 1 - print(audio_count) + print("Audio count: ", audio_count) except usb.core.USBError: print('Respeaker not on USB bus')