class send_params:
    def __init__(self):
        self.dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
        if self.dev:
            self.Mic_tuning = Tuning(self.dev)
        self.vad_pub = rospy.Publisher("vad", Int16, queue_size=1)
        self.doa_pub = rospy.Publisher("Doa", Float32, queue_size=1)
        self.publishers()

    def publishers(self):
        while not rospy.is_shutdown():
            doa = self.Mic_tuning.direction
            speech = self.Mic_tuning.read('SPEECHDETECTED')
            time.sleep(0.05)
            self.vad_pub.publish(speech)
            self.doa_pub.publish(doa)
示例#2
0
from tuning import Tuning
import usb.core
import usb.util
import time
import sys

dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)

if dev:
    Mic_tuning = Tuning(dev)
    while True:
        try:
            #print "\rDIR:", Mic_tuning.direction, ", VAD:", Mic_tuning.is_voice(), "SPEECH:", Mic_tuning.read('SPEECHDETECTED'),
            if Mic_tuning.read('SPEECHDETECTED'):
                print 's',
            elif Mic_tuning.is_voice():
                print ".",
            sys.stdout.flush()
            time.sleep(0.1)
        except KeyboardInterrupt:
            break
示例#3
0
class AudioMessage(object):
    """Class to publish audio to topic"""
    def __init__(self):

        # Initializing publisher with buffer size of 10 messages
        self.pub_ = rospy.Publisher("sphinx_audio", String, queue_size=10)
        self.dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
        self.rec_buffers = 0
        # initialize node
        rospy.init_node("audio_control")
        # Call custom function on node shutdown
        rospy.on_shutdown(self.shutdown)

        # All set. Publish to topic
        self.transfer_audio_msg()

    def transfer_audio_msg(self):
        """Function to publish input audio to topic"""

        rospy.loginfo("audio input node will start after delay of 5 seconds")
        sleep(5)

        # Params
        self._input = "~input"
        _rate_bool = False

        #creating the object for reading speech recognized value from respeaker
        if self.dev:
            self.Mic_tuning = Tuning(self.dev)
        # Checking if audio file given or system microphone is needed
        if rospy.has_param(self._input):
            if rospy.get_param(self._input) != ":default":
                _rate_bool = True
                stream = open(rospy.get_param(self._input), 'rb')
                rate = rospy.Rate(5)  # 10hz
            else:
                # Initializing pyaudio for input from system microhpone
                stream = pyaudio.PyAudio().open(format=pyaudio.paInt16,
                                                channels=6,
                                                rate=16000,
                                                input=True,
                                                frames_per_buffer=1024)
                stream.start_stream()
        else:
            rospy.logerr(
                "No input means provided. Please use the launch file instead")
        while not rospy.is_shutdown():
            data = stream.read(1024)
            speech = self.Mic_tuning.read('SPEECHDETECTED')
            if self.rec_buffers == 0:
                a = np.fromstring(data, dtype=np.int16)[0::6]
                self.rec_buffers = 1
            elif speech == 1:
                np.append(a, np.fromstring(data, dtype=np.int16)[0::6])
                self.rec_buffers += 1
            # else:
            #     a = np.fromstring(data, dtype=np.int16)[0::6]
            #     self.rec_buffers = 1
            # buf = stream.read(1024)
            buf = a.tostring()
            if buf:
                if self.rec_buffers > 1 and speech == 0:
                    print("publishing")
                    # Publish audio to topic
                    self.pub_.publish(buf)
                    self.rec_buffers = 0
                    if _rate_bool:
                        rate.sleep()
            else:
                rospy.loginfo("Buffer returned null")
                break

    @staticmethod
    def shutdown():
        """This function is executed on node shutdown."""
        # command executed after Ctrl+C is pressed
        rospy.loginfo("Stop ASRControl")
        rospy.sleep(1)
示例#4
0
from tuning import Tuning
import usb.core
import usb.util
import time

dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
#print dev
if dev:
    Mic_tuning = Tuning(dev)
    print Mic_tuning.is_voice()
    Mic_tuning.set_vad_threshold(15.0)
    while True:
        try:
            # print Mic_tuning.read('GAMMAVAD_SR')
            print(Mic_tuning.read('SPEECHDETECTED'),Mic_tuning.is_voice())
            # print Mic_tuning.is_voice()
            time.sleep(0.05)
        except KeyboardInterrupt:
            break
示例#5
0
    client.subscribe("hermes/asr/textCaptured")

    ros_listener()
    #wait until microphone is correctly restarted from the other script
    rospy.loginfo(
        "Snips script is sleeping for 20 seconds to wait for respeaker_node to finish launching"
    )
    time.sleep(20)

    if dev:
        Mic_tuning = Tuning(dev)

        while True:
            try:
                #rospy.loginfo"VOICEACTIVITY:", Mic_tuning.is_voice()),
                speechdetected = Mic_tuning.read(
                    "VOICEACTIVITY")  #SPEECHRECOGNIZED fires too often
                #rospy.loginfospeechdetected),

                if speechdetected:
                    if time.time(
                    ) - last_speechdetected_timestamp > LAUNCH_INTERVAL and not pepper_is_speaking:
                        client.publish('hermes/asr/startListening',
                                       '{"siteId": "default"}')
                        last_speechdetected_timestamp = time.time(
                        )  #we don't want to trigger more than once per second or so
                        rospy.loginfo(
                            "\nPUBLISHED TO HERMES TO START LISTENING"
                        )  #snips decides when to stop on its own, so no need to tell it to

                last_seen_speechdetected_status = speechdetected
            except KeyboardInterrupt: