Skip to content

Commit

Permalink
added option remove_symbols (default true)
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Oct 19, 2023
1 parent 5ae67c8 commit c015357
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstdlib>
#include <algorithm>
#include <thread>
#include <regex>

using namespace yarp::os;
using namespace yarp::dev;
Expand Down Expand Up @@ -89,6 +90,8 @@ bool WhisperSpeechTranscription::open(yarp::os::Searchable& config)
max_len = config.find("max-len").asInt32();}
if (config.check("no-fallback", "do not use temperature fallback while decoding")) {
no_fallback = config.find("no-fallback").asBool();}
if (config.check("remove_symbols","remove [] symbols from the text transcript")) {
m_no_symbols = config.find("remove_symbols").asBool();}
m_wparams.n_max_text_ctx = max_context >= 0 ? max_context : m_wparams.n_max_text_ctx;
m_wparams.token_timestamps = false || max_len > 0;
m_wparams.max_len = false && max_len == 0 ? 60 : max_len;
Expand Down Expand Up @@ -213,6 +216,17 @@ bool WhisperSpeechTranscription::transcribe(const yarp::sig::Sound& sound, std::
yCDebug(WHISPER_SPEECHTR, text);
}
}

//remove symbols such as [bla bla]
if (m_no_symbols)
{
std::regex pattern1("\\[[^\\]]*\\]");
std::string input = transcription;
transcription = std::regex_replace(input, pattern1, "");
}

//assign the score
score = 1.0;
if (transcription.empty()) {score = 0.0;}
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ using namespace yarp::os;
* |:--------------:|:--------------:|:-------:|:--------------:|:----------------:|:-----------: |:-----------------------------------------------------------------:|:-----:|
* | model | - | string | - | - | Yes | Full path tot the model file, e.g. ggml-base.en.bin | |
* | language | - | string | - | auto | No | Language (??? TBC) | |
* | remove_symbols | - | bool | - | true | No | Removed symbols from output text, i.e. ...[bla bla]... | |
*/
class WhisperSpeechTranscription :
public yarp::dev::DeviceDriver,
public yarp::dev::ISpeechTranscription
{
private:
bool m_verbose = true;
bool m_no_symbols = true;
std::string m_language="auto";
std::string m_model;
std::vector<float> m_pcmf32; // mono-channel F32 PCM
Expand Down

0 comments on commit c015357

Please sign in to comment.