From 2ce8a4ed980a583e96222483be4913246a475a1e Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 14:39:56 +0100 Subject: [PATCH 01/14] Fix deprecation warning replace tostring with tobytes --- respeaker_ros/scripts/respeaker_node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index baa9c4b54..a03d69794 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -173,7 +173,7 @@ def read(self, name): rospy.logerr(e) rospy.signal_shutdown('Shutdown this node because of USBError') - response = struct.unpack(b'ii', response.tostring()) + response = struct.unpack(b'ii', response.tobytes()) if data[2] == 'int': result = response[0] @@ -283,7 +283,7 @@ def stream_callback(self, in_data, frame_count, time_info, status): data = np.reshape(data, (chunk_per_channel, self.channels)) chan_data = data[:, self.channel] # invoke callback - self.on_audio(chan_data.tostring()) + self.on_audio(chan_data.tobytes()) return None, pyaudio.paContinue def start(self): From e0fd51357862d4549abeaf03546a4104c4bbc109 Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 14:41:37 +0100 Subject: [PATCH 02/14] Use byte strings instead of unicode strings --- respeaker_ros/scripts/respeaker_node.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index a03d69794..3bbab41ff 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -309,7 +309,7 @@ def __init__(self): suppress_pyaudio_error = rospy.get_param("~suppress_pyaudio_error", True) # self.respeaker = RespeakerInterface() - self.speech_audio_buffer = str() + self.speech_audio_buffer = b"" self.is_speeching = False self.speech_stopped = rospy.Time(0) self.prev_is_voice = None @@ -327,7 +327,7 @@ def __init__(self): self.respeaker_audio = RespeakerAudio(self.on_audio, suppress_error=suppress_pyaudio_error) self.speech_prefetch_bytes = int( self.speech_prefetch * self.respeaker_audio.rate * self.respeaker_audio.bitdepth / 8.0) - self.speech_prefetch_buffer = str() + self.speech_prefetch_buffer = b"" self.respeaker_audio.start() self.info_timer = rospy.Timer(rospy.Duration(1.0 / self.update_rate), self.on_timer) @@ -417,7 +417,7 @@ def on_timer(self, event): self.is_speeching = True elif self.is_speeching: buf = self.speech_audio_buffer - self.speech_audio_buffer = str() + self.speech_audio_buffer = b"" self.is_speeching = False duration = 8.0 * len(buf) * self.respeaker_audio.bitwidth duration = duration / self.respeaker_audio.rate / self.respeaker_audio.bitdepth From b7e9b439b74e0053cb9ad9899a76272a329822d1 Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 14:41:48 +0100 Subject: [PATCH 03/14] DOA needs to be an int for publishing --- respeaker_ros/scripts/respeaker_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index 3bbab41ff..d78a642c9 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -386,7 +386,7 @@ def on_timer(self, event): doa_rad = math.radians(self.respeaker.direction - 180.0) doa_rad = angles.shortest_angular_distance( doa_rad, math.radians(self.doa_yaw_offset)) - doa = math.degrees(doa_rad) + doa = int(math.degrees(doa_rad)) # vad if is_voice != self.prev_is_voice: From 751a038869b376779dcd15b9fe152b3365a6d71c Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 14:43:42 +0100 Subject: [PATCH 04/14] Search string must be a byte string --- respeaker_ros/scripts/respeaker_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index d78a642c9..8534b5763 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -237,7 +237,7 @@ def __init__(self, on_audio, channel=0, suppress_error=True): name = info["name"].encode("utf-8") chan = info["maxInputChannels"] rospy.logdebug(" - %d: %s" % (i, name)) - if name.lower().find("respeaker") >= 0: + if name.lower().find(b"respeaker") >= 0: self.channels = chan self.device_index = i rospy.loginfo("Found %d: %s (channels: %d)" % (i, name, chan)) From 7863b13d47db6b2b537c02ff782c222428f8d225 Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 14:44:41 +0100 Subject: [PATCH 05/14] Ensure chunk_per_channel is an int (py3 division change) --- respeaker_ros/scripts/respeaker_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index 8534b5763..d543f3a08 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -279,7 +279,7 @@ def __del__(self): def stream_callback(self, in_data, frame_count, time_info, status): # split channel data = np.fromstring(in_data, dtype=np.int16) - chunk_per_channel = len(data) / self.channels + chunk_per_channel = int(len(data) / self.channels) data = np.reshape(data, (chunk_per_channel, self.channels)) chan_data = data[:, self.channel] # invoke callback From c7c91d2e270d6df021dd68bb75e032bb20211c4a Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 14:46:58 +0100 Subject: [PATCH 06/14] Remove deprecation warning fromstring -> frombuffer --- respeaker_ros/scripts/respeaker_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index d543f3a08..b63ab6db7 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -278,7 +278,7 @@ def __del__(self): def stream_callback(self, in_data, frame_count, time_info, status): # split channel - data = np.fromstring(in_data, dtype=np.int16) + data = np.frombuffer(in_data, dtype=np.int16) chunk_per_channel = int(len(data) / self.channels) data = np.reshape(data, (chunk_per_channel, self.channels)) chan_data = data[:, self.channel] From 03175f1c4e70751c539b3fcb9dfe12f0aeea92e9 Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 15:30:14 +0100 Subject: [PATCH 07/14] Set cancellation option false by default to work out of the box --- respeaker_ros/scripts/speech_to_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/speech_to_text.py b/respeaker_ros/scripts/speech_to_text.py index 439652ba8..47e005005 100755 --- a/respeaker_ros/scripts/speech_to_text.py +++ b/respeaker_ros/scripts/speech_to_text.py @@ -23,7 +23,7 @@ def __init__(self): # language of STT service self.language = rospy.get_param("~language", "ja-JP") # ignore voice input while the robot is speaking - self.self_cancellation = rospy.get_param("~self_cancellation", True) + self.self_cancellation = rospy.get_param("~self_cancellation", False) # time to assume as SPEAKING after tts service is finished self.tts_tolerance = rospy.Duration.from_sec( rospy.get_param("~tts_tolerance", 1.0)) From 7114a5db017417ccd4bda223abe814fcd1cf4c86 Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 15:31:12 +0100 Subject: [PATCH 08/14] Change default language to english --- respeaker_ros/scripts/speech_to_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/speech_to_text.py b/respeaker_ros/scripts/speech_to_text.py index 47e005005..8b8de6332 100755 --- a/respeaker_ros/scripts/speech_to_text.py +++ b/respeaker_ros/scripts/speech_to_text.py @@ -21,7 +21,7 @@ def __init__(self): self.sample_rate = rospy.get_param("~sample_rate", 16000) self.sample_width = rospy.get_param("~sample_width", 2) # language of STT service - self.language = rospy.get_param("~language", "ja-JP") + self.language = rospy.get_param("~language", "en-GB") # ignore voice input while the robot is speaking self.self_cancellation = rospy.get_param("~self_cancellation", False) # time to assume as SPEAKING after tts service is finished From d526ca385476c99a2a43e3c9d922aa18be764f10 Mon Sep 17 00:00:00 2001 From: Dirk Gorissen Date: Sun, 12 Sep 2021 22:44:31 +0100 Subject: [PATCH 09/14] Listen to speech_audio topic --- respeaker_ros/scripts/speech_to_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/speech_to_text.py b/respeaker_ros/scripts/speech_to_text.py index 8b8de6332..b0eaf9240 100755 --- a/respeaker_ros/scripts/speech_to_text.py +++ b/respeaker_ros/scripts/speech_to_text.py @@ -50,7 +50,7 @@ def __init__(self): self.pub_speech = rospy.Publisher( "speech_to_text", SpeechRecognitionCandidates, queue_size=1) - self.sub_audio = rospy.Subscriber("audio", AudioData, self.audio_cb) + self.sub_audio = rospy.Subscriber("speech_audio", AudioData, self.audio_cb) def tts_timer_cb(self, event): stamp = event.current_real From da647e5c3f1d91188bd435627e30f071faf19efb Mon Sep 17 00:00:00 2001 From: Naoya Yamaguchi <708yamaguchi@gmail.com> Date: Mon, 13 Sep 2021 20:37:05 +0900 Subject: [PATCH 10/14] Keep Python 2.x compatibility --- respeaker_ros/scripts/respeaker_node.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/respeaker_node.py b/respeaker_ros/scripts/respeaker_node.py index b63ab6db7..f95f60866 100755 --- a/respeaker_ros/scripts/respeaker_node.py +++ b/respeaker_ros/scripts/respeaker_node.py @@ -173,7 +173,10 @@ def read(self, name): rospy.logerr(e) rospy.signal_shutdown('Shutdown this node because of USBError') - response = struct.unpack(b'ii', response.tobytes()) + if sys.version_info.major == 2: + response = struct.unpack(b'ii', response.tostring()) + else: + response = struct.unpack(b'ii', response.tobytes()) if data[2] == 'int': result = response[0] From f254dc9828c0ec74ee49873143a3c0ada38e96dd Mon Sep 17 00:00:00 2001 From: Naoya Yamaguchi <708yamaguchi@gmail.com> Date: Mon, 13 Sep 2021 20:38:06 +0900 Subject: [PATCH 11/14] Revert "Set cancellation option false by default to work out of the box" This reverts commit 03175f1c4e70751c539b3fcb9dfe12f0aeea92e9. --- respeaker_ros/scripts/speech_to_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/speech_to_text.py b/respeaker_ros/scripts/speech_to_text.py index b0eaf9240..b2ab6564f 100755 --- a/respeaker_ros/scripts/speech_to_text.py +++ b/respeaker_ros/scripts/speech_to_text.py @@ -23,7 +23,7 @@ def __init__(self): # language of STT service self.language = rospy.get_param("~language", "en-GB") # ignore voice input while the robot is speaking - self.self_cancellation = rospy.get_param("~self_cancellation", False) + self.self_cancellation = rospy.get_param("~self_cancellation", True) # time to assume as SPEAKING after tts service is finished self.tts_tolerance = rospy.Duration.from_sec( rospy.get_param("~tts_tolerance", 1.0)) From bc6967bc0ebdee4b23238a5769bf71cbbe9b5f86 Mon Sep 17 00:00:00 2001 From: Naoya Yamaguchi <708yamaguchi@gmail.com> Date: Mon, 13 Sep 2021 20:38:21 +0900 Subject: [PATCH 12/14] Revert "Change default language to english" This reverts commit 7114a5db017417ccd4bda223abe814fcd1cf4c86. --- respeaker_ros/scripts/speech_to_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/speech_to_text.py b/respeaker_ros/scripts/speech_to_text.py index b2ab6564f..0d86cbb26 100755 --- a/respeaker_ros/scripts/speech_to_text.py +++ b/respeaker_ros/scripts/speech_to_text.py @@ -21,7 +21,7 @@ def __init__(self): self.sample_rate = rospy.get_param("~sample_rate", 16000) self.sample_width = rospy.get_param("~sample_width", 2) # language of STT service - self.language = rospy.get_param("~language", "en-GB") + self.language = rospy.get_param("~language", "ja-JP") # ignore voice input while the robot is speaking self.self_cancellation = rospy.get_param("~self_cancellation", True) # time to assume as SPEAKING after tts service is finished From 4deacf0ac66015479aaaaa197e6e8040804e423a Mon Sep 17 00:00:00 2001 From: Naoya Yamaguchi <708yamaguchi@gmail.com> Date: Mon, 13 Sep 2021 20:38:32 +0900 Subject: [PATCH 13/14] Revert "Listen to speech_audio topic" This reverts commit d526ca385476c99a2a43e3c9d922aa18be764f10. --- respeaker_ros/scripts/speech_to_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/respeaker_ros/scripts/speech_to_text.py b/respeaker_ros/scripts/speech_to_text.py index 0d86cbb26..439652ba8 100755 --- a/respeaker_ros/scripts/speech_to_text.py +++ b/respeaker_ros/scripts/speech_to_text.py @@ -50,7 +50,7 @@ def __init__(self): self.pub_speech = rospy.Publisher( "speech_to_text", SpeechRecognitionCandidates, queue_size=1) - self.sub_audio = rospy.Subscriber("speech_audio", AudioData, self.audio_cb) + self.sub_audio = rospy.Subscriber("audio", AudioData, self.audio_cb) def tts_timer_cb(self, event): stamp = event.current_real From b7514a2abfe7bb5f49dc48fa324606a5580ef1ff Mon Sep 17 00:00:00 2001 From: Naoya Yamaguchi <708yamaguchi@gmail.com> Date: Mon, 13 Sep 2021 20:42:16 +0900 Subject: [PATCH 14/14] Add self_cancellation variable to sample_respeaker.launch --- respeaker_ros/launch/sample_respeaker.launch | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/respeaker_ros/launch/sample_respeaker.launch b/respeaker_ros/launch/sample_respeaker.launch index d574a6b19..31d083608 100644 --- a/respeaker_ros/launch/sample_respeaker.launch +++ b/respeaker_ros/launch/sample_respeaker.launch @@ -11,6 +11,8 @@ + + language: $(arg language) - self_cancellation: true + self_cancellation: $(arg self_cancellation) tts_tolerance: 0.5