8 import gcloud_speech_msgs.msg
as gcloud_speech_msgs
10 LinearPcm16Le16000Audio = gcloud_speech_msgs.LinearPcm16Le16000Audio
12 MSG_FRAME_PER_SLICE = 1600
14 _audio_queue = collections.deque()
18 _audio_queue.append(msg.data)
19 rospy.loginfo(
"Received {} bytes.".format(len(msg.data)))
23 assert frame_count == MSG_FRAME_PER_SLICE * 2
31 data_1 = _audio_queue.popleft()
32 data_2 = _audio_queue.popleft()
33 data = data_1 + data_2
38 return (data, pyaudio.paContinue)
42 rospy.init_node(
'playback_microphone_audio', anonymous=
True)
44 "/cogrob/microphone_audio", LinearPcm16Le16000Audio, RosCallback,
46 pa = pyaudio.PyAudio()
48 format=pyaudio.paInt16, channels=1, rate=16000, output=
True,
49 stream_callback=PaCallback, frames_per_buffer=MSG_FRAME_PER_SLICE * 2)
56 if __name__ ==
'__main__':
59 except rospy.ROSInterruptException:
def PlaybackMicrophoneAudio()
def PaCallback(in_data, frame_count, time_info, status)