FP Perception 0.1.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
fp_perception::OpenAISpeechDriver Class Reference

#include <openai_driver.hpp>

Inheritance diagram for fp_perception::OpenAISpeechDriver:
Inheritance graph
[legend]
Collaboration diagram for fp_perception::OpenAISpeechDriver:
Collaboration graph
[legend]

Public Member Functions

 OpenAISpeechDriver ()
 Construct a new OpenAI Speech Driver object.
 
 ~OpenAISpeechDriver () override
 Destroy the OpenAI Speech Driver object.
 
void initialize (const rclcpp::Node::SharedPtr &node) override
 Initialize the driver.
 
void deinitialize () override
 Deinitialize the driver.
 
audio_data synthesize (const text_data &new_text) override
 
void test () override
 Test method for the driver.
 
- Public Member Functions inherited from fp_perception::RestBase
 RestBase ()
 Constructor.
 
virtual ~RestBase ()
 Destructor.
 
virtual void initialize_rest_base (const rclcpp::Node::SharedPtr &node, std::string plugin_name="RestBase", std::string api_key_name="")
 Initialize the REST base class.
 
virtual fp_perception::RESTResponse call (const fp_perception::RESTRequest &req)
 Request data from the REST API.
 
virtual fp_perception::RESTResponse call_audio (const fp_perception::RESTRequest &req)
 Request audio data from the REST API.
 
virtual fp_perception::RESTResponse call_tts (const fp_perception::RESTRequest &req)
 
- Public Member Functions inherited from fp_perception::DriverBase
virtual ~DriverBase ()=default
 
virtual std::string getName () const
 Get the name of the driver.
 
void check_directory (std::string folder_name)
 Check if the test directory exists, create it if not.
 
const std::filesystem::path check_file (const std::string &file_name)
 

Protected Member Functions

std::string resolve_voice (const text_data &new_text) const
 
std::string resolve_instructions (const text_data &new_text) const
 
fp_perception::RESTResponse synthesize_chunk (const std::string &chunk, const std::string &voice, const std::string &instructions)
 
std::vector< std::string > split_text_into_chunks (const std::string &text) const
 
virtual nlohmann::json toJson (const fp_perception::RESTRequest &request)
 Convert a prompt request to a JSON object.
 
virtual fp_perception::RESTResponse fromJson (const nlohmann::json &object)
 Convert a JSON object to a fp_perception response.
 
void produce_diagnostics (diagnostic_updater::DiagnosticStatusWrapper &status)
 
- Protected Member Functions inherited from fp_perception::RestBase
void apply_timeouts (CURL *curl)
 
void record_rest_result (bool success, long http_code, const std::string &error)
 
- Protected Member Functions inherited from fp_perception::DriverBase
void initialize_base (const rclcpp::Node::SharedPtr &node)
 Initializer base driver in place of constructor due to plugin semantics.
 
bool diagnostics_enabled () const
 
void enable_diagnostics (const std::string &hardware_id, const std::string &task_name, std::function< void(diagnostic_updater::DiagnosticStatusWrapper &)> task, std::chrono::milliseconds period=std::chrono::seconds(1))
 
void disable_diagnostics ()
 

Static Protected Member Functions

static std::string trim_copy (const std::string &text)
 
static size_t count_words (const std::string &text)
 
static std::vector< std::string > split_long_segment (const std::string &segment, size_t max_words)
 
- Static Protected Member Functions inherited from fp_perception::RestBase
static std::string build_http_error_message (long http_code, const std::string &response_data)
 
static size_t write_callback (void *contents, size_t size, size_t nmemb, std::string *userp)
 

Protected Attributes

std::string model_name_
 
std::string test_text_
 
std::string voice_
 
std::string instructions_
 
std::string test_file_path_ = "test_audio.wav"
 
bool chunking_enabled_ = true
 
size_t chunk_max_words_ = 200
 
size_t chunk_parallel_requests_ = 3
 
fp_perception::RESTResponse response_
 
audio_data last_audio_
 
- Protected Attributes inherited from fp_perception::RestBase
std::string plugin_name_
 
std::string uri_
 
std::string method_
 
bool ssl_verify_
 
std::string auth_type_
 
std::string api_key_
 
long timeout_sec_ { 60 }
 
long connect_timeout_sec_ { 10 }
 
std::atomic< uint64_t > rest_request_count_ { 0 }
 
std::atomic< uint64_t > rest_failure_count_ { 0 }
 
std::atomic< bool > last_rest_success_ { true }
 
std::atomic< long > last_rest_http_code_ { 0 }
 
std::mutex rest_status_mutex_
 
std::string last_rest_error_
 
- Protected Attributes inherited from fp_perception::DriverBase
rclcpp::Node::SharedPtr node_
 ROS node for the driver.
 
std::string name_
 Name of the driver.
 
std::mutex buffer_mutex_
 Mutex to protect access to the driver data.
 
std::condition_variable buffer_cv_
 Condition variable to notify when new data is available.
 
std::atomic< bool > is_running_ { false }
 Flag to indicate if the driver thread is running.
 
bool diagnostics_enabled_ { false }
 Flag to enable standard ROS diagnostics publishing.
 
