-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a playback node to gcloud_speech_utils (#7)
* Adds a microphone playback node * Use a newer version of record_audio.cc, and adds a playback node to utils
- Loading branch information
Showing
8 changed files
with
146 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Tue Oct 3 11:31:45 PDT 2017 | ||
Tue Oct 3 13:42:09 PDT 2017 | ||
CogRob/workspace branch: master | ||
14068e6c1040ee1d401e8a98487583e36aa015fd | ||
f9f959353d691b92dbc9b9227b4b4235ba91c738 | ||
Working directory clean. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
import array | ||
import collections | ||
import pyaudio | ||
import Queue | ||
import time | ||
|
||
import rospy | ||
import gcloud_speech_msgs.msg as gcloud_speech_msgs | ||
|
||
LinearPcm16Le16000Audio = gcloud_speech_msgs.LinearPcm16Le16000Audio | ||
|
||
FRAME_PER_SLICE=1600 | ||
|
||
_audio_queue = collections.deque() | ||
|
||
|
||
def RosCallback(msg): | ||
_audio_queue.append(msg.data) | ||
rospy.loginfo("Received {} bytes.".format(len(msg.data))) | ||
|
||
|
||
def PaCallback(in_data, frame_count, time_info, status): | ||
assert frame_count == FRAME_PER_SLICE | ||
|
||
while True: | ||
try: | ||
data = _audio_queue.popleft() | ||
break | ||
except: | ||
time.sleep(.5) | ||
|
||
return (data, pyaudio.paContinue) | ||
|
||
|
||
def PlaybackMicrophoneAudio(): | ||
rospy.init_node('playback_microphone_audio', anonymous=True) | ||
rospy.Subscriber( | ||
"/cogrob/microphone_audio", LinearPcm16Le16000Audio, RosCallback, | ||
queue_size=10) | ||
pa = pyaudio.PyAudio() | ||
stream = pa.open( | ||
format=pyaudio.paInt16, channels=1, rate=16000, output=True, | ||
stream_callback=PaCallback, frames_per_buffer=FRAME_PER_SLICE) | ||
|
||
stream.start_stream() | ||
rospy.spin() | ||
pa.terminate() | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
PlaybackMicrophoneAudio() | ||
except rospy.ROSInterruptException: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Tue Oct 3 11:31:51 PDT 2017 | ||
Tue Oct 3 13:41:59 PDT 2017 | ||
CogRob/workspace branch: master | ||
14068e6c1040ee1d401e8a98487583e36aa015fd | ||
f9f959353d691b92dbc9b9227b4b4235ba91c738 | ||
Working directory clean. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters