whisper_ros: whisper.cpp for ROS 2
Loading...
Searching...
No Matches
whisper_base_node.hpp
Go to the documentation of this file.
1// MIT License
2
3// Copyright (c) 2023 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_BASE_NODE_HPP
24#define WHISPER_BASE_NODE_HPP
25
26#include <memory>
27#include <rclcpp/rclcpp.hpp>
28#include <rclcpp_lifecycle/lifecycle_node.hpp>
29
30#include "whisper_msgs/msg/transcription.hpp"
32
33namespace whisper_ros {
34
36 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
37
38class WhisperBaseNode : public rclcpp_lifecycle::LifecycleNode {
39
40public:
42
43 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
44 on_configure(const rclcpp_lifecycle::State &);
45 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
46 on_activate(const rclcpp_lifecycle::State &);
47 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
48 on_deactivate(const rclcpp_lifecycle::State &);
49 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
50 on_cleanup(const rclcpp_lifecycle::State &);
51 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
52 on_shutdown(const rclcpp_lifecycle::State &);
53
54 virtual void activate_ros_interfaces(){};
55 virtual void deactivate_ros_interfaces(){};
56
57protected:
58 std::string language;
59 std::shared_ptr<Whisper> whisper;
60
61 whisper_msgs::msg::Transcription transcribe(const std::vector<float> &audio);
62
63private:
64 std::string model;
67 struct whisper_context_params cparams = whisper_context_default_params();
68 struct whisper_full_params wparams;
69};
70
71} // namespace whisper_ros
72
73#endif
Definition whisper_base_node.hpp:38
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_configure(const rclcpp_lifecycle::State &)
Definition whisper_base_node.cpp:87
std::shared_ptr< Whisper > whisper
Definition whisper_base_node.hpp:59
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(const rclcpp_lifecycle::State &)
Definition whisper_base_node.cpp:211
WhisperBaseNode()
Definition whisper_base_node.cpp:32
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &)
Definition whisper_base_node.cpp:229
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &)
Definition whisper_base_node.cpp:245
struct whisper_full_params wparams
Definition whisper_base_node.hpp:68
std::string language
Definition whisper_base_node.hpp:58
whisper_msgs::msg::Transcription transcribe(const std::vector< float > &audio)
Definition whisper_base_node.cpp:265
struct whisper_context_params cparams
Definition whisper_base_node.hpp:67
int n_processors
Definition whisper_base_node.hpp:66
std::string model
Definition whisper_base_node.hpp:64
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &)
Definition whisper_base_node.cpp:255
virtual void deactivate_ros_interfaces()
Definition whisper_base_node.hpp:55
virtual void activate_ros_interfaces()
Definition whisper_base_node.hpp:54
std::string openvino_encode_device
Definition whisper_base_node.hpp:65
Definition whisper.hpp:45
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturn
Definition whisper_base_node.hpp:35