From 5530f0bb434a1d0c3b60f054026e6f03265b3a7a Mon Sep 17 00:00:00 2001 From: jieshoudaxue <1641395022@qq.com> Date: Tue, 10 Oct 2023 15:05:59 +0800 Subject: [PATCH] [fix] up it --- robot_voice/src/robot_controller.cpp | 15 +++++++++------ robot_voice/src/voice_detector.cpp | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/robot_voice/src/robot_controller.cpp b/robot_voice/src/robot_controller.cpp index a650520..61e0b17 100644 --- a/robot_voice/src/robot_controller.cpp +++ b/robot_voice/src/robot_controller.cpp @@ -33,18 +33,21 @@ public: bool ok = client_.call(req, resp); if (ok) { - printf("send str2voice service success: %s\n", req.data.c_str()); - geometry_msgs::Twist msg; - msg.linear.x = linear_x; - msg.angular.z = angular_z; - cmd_pub_.publish(msg); + printf("send str2voice service success: %s, and pub cmd_vel\n", req.data.c_str()); + for (int i = 0; i < 10; i ++) { + geometry_msgs::Twist msg; + msg.linear.x = linear_x; + msg.angular.z = angular_z; + cmd_pub_.publish(msg); + sleep(0.5); + } } else { ROS_ERROR("failed to send str2voice service"); } } void ChatterCallbback(const std_msgs::String::ConstPtr &msg) { - ROS_INFO("i received: %s", msg->data.c_str()); + printf("i received: %s\n", msg->data.c_str()); int ret = -1; std::string voice_txt = msg->data; diff --git a/robot_voice/src/voice_detector.cpp b/robot_voice/src/voice_detector.cpp index 3b0f76f..a3ffc72 100644 --- a/robot_voice/src/voice_detector.cpp +++ b/robot_voice/src/voice_detector.cpp @@ -57,7 +57,7 @@ public: static void InitSpeech() { VoiceDetector::voice_txt_ = ""; - printf("Start Listening...\n"); + printf("clear cache, start Listening...\n"); } static void EndSpeech(int reason) { @@ -92,7 +92,7 @@ public: } /* demo 15 seconds recording */ - sleep(15); + sleep(10); ret = sr_stop_listening(&iat); if (ret) { @@ -148,6 +148,7 @@ int main(int argc, char* argv[]) { std::string voice_txt = VoiceDetector::get_voice_txt_(); if (voice_txt == "") { + printf("voice_txt is empty\n"); continue; } else if (voice_txt.find("结束") != std::string::npos) { break; @@ -156,6 +157,8 @@ int main(int argc, char* argv[]) { std_msgs::String msg; msg.data = voice_txt; str_pub_.publish(msg); + + sleep(10); } ros::spin();