From 2a47d198e0c8b3ede0f6f6094ef53f4df7f90da1 Mon Sep 17 00:00:00 2001 From: BennyR Date: Fri, 9 May 2014 11:01:54 +0200 Subject: [PATCH] Added startup sentence option. --- cerevoice_tts/launch/tts.launch | 1 + cerevoice_tts/src/cerevoice_tts_node.cpp | 36 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/cerevoice_tts/launch/tts.launch b/cerevoice_tts/launch/tts.launch index 027282c..3f55b5e 100644 --- a/cerevoice_tts/launch/tts.launch +++ b/cerevoice_tts/launch/tts.launch @@ -1,5 +1,6 @@ + - path: $(env HOME)/cerevoice_sdk/voices/cerevoice_alex_3.0.6_22k.voice license: $(env HOME)/cerevoice_sdk/voices/license.lic diff --git a/cerevoice_tts/src/cerevoice_tts_node.cpp b/cerevoice_tts/src/cerevoice_tts_node.cpp index 49698af..994a51c 100644 --- a/cerevoice_tts/src/cerevoice_tts_node.cpp +++ b/cerevoice_tts/src/cerevoice_tts_node.cpp @@ -36,7 +36,10 @@ #include "ros/ros.h" +#include + #include "cerevoice_tts/CerevoiceTts.h" +#include "cerevoice_tts_msgs/TtsAction.h" int main(int argc, char **argv) { @@ -48,6 +51,39 @@ int main(int argc, char **argv) if(!initialized) return EXIT_FAILURE; + ros::spinOnce(); + + ros::NodeHandle private_node_handle("~"); + std::string startup_sentence; + private_node_handle.param("startup_sentence", startup_sentence, std::string("")); + + if(!startup_sentence.empty()) + { + ROS_INFO("Will now say the startup sentence '%s'", startup_sentence.c_str()); + ROS_INFO("Will wait for server"); + + // Output this startup sentence + actionlib::SimpleActionClient action_client("TTS", true); + while(!action_client.isServerConnected()) + { + ros::spinOnce(); // this looped spinning is required because we call an action from within the same node + } + + ROS_INFO("Server ready"); + + cerevoice_tts_msgs::TtsGoal goal; + goal.text = startup_sentence; + + action_client.sendGoal(goal); + while(!action_client.waitForResult(ros::Duration(0.0001))) + { + ros::spinOnce(); + } + + if(action_client.getState() != actionlib::SimpleClientGoalState::SUCCEEDED) + ROS_ERROR("Synthesizing the startup sentence failed!"); + } + ros::spin(); return EXIT_SUCCESS;