28 m_wparams.language=m_language.c_str();
44 if (config.
check(
"threads",
"number of threads")){
45 m_wparams.n_threads = config.
find(
"threads").asInt16();}
46 if (config.
check(
"processors",
"number of processors")){
47 m_wparams.n_threads = config.
find(
"processors").asInt16();}
48 if (config.
check(
"initial_prompt")) {
49 m_wparams.initial_prompt = config.
find(
"initial_prompt").asString().c_str();}
50 if (config.
check(
"duration",
"duration of audio to process in milliseconds")) {
51 m_wparams.duration_ms = config.
find(
"duration").asInt32();}
52 if (config.
check(
"offset_ms")) {
53 m_wparams.offset_ms = config.
find(
"offset_ms").asInt32();}
56 if (config.
check(
"thold_pt",
"word timestamp probability threshold")) {
57 m_wparams.thold_pt = config.
find(
"thold_pt").asFloat32();}
58 if (config.
check(
"entropy_thold",
"entropy threshold for decoder fail")) {
59 m_wparams.entropy_thold = config.
find(
"entropy_thold").asFloat32();}
60 if (config.
check(
"logprob_thold",
"log probability threshold for decoder fail")) {
61 m_wparams.logprob_thold = config.
find(
"logprob_thold").asFloat32();}
62 if (config.
check(
"print_timestamps",
"print_timestamps")) {
63 m_wparams.logprob_thold = config.
find(
"print_timestamps").asFloat32();}
64 if (config.
check(
"model",
"file containing the model")) {
65 m_model = config.
find(
"model").asString();}
66 if (config.
check(
"translate",
"translate from source language to English")) {
67 m_wparams.translate = config.
find(
"translate").asBool();}
70 if(config.
check(
"print_realtime",
"print_realtime")) {
71 m_wparams.print_realtime = config.
find(
"print_realtime").asBool();}
72 if(config.
check(
"print_progress",
"print_progress")) {
73 m_wparams.print_progress = config.
find(
"print_progress").asBool();}
74 if (config.
check(
"split_on_word",
"split on word rather than on token")) {
75 m_wparams.split_on_word = config.
find(
"split_on_word").asBool();}
76 if (config.
check(
"best_of",
"number of best candidates to keep")) {
77 m_wparams.greedy.best_of = config.
find(
"best_of").asInt32();}
78 if (config.
check(
"detect-language",
"exit after automatically detecting language")) {
79 m_wparams.detect_language = config.
find(
"detect-language").asBool();}
80 if (config.
check(
"beam_size",
" beam size for beam search")) {
81 m_wparams.beam_search.beam_size = config.
find(
"beam_size").asInt32();
87 if (config.
check(
"max-context",
"maximum number of text context tokens to store")) {
89 if (config.
check(
"max-len",
"maximum segment length in characters")) {
91 if (config.
check(
"no-fallback",
"do not use temperature fallback while decoding")) {
95 m_wparams.token_timestamps =
false ||
max_len > 0;
97 m_wparams.temperature_inc =
no_fallback ? 0.0f : m_wparams.temperature_inc;
104 m_wparams.language = config.
find(
"language").asString().c_str();
107 std::string model_path;
120 if (m_ctx ==
nullptr)
136 if (m_wparams.language !=
"en" || m_wparams.translate)
138 m_wparams.language =
"en";
139 m_wparams.translate =
false;
143 if (m_wparams.detect_language)
145 m_wparams.language =
"auto";
147 yCDebug(
WHISPER_SPEECHTR,
"%s: processing (%d samples, %.1f sec), %d threads, %d processors, lang = %s, task = %s, timestamps = %d ...\n",
149 m_wparams.n_threads, n_processors,
151 m_wparams.translate ?
"translate" :
"transcribe",
152 m_wparams.print_timestamps);
176 language = m_language;
191 return ReturnValue::return_code::return_value_error_method_failed;
196 m_pcmf32.resize(1000);
201 for (
size_t i = 0; i < m_pcmf32.size(); i++)
203 m_pcmf32[i]=
float(sound.
get(i, channel))/65535.0;
213 return ReturnValue::return_code::return_value_error_method_failed;
222 transcription += std::string(text);
230 std::regex
pattern1(
"\\[[^\\]]*\\]");
231 std::string input = transcription;
232 transcription = std::regex_replace(input,
pattern1,
"");
237 if (transcription.empty()) {score = 0.0;}
std::string m_model_context
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
virtual ~WhisperSpeechTranscription()
WhisperSpeechTranscription()
virtual yarp::dev::ReturnValue setLanguage(const std::string &language) override
Sets the language for speech transcription.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
virtual yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current language set for speech transcription.
virtual yarp::dev::ReturnValue transcribe(const yarp::sig::Sound &sound, std::string &transcription, double &score) override
Performs the speech transcription.
A mini-server for performing network communication in the background.
Helper class for finding config files and other external resources.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
size_t getChannels() const
Get the number of channels of the sound.
audio_sample get(size_t sample, size_t channel=0) const
size_t getSamples() const
Get the number of samples contained in the sound.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.