Browse Source

I FIXED THE SHUTTING DOWN ISSUE!!!!

pull/65/head
Hongyu Li 2 years ago
parent
commit
2864415730
2 changed files with 10 additions and 5 deletions
  1. +1
    -1
      vz_acoustic_scene_analysis/msg/MyAudioData.msg
  2. +9
    -4
      vz_acoustic_scene_analysis/scripts/stretch_audio.py

+ 1
- 1
vz_acoustic_scene_analysis/msg/MyAudioData.msg View File

@ -1 +1 @@
uint16[] data
int16[] data

+ 9
- 4
vz_acoustic_scene_analysis/scripts/stretch_audio.py View File

@ -202,6 +202,7 @@ class Audio:
self.file_name = "/home/hello-robot/Desktop/output_audio.wav" self.file_name = "/home/hello-robot/Desktop/output_audio.wav"
self.secs = rospy.get_param("/seconds") self.secs = rospy.get_param("/seconds")
self.chunk_size = rospy.get_param("/chunk_size") self.chunk_size = rospy.get_param("/chunk_size")
self.respeaker = Tuning()
# Publisher for Audio Data # Publisher for Audio Data
self.audio_data_pub = rospy.Publisher("/wav_data", numpy_msg(MyAudioData), queue_size=10) self.audio_data_pub = rospy.Publisher("/wav_data", numpy_msg(MyAudioData), queue_size=10)
@ -236,7 +237,7 @@ class Audio:
frames = [] frames = []
for i in range(0, int(RESPEAKER_RATE / CHUNK * seconds)): for i in range(0, int(RESPEAKER_RATE / CHUNK * seconds)):
data = stream.read(CHUNK) data = stream.read(CHUNK)
a = np.frombuffer(data,dtype=np.uint16)[0::6] # extracts fused channel 0
a = np.frombuffer(data,dtype=np.int16)[0::6] # extracts fused channel 0
print("a type: ", type(a[0])) print("a type: ", type(a[0]))
print("a length: ", len(a)) print("a length: ", len(a))
self.audio_data_pub.publish(a) self.audio_data_pub.publish(a)
@ -257,14 +258,12 @@ class Audio:
def process_audio_loop(self): def process_audio_loop(self):
rospy.init_node("audio_capture")
audio_count = 0 audio_count = 0
dev = usb.core.find(idVendor=0x2886, idProduct=0x0018) dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
try: try:
if dev: if dev:
respeaker = Tuning()
while True: while True:
if respeaker.is_voice() == 1:
if self.respeaker.is_voice() == 1:
# wav_data = list of lists of bytes # wav_data = list of lists of bytes
wav_data = self.get_audio() wav_data = self.get_audio()
# if (str(type(wav_data)) == "<class 'list'>"): # if (str(type(wav_data)) == "<class 'list'>"):
@ -279,11 +278,17 @@ class Audio:
except usb.core.USBError: except usb.core.USBError:
print('Respeaker not on USB bus') print('Respeaker not on USB bus')
def shutdown(self):
self.respeaker.close()
print("shutting down")
if __name__ == "__main__": if __name__ == "__main__":
try: try:
rospy.init_node("audio_capture")
audio = Audio() audio = Audio()
audio.process_audio_loop() audio.process_audio_loop()
except rospy.ROSInterruptException: except rospy.ROSInterruptException:
print('Audio processing node failed!') print('Audio processing node failed!')
rospy.on_shutdown(audio.shutdown)
pass pass

Loading…
Cancel
Save