diff --git a/wpb_home_tutorials/CMakeLists.txt b/wpb_home_tutorials/CMakeLists.txt index 4851903..2658ebe 100644 --- a/wpb_home_tutorials/CMakeLists.txt +++ b/wpb_home_tutorials/CMakeLists.txt @@ -245,6 +245,14 @@ target_link_libraries(wpb_home_speech_recognition ${catkin_LIBRARIES} ) +add_executable(wpb_home_sr_xfyun + src/wpb_home_sr_xfyun.cpp +) +add_dependencies(wpb_home_sr_xfyun ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) +target_link_libraries(wpb_home_sr_xfyun + ${catkin_LIBRARIES} +) + add_executable(wpb_home_velocity_control src/wpb_home_velocity_control.cpp ) diff --git a/wpb_home_tutorials/launch/sr_xfyun.launch b/wpb_home_tutorials/launch/sr_xfyun.launch new file mode 100644 index 0000000..15231ab --- /dev/null +++ b/wpb_home_tutorials/launch/sr_xfyun.launch @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/wpb_home_tutorials/src/wpb_home_sr_xfyun.cpp b/wpb_home_tutorials/src/wpb_home_sr_xfyun.cpp new file mode 100644 index 0000000..cd589c0 --- /dev/null +++ b/wpb_home_tutorials/src/wpb_home_sr_xfyun.cpp @@ -0,0 +1,72 @@ +/********************************************************************* +* Software License Agreement (BSD License) +* +* Copyright (c) 2017-2020, Waterplus http://www.6-robot.com +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of the WaterPlus nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* FOOTPRINTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*********************************************************************/ +/*!****************************************************************** + @author ZhangWanjie + ********************************************************************/ + +#include +#include + +static ros::Publisher spk_pub; +static std_msgs::String strSpeak; + +void KeywordCB(const std_msgs::String::ConstPtr & msg) +{ + //ROS_WARN("[KeywordCB] - %s",msg->data.c_str()); + int nFindIndex = 0; + nFindIndex = msg->data.find("你好"); + if( nFindIndex >= 0 ) + { + strSpeak.data = "很高兴认识你"; + spk_pub.publish(strSpeak); + } +} + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "wpb_home_sr_xfyun"); + + ros::NodeHandle n; + ros::Subscriber sub_sr = n.subscribe("/xfyun/iat", 10, KeywordCB); + spk_pub = n.advertise("/xfyun/tts", 10); + + ros::Rate r(10); + while(ros::ok()) + { + ros::spinOnce(); + r.sleep(); + } + + return 0; +} \ No newline at end of file