Skip to content

Commit

Permalink
hacky
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed Jul 30, 2024
1 parent 4d91f9e commit b5e4ca3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 94 deletions.
2 changes: 1 addition & 1 deletion example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
int main() {
babylon_g2p_init("./models/deep_phonemizer.onnx", "en_us", 1);

const char* text = "Hello world. There is 316 characters in this sentence. This is an example program for the Babylon project. Text to speech models can be used to generate speech from text. This is a very powerful tool for many applications. For example, it can be used to generate speech for virtual assistants, audiobooks, and more.";
const char* text = "Hello world. There is 317 characters in this sentence. This is an example program for the Babylon project. Text to speech models can be used to generate speech from text. This is a very powerful tool for many applications. For example, it can be used to generate speech for virtual assistants, audiobooks, and more.";

babylon_tts_init("./models/curie.onnx");

Expand Down
97 changes: 4 additions & 93 deletions src/numbers_to_words.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <vector>
#include <iostream>

std::string number_to_word(int number) {
switch (number) {
Expand Down Expand Up @@ -28,102 +29,12 @@ std::string number_to_word(int number) {
}
}

std::string length_to_word(int length) {
switch (length) {
case 0:
return "";
case 1:
return "";
case 2:
return "";
case 3:
return "hundred";
case 4:
return "thousand";
case 5:
return "thousand";
case 6:
return "hundred thousand";
case 7:
return "million";
case 8:
return "million";
case 9:
return "hundred million";
case 10:
return "billion";
case 11:
return "billion";
case 12:
return "hundred billion";
case 13:
return "trillion";
case 14:
return "trillion";
case 15:
return "hundred trillion";
case 16:
return "quadrillion";
case 17:
return "quadrillion";
case 18:
return "hundred quadrillion";
case 19:
return "quintillion";
case 20:
return "quintillion";
}
}

std::string tens_to_word(int tens) {
switch (tens) {
case 0:
return "";
case 1:
return "ten";
case 2:
return "twenty";
case 3:
return "thirty";
case 4:
return "forty";
case 5:
return "fifty";
case 6:
return "sixty";
case 7:
return "seventy";
case 8:
return "eighty";
case 9:
return "ninety";
}
}

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

if (text.length() > 20) {
for (int i = 0; i < text.length(); i++) {
result.push_back(number_to_word(text[i] - '0'));
}
}
else {
for (int i = 0; i < text.length(); i++) {
int position = text.length() - i - 1;

if (position < 2) {
result.push_back(number_to_word(text[i] - '0'));
}
else if (position == 2 || position == 5 || position == 8 || position == 11 || position == 14 || position == 17) {
result.push_back(tens_to_word(text[i] - '0'));
result.push_back(length_to_word(position));
}
else {
result.push_back(number_to_word(text[i] - '0'));
result.push_back(length_to_word(position));
}
}
for (int i = 0; i < text.length(); i++) {
result.push_back(number_to_word(text[i] - '0'));
std::cout << number_to_word(text[i] - '0') << std::endl;
}

return result;
Expand Down

0 comments on commit b5e4ca3

Please sign in to comment.