.. _program_listing_file_include_hri_voice.hpp: Program Listing for File voice.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/hri/voice.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright (c) 2023 PAL Robotics S.L. All rights reserved. // // 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 HRI__VOICE_HPP_ #define HRI__VOICE_HPP_ #include #include #include #include #include "hri_msgs/msg/live_speech.hpp" #include "std_msgs/msg/bool.hpp" #include "tf2_ros/buffer.h" #include "hri/feature_tracker.hpp" #include "hri/types.hpp" namespace hri { class Voice : public FeatureTracker, public std::enable_shared_from_this // TODO(LJU): possibly subscribe also to the /audio and the /features sub-topics { friend class HRIListener; // for invalidate() public: Voice( ID id, NodeInterfaces node_interfaces, rclcpp::CallbackGroup::SharedPtr callback_group, const tf2::BufferCore & tf_buffer, const std::string & reference_frame); virtual ~Voice(); std::optional isSpeaking() const {return is_speaking_;} std::optional speech() const {return speech_;} std::optional incrementalSpeech() const {return incremental_speech_;} std::optional locale() const {return locale_;} void onSpeaking(std::function callback) { is_speaking_callbacks_.push_back(callback); } void onSpeech(std::function callback) { speech_callbacks_.push_back(callback); } void onSpeech(std::function callback) { speech_callbacks_.push_back( [callback](const std::string & text, const std::string &) {callback(text);}); } void onIncrementalSpeech(std::function callback) { incremental_speech_callbacks_.push_back(callback); } void onIncrementalSpeech(std::function callback) { incremental_speech_callbacks_.push_back( [callback](const std::string & text, const std::string &) {callback(text);}); } private: void onSpeech_(hri_msgs::msg::LiveSpeech::ConstSharedPtr msg); void onIsSpeaking(std_msgs::msg::Bool::ConstSharedPtr msg); void invalidate(); std::optional is_speaking_; std::optional speech_; std::optional incremental_speech_; std::optional locale_; std::vector> is_speaking_callbacks_; std::vector> speech_callbacks_; std::vector> incremental_speech_callbacks_; rclcpp::Subscription::SharedPtr is_speaking_subscriber_; rclcpp::Subscription::SharedPtr speech_subscriber_; }; typedef std::shared_ptr VoicePtr; typedef std::shared_ptr ConstVoicePtr; } // namespace hri #endif // HRI__VOICE_HPP_