whisper_ros: whisper.cpp for ROS 2
Loading...
Searching...
No Matches
whisper_server_node.hpp
Go to the documentation of this file.
1// MIT License
2
3// Copyright (c) 2024 Miguel Ángel González Santamarta
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef WHISPER_SERVER_NODE_HPP
24#define WHISPER_SERVER_NODE_HPP
25
26#include <condition_variable>
27#include <memory>
28#include <mutex>
29
30#include <rclcpp_action/rclcpp_action.hpp>
31#include <std_msgs/msg/float32_multi_array.hpp>
32#include <std_srvs/srv/set_bool.hpp>
33
34#include "whisper_msgs/action/stt.hpp"
35#include "whisper_msgs/msg/transcription.hpp"
37
38namespace whisper_ros {
39
41
42 using STT = whisper_msgs::action::STT;
43 using GoalHandleSTT = rclcpp_action::ServerGoalHandle<STT>;
44
45public:
47
50
51protected:
52 void enable_silero(bool enable);
53
54private:
55 whisper_msgs::msg::Transcription transcription_msg;
57 std::condition_variable transcription_cond;
58
59 std::shared_ptr<GoalHandleSTT> goal_handle_;
60 rclcpp::Subscription<std_msgs::msg::Float32MultiArray>::SharedPtr
62 rclcpp::Client<std_srvs::srv::SetBool>::SharedPtr enable_silero_client_;
63 rclcpp_action::Server<STT>::SharedPtr action_server_;
64
65 void vad_callback(const std_msgs::msg::Float32MultiArray::SharedPtr msg);
66 void execute(const std::shared_ptr<GoalHandleSTT> goal_handle);
67 rclcpp_action::GoalResponse
68 handle_goal(const rclcpp_action::GoalUUID &uuid,
69 std::shared_ptr<const STT::Goal> goal);
70 rclcpp_action::CancelResponse
71 handle_cancel(const std::shared_ptr<GoalHandleSTT> goal_handle);
72 void handle_accepted(const std::shared_ptr<GoalHandleSTT> goal_handle);
73};
74
75} // namespace whisper_ros
76
77#endif
Definition whisper_base_node.hpp:38
Definition whisper_server_node.hpp:40
rclcpp_action::CancelResponse handle_cancel(const std::shared_ptr< GoalHandleSTT > goal_handle)
Definition whisper_server_node.cpp:96
rclcpp_action::Server< STT >::SharedPtr action_server_
Definition whisper_server_node.hpp:63
void deactivate_ros_interfaces()
Definition whisper_server_node.cpp:52
rclcpp_action::GoalResponse handle_goal(const rclcpp_action::GoalUUID &uuid, std::shared_ptr< const STT::Goal > goal)
Definition whisper_server_node.cpp:84
void handle_accepted(const std::shared_ptr< GoalHandleSTT > goal_handle)
Definition whisper_server_node.cpp:107
whisper_msgs::msg::Transcription transcription_msg
Definition whisper_server_node.hpp:55
void enable_silero(bool enable)
Definition whisper_server_node.cpp:64
whisper_msgs::action::STT STT
Definition whisper_server_node.hpp:42
void execute(const std::shared_ptr< GoalHandleSTT > goal_handle)
Definition whisper_server_node.cpp:114
void vad_callback(const std_msgs::msg::Float32MultiArray::SharedPtr msg)
Definition whisper_server_node.cpp:73
std::mutex transcription_mutex
Definition whisper_server_node.hpp:56
rclcpp_action::ServerGoalHandle< STT > GoalHandleSTT
Definition whisper_server_node.hpp:43
std::shared_ptr< GoalHandleSTT > goal_handle_
Definition whisper_server_node.hpp:59
std::condition_variable transcription_cond
Definition whisper_server_node.hpp:57
rclcpp::Subscription< std_msgs::msg::Float32MultiArray >::SharedPtr subscription_
Definition whisper_server_node.hpp:61
rclcpp::Client< std_srvs::srv::SetBool >::SharedPtr enable_silero_client_
Definition whisper_server_node.hpp:62
WhisperServerNode()
Definition whisper_server_node.cpp:33
void activate_ros_interfaces()
Definition whisper_server_node.cpp:37
Definition whisper.hpp:45