Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed Jul 30, 2024
1 parent 4114628 commit 9aa6193
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_library(
babylon
SHARED
src/babylon.cpp
src/cleaners.cpp
src/phonemizer.cpp
src/voice.cpp
)
Expand Down
2 changes: 2 additions & 0 deletions include/babylon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace DeepPhonemizer {

std::vector<std::string> g2p_internal(const std::string& text);
};

std::vector<std::string> numbers_to_words(const std::string& text);
}

namespace Vits {
Expand Down
52 changes: 27 additions & 25 deletions src/numbers_to_words.hpp → src/cleaners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,33 @@ std::string hundreds_to_words(int hundreds) {
return result;
}

std::vector<std::string> numbers_to_words(const std::string& text) {
std::vector<std::string> result;
std::vector<std::string> parts = split_into_threes(text);
std::vector<std::string> suffixes = {
"thousand",
"million",
"billion",
"trillion",
"quadrillion",
"quintillion",
"sextillion",
"septillion",
"octillion",
"nonillion",
"decillion"
};

for (int i = 0; i < parts.size(); i++) {
int number = std::stoi(parts[i]);
result.push_back(hundreds_to_words(number));

if (i > 0 && i < suffixes.size()) {
result.back() += " " + suffixes[i - 1];
namespace DeepPhonemizer {
std::vector<std::string> numbers_to_words(const std::string& text) {
std::vector<std::string> result;
std::vector<std::string> parts = split_into_threes(text);
std::vector<std::string> suffixes = {
"thousand",
"million",
"billion",
"trillion",
"quadrillion",
"quintillion",
"sextillion",
"septillion",
"octillion",
"nonillion",
"decillion"
};

for (int i = 0; i < parts.size(); i++) {
int number = std::stoi(parts[i]);
result.push_back(hundreds_to_words(number));

if (i > 0 && i < suffixes.size()) {
result.back() += " " + suffixes[i - 1];
}
}
}

return result;
return result;
}
}
1 change: 0 additions & 1 deletion src/phonemizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <sstream>
#include <algorithm>
#include <cmath>
#include "numbers_to_words.hpp"

namespace DeepPhonemizer {
SequenceTokenizer::SequenceTokenizer(const std::vector<std::string>& symbols, const std::vector<std::string>& languages, int char_repeats, bool lowercase, bool append_start_end)
Expand Down

0 comments on commit 9aa6193

Please sign in to comment.