std::unique_ptr< diagnostic_updater::Updater > diagnostics_updater_
 
rclcpp::TimerBase::SharedPtr diagnostics_timer_
 

Constructor & Destructor Documentation

◆ OpenAISpeechDriver()

fp_perception::OpenAISpeechDriver::OpenAISpeechDriver ( )
inline

Construct a new OpenAI Speech Driver object.

◆ ~OpenAISpeechDriver()

fp_perception::OpenAISpeechDriver::~OpenAISpeechDriver ( )
inlineoverride

Destroy the OpenAI Speech Driver object.

Member Function Documentation

◆ count_words()

static size_t fp_perception::OpenAISpeechDriver::count_words ( const std::string &  text)
inlinestaticprotected

◆ deinitialize()

void fp_perception::OpenAISpeechDriver::deinitialize ( )
inlineoverridevirtual

Deinitialize the driver.

Required by DriverBase. This driver holds no long-running resources beyond cached state and the ROS node pointer.

Implements fp_perception::DriverBase.

◆ fromJson()

virtual fp_perception::RESTResponse fp_perception::OpenAISpeechDriver::fromJson ( const nlohmann::json &  object)
inlineprotectedvirtual

Convert a JSON object to a fp_perception response.

This method converts a JSON object received from the fp_perception plugin into a fp_perception response. It extracts the relevant fields from the JSON object and returns a fp_perception response object.

Parameters
objectThe JSON object to convert
Returns
A fp_perception response object containing the response data

Implements fp_perception::RestBase.

◆ initialize()

void fp_perception::OpenAISpeechDriver::initialize ( const rclcpp::Node::SharedPtr &  node)
inlineoverridevirtual

Initialize the driver.

This function should be overridden in derived classes to provide specific initialization.

Parameters
nodeShared pointer to the ROS node

Reimplemented from fp_perception::DriverBase.

◆ produce_diagnostics()

void fp_perception::OpenAISpeechDriver::produce_diagnostics ( diagnostic_updater::DiagnosticStatusWrapper &  status)
inlineprotected

◆ resolve_instructions()

std::string fp_perception::OpenAISpeechDriver::resolve_instructions ( const text_data new_text) const
inlineprotected

◆ resolve_voice()

std::string fp_perception::OpenAISpeechDriver::resolve_voice ( const text_data new_text) const
inlineprotected

◆ split_long_segment()

static std::vector< std::string > fp_perception::OpenAISpeechDriver::split_long_segment ( const std::string &  segment,
size_t  max_words 
)
inlinestaticprotected

◆ split_text_into_chunks()

std::vector< std::string > fp_perception::OpenAISpeechDriver::split_text_into_chunks ( const std::string &  text) const
inlineprotected

◆ synthesize()

audio_data fp_perception::OpenAISpeechDriver::synthesize ( const text_data new_text)
inlineoverridevirtual

◆ synthesize_chunk()

fp_perception::RESTResponse fp_perception::OpenAISpeechDriver::synthesize_chunk ( const std::string &  chunk,
const std::string &  voice,
const std::string &  instructions 
)
inlineprotected

◆ test()

void fp_perception::OpenAISpeechDriver::test ( )
inlineoverridevirtual

Test method for the driver.

This function can be overridden in derived classes to implement specific test logic.

Reimplemented from fp_perception::DriverBase.

◆ toJson()

virtual nlohmann::json fp_perception::OpenAISpeechDriver::toJson ( const fp_perception::RESTRequest request)
inlineprotectedvirtual

Convert a prompt request to a JSON object.

This method converts the fp_perception request to a JSON object that can be sent to the fp_perception plugin. It includes the prompt text and options for the JSON object.

Parameters
promptThe fp_perception request to convert
Returns
A JSON object representing the prompt request

Implements fp_perception::RestBase.

◆ trim_copy()

static std::string fp_perception::OpenAISpeechDriver::trim_copy ( const std::string &  text)
inlinestaticprotected

Member Data Documentation

◆ chunk_max_words_

size_t fp_perception::OpenAISpeechDriver::chunk_max_words_ = 200
protected

◆ chunk_parallel_requests_

size_t fp_perception::OpenAISpeechDriver::chunk_parallel_requests_ = 3
protected

◆ chunking_enabled_

bool fp_perception::OpenAISpeechDriver::chunking_enabled_ = true
protected

◆ instructions_

std::string fp_perception::OpenAISpeechDriver::instructions_
protected

◆ last_audio_

audio_data fp_perception::OpenAISpeechDriver::last_audio_
protected

◆ model_name_

std::string fp_perception::OpenAISpeechDriver::model_name_
protected

◆ response_

fp_perception::RESTResponse fp_perception::OpenAISpeechDriver::response_
protected

◆ test_file_path_

std::string fp_perception::OpenAISpeechDriver::test_file_path_ = "test_audio.wav"
protected

◆ test_text_

std::string fp_perception::OpenAISpeechDriver::test_text_
protected

◆ voice_

std::string fp_perception::OpenAISpeechDriver::voice_
protected

The documentation for this class was generated from the following file: