6 #include "gcloud_speech_msgs/SpeechToTextAction.h" 7 #include "gcloud_speech_msgs/RecognitionHypothesis.h" 8 #include "gcloud_speech_msgs/LinearPcm16Le16000Audio.h" 17 namespace speech = ::cogrob::cloud::speech;
19 using gcloud_speech_msgs::LinearPcm16Le16000Audio;
23 int main(
int argc,
char* argv[]) {
24 google::InitGoogleLogging(argv[0]);
25 gflags::ParseCommandLineFlags(&argc, &argv,
true);
29 ros::init(argc, argv,
"gcloud_speech_action_server");
32 std::mutex action_handler_mutex;
33 std::unique_ptr<gcloud_speech::SpeechToTextActionHandler> action_handler;
35 std::unique_ptr<speech::GoogleSpeechRecognizerInterface> recognizer(
38 std::function<void (const SpeechToTextSimpleActionServer::GoalConstPtr &)>
39 exec_callback = [&action_handler_mutex, &action_handler]
40 (
const SpeechToTextSimpleActionServer::GoalConstPtr& goal) {
41 std::lock_guard<std::mutex> lock(action_handler_mutex);
43 action_handler->ExecuteSpeechToTextAction(goal);
48 ros_node_handle,
"/cogrob/speech_to_text", exec_callback,
false);
52 std::lock_guard<std::mutex> lock(action_handler_mutex);
54 recognizer.get(), &action_server));
58 ros_node_handle.
subscribe<LinearPcm16Le16000Audio>(
59 "/cogrob/microphone_audio", 10,
60 [&action_handler] (
const LinearPcm16Le16000Audio::ConstPtr& msg) {
61 action_handler->AudioMsgCallback(msg);
64 action_server.
start();
65 LOG(INFO) <<
"SpeechToTextSimpleActionServer started.";
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char *argv[])
void PrepareGoogleCloudCredentials()