From 1a847e0fa9c9f0157613387be8c08f849c1858f8 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Fri, 2 Oct 2015 17:59:48 +0900 Subject: [PATCH] [WIP] add subscribers/speech.cpp --- CMakeLists.txt | 1 + src/naoqi_driver.cpp | 2 ++ src/subscribers/speech.cpp | 48 ++++++++++++++++++++++++++++++ src/subscribers/speech.hpp | 60 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/subscribers/speech.cpp create mode 100644 src/subscribers/speech.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fa0bf61a..b24e630e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ set( SUBSCRIBER_SRC src/subscribers/teleop.cpp src/subscribers/moveto.cpp + src/subscribers/speech.cpp ) set( diff --git a/src/naoqi_driver.cpp b/src/naoqi_driver.cpp index 3c1ceb4e..ffa9002f 100644 --- a/src/naoqi_driver.cpp +++ b/src/naoqi_driver.cpp @@ -60,6 +60,7 @@ */ #include "subscribers/teleop.hpp" #include "subscribers/moveto.hpp" +#include "subscribers/speech.hpp" /* @@ -787,6 +788,7 @@ void Driver::registerDefaultSubscriber() return; registerSubscriber( boost::make_shared("teleop", "/cmd_vel", "/joint_angles", sessionPtr_) ); registerSubscriber( boost::make_shared("moveto", "/move_base_simple/goal", sessionPtr_, tf2_buffer_) ); + registerSubscriber( boost::make_shared("speech", "/speech", sessionPtr_) ); } void Driver::registerService( service::Service srv ) diff --git a/src/subscribers/speech.cpp b/src/subscribers/speech.cpp new file mode 100644 index 00000000..f0ee4879 --- /dev/null +++ b/src/subscribers/speech.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2015 Aldebaran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +/* + * LOCAL includes + */ +#include "speech.hpp" + + +namespace naoqi +{ +namespace subscriber +{ + +SpeechSubscriber::SpeechSubscriber( const std::string& name, const std::string& speech_topic, const qi::SessionPtr& session ): + speech_topic_(speech_topic), + BaseSubscriber( name, speech_topic, session ), + p_tts_( session->service("ALTextToSpeech") ) +{} + +void SpeechSubscriber::reset( ros::NodeHandle& nh ) +{ + sub_speech_ = nh.subscribe( speech_topic_, 10, &SpeechSubscriber::speech_callback, this ); + + is_initialized_ = true; +} + +void SpeechSubscriber::speech_callback( const std_msgs::StringConstPtr& string_msg ) +{ + p_tts_.async("say", string_msg->data); +} + +} //publisher +} // naoqi diff --git a/src/subscribers/speech.hpp b/src/subscribers/speech.hpp new file mode 100644 index 00000000..ca032922 --- /dev/null +++ b/src/subscribers/speech.hpp @@ -0,0 +1,60 @@ +/* + * Copyright 2015 Aldebaran + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef SPEECH_SUBSCRIBER_HPP +#define SPEECH_SUBSCRIBER_HPP + +/* + * LOCAL includes + */ +#include "subscriber_base.hpp" + +/* + * ROS includes + */ +#include +#include + +namespace naoqi +{ +namespace subscriber +{ + +class SpeechSubscriber: public BaseSubscriber +{ +public: + SpeechSubscriber( const std::string& name, const std::string& speech_topic, const qi::SessionPtr& session ); + ~SpeechSubscriber(){} + + void reset( ros::NodeHandle& nh ); + void speech_callback( const std_msgs::StringConstPtr& speech_msg ); + +private: + + std::string speech_topic_; + + qi::AnyObject p_tts_; + ros::Subscriber sub_speech_; + + + +}; // class Speech + +} // subscriber +}// naoqi +#endif