Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion respeaker_ros/scripts/respeaker_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self):
self.speech_continuation = rospy.get_param("~speech_continuation", 0.5)
self.speech_max_duration = rospy.get_param("~speech_max_duration", 7.0)
self.speech_min_duration = rospy.get_param("~speech_min_duration", 0.1)
self.sample_duration = rospy.get_param("~sample_duration", None) # sec
suppress_pyaudio_error = rospy.get_param("~suppress_pyaudio_error", True)
#
self.respeaker = RespeakerInterface()
Expand All @@ -34,7 +35,8 @@ def __init__(self):
self.config = None
self.dyn_srv = Server(RespeakerConfig, self.on_config)
# start
self.respeaker_audio = RespeakerAudio(self.on_audio, suppress_error=suppress_pyaudio_error)
self.respeaker_audio = RespeakerAudio(self.on_audio, suppress_error=suppress_pyaudio_error,
sample_duration=self.sample_duration)
self.speech_prefetch_bytes = int(
self.speech_prefetch * self.respeaker_audio.rate * self.respeaker_audio.bitdepth / 8.0)
self.speech_prefetch_buffer = b""
Expand Down
8 changes: 6 additions & 2 deletions respeaker_ros/src/respeaker_ros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def close(self):


class RespeakerAudio(object):
def __init__(self, on_audio, channel=0, suppress_error=True):
def __init__(self, on_audio, channel=0, suppress_error=True, sample_duration=None):
self.on_audio = on_audio
with ignore_stderr(enable=suppress_error):
self.pyaudio = pyaudio.PyAudio()
Expand All @@ -242,6 +242,10 @@ def __init__(self, on_audio, channel=0, suppress_error=True):
self.rate = 16000
self.bitwidth = 2
self.bitdepth = 16
if sample_duration is not None:
frames_per_buffer = int(sample_duration * self.rate)
else:
frames_per_buffer = 1024

# find device
count = self.pyaudio.get_device_count()
Expand Down Expand Up @@ -272,7 +276,7 @@ def __init__(self, on_audio, channel=0, suppress_error=True):
format=pyaudio.paInt16,
channels=self.channels,
rate=self.rate,
frames_per_buffer=1024,
frames_per_buffer=frames_per_buffer,
stream_callback=self.stream_callback,
input_device_index=self.device_index,
)
Expand Down
Loading