Spaces:
Running
Running
add pauses and controls
Browse files- __pycache__/numToLez.cpython-310.pyc +0 -0
- app.py +60 -26
- numToLez.py +374 -0
__pycache__/numToLez.cpython-310.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
app.py
CHANGED
|
@@ -3,20 +3,7 @@ import numpy as np
|
|
| 3 |
from scipy.io.wavfile import write
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import VitsTokenizer, VitsModel, set_seed, pipeline
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
class CustomFlagging(gr.FlaggingCallback):
|
| 9 |
-
def setup(self, *args, **kwargs):
|
| 10 |
-
pass # Optional setup steps
|
| 11 |
-
|
| 12 |
-
def flag(self, flag_data, flag_option=None, username=None):
|
| 13 |
-
print(f"Аудио: {flag_data}, Сообщение: {flag_option}")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# Custom options
|
| 17 |
-
flagging_callback = CustomFlagging()
|
| 18 |
-
flagging_options = ["Хорошая озвучка", "Слышен механический треск", "Не совпадает произношение букв", 'Проглочены буквы'] # Customize options
|
| 19 |
-
|
| 20 |
|
| 21 |
# Load your fine-tuned model
|
| 22 |
model_name = "leks-forever/vits_lez_tts" # Replace with your Hugging Face model name
|
|
@@ -25,15 +12,33 @@ model = VitsModel.from_pretrained(model_name)
|
|
| 25 |
|
| 26 |
tts_pipeline = pipeline("text-to-speech", model=model_name)
|
| 27 |
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
speech = tts_pipeline(input_text)
|
| 32 |
set_seed(900)
|
| 33 |
|
| 34 |
# make speech faster and more noisy
|
| 35 |
-
model.speaking_rate =
|
| 36 |
-
model.noise_scale =
|
| 37 |
|
| 38 |
sampling_rate = speech["sampling_rate"]
|
| 39 |
|
|
@@ -46,13 +51,42 @@ def tts_function(input_text):
|
|
| 46 |
return tmpfile.name # Return the filepath
|
| 47 |
|
| 48 |
|
| 49 |
-
interface = gr.Interface(
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
)
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Launch the app
|
| 58 |
interface.launch()
|
|
|
|
| 3 |
from scipy.io.wavfile import write
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import VitsTokenizer, VitsModel, set_seed, pipeline
|
| 6 |
+
from numToLez import numToLez
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load your fine-tuned model
|
| 9 |
model_name = "leks-forever/vits_lez_tts" # Replace with your Hugging Face model name
|
|
|
|
| 12 |
|
| 13 |
tts_pipeline = pipeline("text-to-speech", model=model_name)
|
| 14 |
|
| 15 |
+
new_sentence = '!.?'
|
| 16 |
+
in_sentence = ',-.:;'
|
| 17 |
|
| 18 |
+
|
| 19 |
+
def canonize_lez(text):
|
| 20 |
+
for abruptive_letter in ['к', 'К', 'п', 'П', 'т', 'Т', 'ц', 'Ц', 'ч', 'Ч']:
|
| 21 |
+
for abruptive_symbol in ['1', 'l', 'i', 'I', '|', 'ӏ', 'Ӏ', 'ӏ']:
|
| 22 |
+
text = text.replace(abruptive_letter+abruptive_symbol, abruptive_letter+'Ӏ')
|
| 23 |
+
return text
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def tts_function(input_text, speaking_rate, noise_scale, add_pauses):
|
| 27 |
+
fixed_text = canonize_lez(input_text)
|
| 28 |
+
if add_pauses:
|
| 29 |
+
for symb in new_sentence:
|
| 30 |
+
fixed_text = fixed_text.replace(symb, ' ')
|
| 31 |
+
|
| 32 |
+
for symb in in_sentence:
|
| 33 |
+
fixed_text = fixed_text.replace(symb, ' ')
|
| 34 |
+
|
| 35 |
+
inputs = tokenizer(text=fixed_text, return_tensors="pt")
|
| 36 |
speech = tts_pipeline(input_text)
|
| 37 |
set_seed(900)
|
| 38 |
|
| 39 |
# make speech faster and more noisy
|
| 40 |
+
model.speaking_rate = speaking_rate
|
| 41 |
+
model.noise_scale = noise_scale
|
| 42 |
|
| 43 |
sampling_rate = speech["sampling_rate"]
|
| 44 |
|
|
|
|
| 51 |
return tmpfile.name # Return the filepath
|
| 52 |
|
| 53 |
|
| 54 |
+
# interface = gr.Interface(
|
| 55 |
+
# fn=tts_function,
|
| 56 |
+
# inputs=[
|
| 57 |
+
# gr.Textbox(label="Введите текст на лезгинском"),
|
| 58 |
+
# gr.Slider(label="Скорость речи", minimum=0, maximum=2, step=0.1, value=0.9),
|
| 59 |
+
# gr.Slider(label="Шум", minimum=0, maximum=5, step=0.1, value=0),
|
| 60 |
+
# gr.Checkbox(label="Сделать паузы длиннее", value=False),
|
| 61 |
+
# ],
|
| 62 |
+
# outputs=gr.Audio(label="Аудио"),
|
| 63 |
+
# title="Text-to-speech Лезги ЧIалал",
|
| 64 |
+
# submit_button=gr.Button("Сгенерировать"),
|
| 65 |
+
|
| 66 |
+
# flagging_mode="auto", # Enable the flagging button
|
| 67 |
+
# )
|
| 68 |
+
|
| 69 |
+
with gr.Blocks() as interface:
|
| 70 |
+
gr.Markdown("### Text-to-speech Лезги ЧIалал")
|
| 71 |
+
|
| 72 |
+
with gr.Row():
|
| 73 |
+
# Left Column: Inputs
|
| 74 |
+
with gr.Column():
|
| 75 |
+
input_text = gr.Textbox(label="Введите текст на лезгинском", elem_id="custom-input")
|
| 76 |
+
add_pauses = gr.Checkbox(label="Добавить больше пауз у знаков препинания", value=False)
|
| 77 |
+
speaking_rate = gr.Slider(label="Скорость речи (speaking_rate)", minimum=0, maximum=2, step=0.1, value=0.9)
|
| 78 |
+
noise_scale = gr.Slider(label="Шум (noise_scale)", minimum=0, maximum=5, step=0.1, value=0)
|
| 79 |
+
submit_button = gr.Button("Сгенерировать")
|
| 80 |
+
|
| 81 |
+
# Right Column: Output
|
| 82 |
+
with gr.Column():
|
| 83 |
+
output_audio = gr.Audio(label="Аудио")
|
| 84 |
+
|
| 85 |
+
# Link function to button
|
| 86 |
+
submit_button.click(
|
| 87 |
+
fn=tts_function,
|
| 88 |
+
inputs=[input_text, speaking_rate, noise_scale, add_pauses],
|
| 89 |
+
outputs=output_audio,
|
| 90 |
+
)
|
| 91 |
# Launch the app
|
| 92 |
interface.launch()
|
numToLez.py
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numToLez = '''(input_text) => {
|
| 2 |
+
const million = 1e6; // 10^6;
|
| 3 |
+
const billion = 1e9; // 10^9;
|
| 4 |
+
const trillion = 1e12; // 10^12;
|
| 5 |
+
const quadrillion = 1e15; // 10^15;
|
| 6 |
+
const quintillion = 1e18; // 10^18;
|
| 7 |
+
const sextillion = 1e21; // 10^21;
|
| 8 |
+
const septillion = 1e24; // 10^24;
|
| 9 |
+
const octillion = 1e27; // 10^27;
|
| 10 |
+
const nonillion = 1e30; // 10^30;
|
| 11 |
+
const atomic = {
|
| 12 |
+
0: 'нул',
|
| 13 |
+
1: 'сад',
|
| 14 |
+
2: 'кьвед',
|
| 15 |
+
3: 'пуд',
|
| 16 |
+
4: 'кьуд',
|
| 17 |
+
5: 'вад',
|
| 18 |
+
6: 'ругуд',
|
| 19 |
+
7: 'ирид',
|
| 20 |
+
8: 'муьжуьд',
|
| 21 |
+
9: 'кIуьд',
|
| 22 |
+
10: 'цIуд',
|
| 23 |
+
20: 'къад',
|
| 24 |
+
40: 'яхцIур',
|
| 25 |
+
// 10^2
|
| 26 |
+
100: 'виш',
|
| 27 |
+
// 10^3
|
| 28 |
+
1000: 'агъзур',
|
| 29 |
+
// 10^6
|
| 30 |
+
[million]: 'миллион',
|
| 31 |
+
// 10^9
|
| 32 |
+
[billion]: 'миллиард',
|
| 33 |
+
// 10^12
|
| 34 |
+
[trillion]: 'триллион',
|
| 35 |
+
// 10^15
|
| 36 |
+
[quadrillion]: 'квадриллион',
|
| 37 |
+
// 10^18
|
| 38 |
+
[quintillion]: 'квинтиллион',
|
| 39 |
+
// 10^21
|
| 40 |
+
[sextillion]: 'секстиллион',
|
| 41 |
+
// 10^24
|
| 42 |
+
[septillion]: 'септиллион',
|
| 43 |
+
// 10^27
|
| 44 |
+
[octillion]: 'октиллион',
|
| 45 |
+
// 10^30
|
| 46 |
+
[nonillion]: 'нониллион',
|
| 47 |
+
};
|
| 48 |
+
const MINUS = 'минус';
|
| 49 |
+
function separateNumberIntoUnits(n) {
|
| 50 |
+
if (n == 0)
|
| 51 |
+
return [0];
|
| 52 |
+
const arr = [];
|
| 53 |
+
let i = 1;
|
| 54 |
+
while (n > 0) {
|
| 55 |
+
arr.unshift((n % 10) * i);
|
| 56 |
+
n = Math.floor(n / 10);
|
| 57 |
+
i *= 10;
|
| 58 |
+
}
|
| 59 |
+
const result = groupNumberUnitsToLezgiRange(arr);
|
| 60 |
+
return result;
|
| 61 |
+
}
|
| 62 |
+
const ranges = [
|
| 63 |
+
{ start: nonillion, end: octillion }, // nonillion to octillion
|
| 64 |
+
{ start: octillion, end: septillion }, // octillion to septillion
|
| 65 |
+
{ start: septillion, end: sextillion }, // septillion to sextillion
|
| 66 |
+
{ start: sextillion, end: quintillion }, // sextillion to quintillion
|
| 67 |
+
{ start: quadrillion, end: quintillion }, // quadrillion to quintillion
|
| 68 |
+
{ start: trillion, end: quadrillion }, // trillion to quadrillion
|
| 69 |
+
{ start: billion, end: trillion }, // billion to trillion
|
| 70 |
+
{ start: million, end: billion }, // million to billion
|
| 71 |
+
{ start: 1000, end: million }, // thousand to million
|
| 72 |
+
];
|
| 73 |
+
function groupNumberUnitsToLezgiRange(arr) {
|
| 74 |
+
let result = [];
|
| 75 |
+
for (let range of ranges) {
|
| 76 |
+
let sum = arr.reduce((acc, num) => {
|
| 77 |
+
if (num >= range.start && num < range.end) {
|
| 78 |
+
return acc + num;
|
| 79 |
+
}
|
| 80 |
+
return acc;
|
| 81 |
+
}, 0);
|
| 82 |
+
if (sum !== 0) {
|
| 83 |
+
result.push(sum);
|
| 84 |
+
}
|
| 85 |
+
// Filter out the numbers that were added to sum
|
| 86 |
+
arr = arr.filter((num) => num < range.start || num >= range.end);
|
| 87 |
+
}
|
| 88 |
+
// Concatenate the remaining numbers to the result
|
| 89 |
+
result = result.concat(arr);
|
| 90 |
+
return result;
|
| 91 |
+
}
|
| 92 |
+
function getTenPlusBase(num) {
|
| 93 |
+
if (num < 10 || num >= 20) {
|
| 94 |
+
throw new Error('Invalid number');
|
| 95 |
+
}
|
| 96 |
+
if (num === 10) {
|
| 97 |
+
return [atomic[10]];
|
| 98 |
+
}
|
| 99 |
+
const base10 = atomic[10].slice(0, -2);
|
| 100 |
+
if (num === 11 || num === 15 || num === 16) {
|
| 101 |
+
return [base10 + 'у'];
|
| 102 |
+
}
|
| 103 |
+
else if (num < 15) {
|
| 104 |
+
return [base10 + 'и'];
|
| 105 |
+
}
|
| 106 |
+
return [base10 + 'е'];
|
| 107 |
+
}
|
| 108 |
+
function getTwentyPlusBase(num) {
|
| 109 |
+
return num === 20 ? [atomic[20]] : ['къанни'];
|
| 110 |
+
}
|
| 111 |
+
function getThirtyPlusBase(num) {
|
| 112 |
+
return [...getTwentyPlusBase(num), ...getTenPlusBase(num - 20)];
|
| 113 |
+
}
|
| 114 |
+
function getFourtyPlusBase(num) {
|
| 115 |
+
return num === 40 ? [atomic[40]] : [atomic[40], 'ни'];
|
| 116 |
+
}
|
| 117 |
+
function getFiftyPlusBase(num) {
|
| 118 |
+
return [...getFourtyPlusBase(num), ...getTenPlusBase(num - 40)];
|
| 119 |
+
}
|
| 120 |
+
function getSixtyPlusBase(num) {
|
| 121 |
+
return num === 60 ? [atomic[3], atomic[20]] : [atomic[3], ...getTwentyPlusBase(num)];
|
| 122 |
+
}
|
| 123 |
+
function getSeventyPlusBase(num) {
|
| 124 |
+
return [...getSixtyPlusBase(61), ...getTenPlusBase(num - 60)];
|
| 125 |
+
}
|
| 126 |
+
function getEightyPlusBase(num) {
|
| 127 |
+
return num === 80 ? [atomic[4], atomic[20]] : [atomic[4], ...getTwentyPlusBase(num)];
|
| 128 |
+
}
|
| 129 |
+
function getNinetyPlusBase(num) {
|
| 130 |
+
return [...getEightyPlusBase(81), ...getTenPlusBase(num - 80)];
|
| 131 |
+
}
|
| 132 |
+
function getHundredPlusBase(num) {
|
| 133 |
+
return num % 100 === 0 ? [atomic[100]] : [atomic[100], 'ни'];
|
| 134 |
+
}
|
| 135 |
+
function getHundredPlusNumCount(numCount) {
|
| 136 |
+
if (atomic[numCount] !== undefined) {
|
| 137 |
+
return numCount === 2 ? [atomic[numCount].slice(0, -1)] : [atomic[numCount]];
|
| 138 |
+
}
|
| 139 |
+
return undefined;
|
| 140 |
+
}
|
| 141 |
+
function getBetweenHundredAndThousand(num, followUpNumber) {
|
| 142 |
+
const hundredsCount = num % 100 != 0 ? num - (num % 100) : num / 100;
|
| 143 |
+
const hundredsCountInLezgi = getHundredPlusNumCount(hundredsCount);
|
| 144 |
+
return [...hundredsCountInLezgi, ' ', ...getHundredPlusBase(num + followUpNumber)];
|
| 145 |
+
}
|
| 146 |
+
function getThousandPlusBase(num) {
|
| 147 |
+
return num % 1000 === 0 ? [atomic[1000]] : [atomic[1000], 'ни'];
|
| 148 |
+
}
|
| 149 |
+
function getBetweenThousandAndMillion(num, followUpNumber) {
|
| 150 |
+
var _a;
|
| 151 |
+
const thousandsCount = num % 1000 != 0 ? num - (num % 1000) : num / 1000;
|
| 152 |
+
const thousandsCountInLezgi = (_a = getHundredPlusNumCount(thousandsCount)) !== null && _a !== void 0 ? _a : getCompound(thousandsCount);
|
| 153 |
+
return [...thousandsCountInLezgi, ' ', ...getThousandPlusBase(num + followUpNumber)];
|
| 154 |
+
}
|
| 155 |
+
function getMillionPlusBase(num) {
|
| 156 |
+
return num % million === 0 ? [atomic[million]] : [atomic[million], 'ни'];
|
| 157 |
+
}
|
| 158 |
+
function getBetweenMillionAndBillion(num, followUpNumber) {
|
| 159 |
+
var _a;
|
| 160 |
+
const millionsCount = num % million != 0 ? num - (num % million) : num / million;
|
| 161 |
+
const millionsCountInLezgi = (_a = getHundredPlusNumCount(millionsCount)) !== null && _a !== void 0 ? _a : getCompound(millionsCount);
|
| 162 |
+
return [...millionsCountInLezgi, ' ', ...getMillionPlusBase(num + followUpNumber)];
|
| 163 |
+
}
|
| 164 |
+
function getBillionPlusBase(num) {
|
| 165 |
+
return num % billion === 0 ? [atomic[billion]] : [atomic[billion], 'ни'];
|
| 166 |
+
}
|
| 167 |
+
function getBetweenBillionAndTrillion(num, followUpNumber) {
|
| 168 |
+
var _a;
|
| 169 |
+
const billionsCount = num % billion != 0 ? num - (num % billion) : num / billion;
|
| 170 |
+
const billionsCountInLezgi = (_a = getHundredPlusNumCount(billionsCount)) !== null && _a !== void 0 ? _a : getCompound(billionsCount);
|
| 171 |
+
return [...billionsCountInLezgi, ' ', ...getBillionPlusBase(num + followUpNumber)];
|
| 172 |
+
}
|
| 173 |
+
function getTrillionPlusBase(num) {
|
| 174 |
+
return num % trillion === 0 ? [atomic[trillion]] : [atomic[trillion], 'ни'];
|
| 175 |
+
}
|
| 176 |
+
function getBetweenTrillionAndQuadrillion(num, followUpNumber) {
|
| 177 |
+
var _a;
|
| 178 |
+
const trillionsCount = num % trillion != 0 ? num - (num % trillion) : num / trillion;
|
| 179 |
+
const trillionsCountInLezgi = (_a = getHundredPlusNumCount(trillionsCount)) !== null && _a !== void 0 ? _a : getCompound(trillionsCount);
|
| 180 |
+
return [...trillionsCountInLezgi, ' ', ...getTrillionPlusBase(num + followUpNumber)];
|
| 181 |
+
}
|
| 182 |
+
function getQuadrillionPlusBase(num) {
|
| 183 |
+
return num % quadrillion === 0 ? [atomic[quadrillion]] : [atomic[quadrillion], 'ни'];
|
| 184 |
+
}
|
| 185 |
+
function getBetweenQuadrillionAndQuintillion(num, followUpNumber) {
|
| 186 |
+
var _a;
|
| 187 |
+
const quadrillionsCount = num % quadrillion != 0 ? num - (num % quadrillion) : num / quadrillion;
|
| 188 |
+
const quadrillionsCountInLezgi = (_a = getHundredPlusNumCount(quadrillionsCount)) !== null && _a !== void 0 ? _a : getCompound(quadrillionsCount);
|
| 189 |
+
return [...quadrillionsCountInLezgi, ' ', ...getQuadrillionPlusBase(num + followUpNumber)];
|
| 190 |
+
}
|
| 191 |
+
function getQuintillionPlusBase(num) {
|
| 192 |
+
return num % quintillion === 0 ? [atomic[quintillion]] : [atomic[quintillion], 'ни'];
|
| 193 |
+
}
|
| 194 |
+
function getBetweenQuintillionAndSextillion(num, followUpNumber) {
|
| 195 |
+
var _a;
|
| 196 |
+
const quintillionsCount = num % quintillion != 0 ? num - (num % quintillion) : num / quintillion;
|
| 197 |
+
const quintillionsCountInLezgi = (_a = getHundredPlusNumCount(quintillionsCount)) !== null && _a !== void 0 ? _a : getCompound(quintillionsCount);
|
| 198 |
+
return [...quintillionsCountInLezgi, ' ', ...getQuintillionPlusBase(num + followUpNumber)];
|
| 199 |
+
}
|
| 200 |
+
function getSextillionPlusBase(num) {
|
| 201 |
+
return num % sextillion === 0 ? [atomic[sextillion]] : [atomic[sextillion], 'ни'];
|
| 202 |
+
}
|
| 203 |
+
function getBetweenSextillionAndSeptillion(num, followUpNumber) {
|
| 204 |
+
var _a;
|
| 205 |
+
const sextillionsCount = num % sextillion != 0 ? num - (num % sextillion) : num / sextillion;
|
| 206 |
+
const sextillionsCountInLezgi = (_a = getHundredPlusNumCount(sextillionsCount)) !== null && _a !== void 0 ? _a : getCompound(sextillionsCount);
|
| 207 |
+
return [...sextillionsCountInLezgi, ' ', ...getSextillionPlusBase(num + followUpNumber)];
|
| 208 |
+
}
|
| 209 |
+
function getSeptillionPlusBase(num) {
|
| 210 |
+
return num % septillion === 0 ? [atomic[septillion]] : [atomic[septillion], 'ни'];
|
| 211 |
+
}
|
| 212 |
+
function getBetweenSeptillionAndOctillion(num, followUpNumber) {
|
| 213 |
+
var _a;
|
| 214 |
+
const septillionsCount = num % septillion != 0 ? num - (num % septillion) : num / septillion;
|
| 215 |
+
const septillionsCountInLezgi = (_a = getHundredPlusNumCount(septillionsCount)) !== null && _a !== void 0 ? _a : getCompound(septillionsCount);
|
| 216 |
+
return [...septillionsCountInLezgi, ' ', ...getSeptillionPlusBase(num + followUpNumber)];
|
| 217 |
+
}
|
| 218 |
+
function getOctillionPlusBase(num) {
|
| 219 |
+
return num % octillion === 0 ? [atomic[octillion]] : [atomic[octillion], 'ни'];
|
| 220 |
+
}
|
| 221 |
+
function getBetweenOctillionAndNonillion(num, followUpNumber) {
|
| 222 |
+
var _a;
|
| 223 |
+
const octillionsCount = num % octillion != 0 ? num - (num % octillion) : num / octillion;
|
| 224 |
+
const octillionsCountInLezgi = (_a = getHundredPlusNumCount(octillionsCount)) !== null && _a !== void 0 ? _a : getCompound(octillionsCount);
|
| 225 |
+
return [...octillionsCountInLezgi, ' ', ...getOctillionPlusBase(num + followUpNumber)];
|
| 226 |
+
}
|
| 227 |
+
function getNonillionPlusBase(num) {
|
| 228 |
+
return num % nonillion === 0 ? [atomic[nonillion]] : [atomic[nonillion], 'ни'];
|
| 229 |
+
}
|
| 230 |
+
function getCompound(num) {
|
| 231 |
+
const units = separateNumberIntoUnits(num);
|
| 232 |
+
const result = units.map((unit, i) => {
|
| 233 |
+
if (i > 0 &&
|
| 234 |
+
unit === 7 &&
|
| 235 |
+
(units[i - 1] === 10 ||
|
| 236 |
+
units[i - 1] === 30 ||
|
| 237 |
+
units[i - 1] === 50 ||
|
| 238 |
+
units[i - 1] === 70 ||
|
| 239 |
+
units[i - 1] === 90)) {
|
| 240 |
+
return [atomic[7].slice(1)];
|
| 241 |
+
}
|
| 242 |
+
const followUpNumber = units.slice(i + 1).reduce((acc, num) => acc + num, 0);
|
| 243 |
+
if (unit === 10) {
|
| 244 |
+
return getTenPlusBase(unit + followUpNumber);
|
| 245 |
+
}
|
| 246 |
+
if (unit === 20) {
|
| 247 |
+
return getTwentyPlusBase(unit + followUpNumber);
|
| 248 |
+
}
|
| 249 |
+
if (unit === 30) {
|
| 250 |
+
return getThirtyPlusBase(unit + followUpNumber);
|
| 251 |
+
}
|
| 252 |
+
if (unit === 40) {
|
| 253 |
+
return getFourtyPlusBase(unit + followUpNumber);
|
| 254 |
+
}
|
| 255 |
+
if (unit === 50) {
|
| 256 |
+
return getFiftyPlusBase(unit + followUpNumber);
|
| 257 |
+
}
|
| 258 |
+
if (unit === 60) {
|
| 259 |
+
return getSixtyPlusBase(unit + followUpNumber);
|
| 260 |
+
}
|
| 261 |
+
if (unit === 70) {
|
| 262 |
+
return getSeventyPlusBase(unit + followUpNumber);
|
| 263 |
+
}
|
| 264 |
+
if (unit === 80) {
|
| 265 |
+
return getEightyPlusBase(unit + followUpNumber);
|
| 266 |
+
}
|
| 267 |
+
if (unit === 90) {
|
| 268 |
+
return getNinetyPlusBase(unit + followUpNumber);
|
| 269 |
+
}
|
| 270 |
+
if (unit === 100) {
|
| 271 |
+
return getHundredPlusBase(unit + followUpNumber);
|
| 272 |
+
}
|
| 273 |
+
if (unit > 100 && unit < 1000) {
|
| 274 |
+
return getBetweenHundredAndThousand(unit, followUpNumber);
|
| 275 |
+
}
|
| 276 |
+
if (unit === 1000) {
|
| 277 |
+
return getThousandPlusBase(unit + followUpNumber);
|
| 278 |
+
}
|
| 279 |
+
if (unit > 1000 && unit < million) {
|
| 280 |
+
return getBetweenThousandAndMillion(unit, followUpNumber);
|
| 281 |
+
}
|
| 282 |
+
if (unit === million) {
|
| 283 |
+
return getMillionPlusBase(unit + followUpNumber);
|
| 284 |
+
}
|
| 285 |
+
if (unit > million && unit < billion) {
|
| 286 |
+
return getBetweenMillionAndBillion(unit, followUpNumber);
|
| 287 |
+
}
|
| 288 |
+
if (unit === billion) {
|
| 289 |
+
return getBillionPlusBase(unit + followUpNumber);
|
| 290 |
+
}
|
| 291 |
+
if (unit > billion && unit < trillion) {
|
| 292 |
+
return getBetweenBillionAndTrillion(unit, followUpNumber);
|
| 293 |
+
}
|
| 294 |
+
if (unit === trillion) {
|
| 295 |
+
return getTrillionPlusBase(unit + followUpNumber);
|
| 296 |
+
}
|
| 297 |
+
if (unit > trillion && unit < quadrillion) {
|
| 298 |
+
return getBetweenTrillionAndQuadrillion(unit, followUpNumber);
|
| 299 |
+
}
|
| 300 |
+
if (unit === quadrillion) {
|
| 301 |
+
return getQuadrillionPlusBase(unit + followUpNumber);
|
| 302 |
+
}
|
| 303 |
+
if (unit > quadrillion && unit < quintillion) {
|
| 304 |
+
return getBetweenQuadrillionAndQuintillion(unit, followUpNumber);
|
| 305 |
+
}
|
| 306 |
+
if (unit === quintillion) {
|
| 307 |
+
return getQuintillionPlusBase(unit + followUpNumber);
|
| 308 |
+
}
|
| 309 |
+
if (unit > quintillion && unit < sextillion) {
|
| 310 |
+
return getBetweenQuintillionAndSextillion(unit, followUpNumber);
|
| 311 |
+
}
|
| 312 |
+
if (unit === sextillion) {
|
| 313 |
+
return getSextillionPlusBase(unit + followUpNumber);
|
| 314 |
+
}
|
| 315 |
+
if (unit > sextillion && unit < septillion) {
|
| 316 |
+
return getBetweenSextillionAndSeptillion(unit, followUpNumber);
|
| 317 |
+
}
|
| 318 |
+
if (unit === septillion) {
|
| 319 |
+
return getSeptillionPlusBase(unit + followUpNumber);
|
| 320 |
+
}
|
| 321 |
+
if (unit > septillion && unit < octillion) {
|
| 322 |
+
return getBetweenSeptillionAndOctillion(unit, followUpNumber);
|
| 323 |
+
}
|
| 324 |
+
if (unit === octillion) {
|
| 325 |
+
return getOctillionPlusBase(unit + followUpNumber);
|
| 326 |
+
}
|
| 327 |
+
if (unit > octillion && unit < nonillion) {
|
| 328 |
+
return getBetweenOctillionAndNonillion(unit, followUpNumber);
|
| 329 |
+
}
|
| 330 |
+
if (unit === nonillion) {
|
| 331 |
+
return getNonillionPlusBase(unit + followUpNumber);
|
| 332 |
+
}
|
| 333 |
+
return units.length > 1 && unit === 0 ? [''] : [atomic[unit] || unit.toString()];
|
| 334 |
+
});
|
| 335 |
+
return result.flat(); //.join('').replaceAll(' ', ' ').trim();
|
| 336 |
+
}
|
| 337 |
+
function getAtomicOrCompound(num) {
|
| 338 |
+
if (atomic[num]) {
|
| 339 |
+
return [atomic[num]];
|
| 340 |
+
}
|
| 341 |
+
else {
|
| 342 |
+
return getCompound(num);
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
function numToLezgiArray(num) {
|
| 346 |
+
if (isNaN(num)) {
|
| 347 |
+
throw new Error('Provided value is not a number');
|
| 348 |
+
}
|
| 349 |
+
if (!Number.isInteger(num)) {
|
| 350 |
+
throw new Error('Provided number is not an integer. Currently only integers are supported!');
|
| 351 |
+
}
|
| 352 |
+
const isNegative = num < 0;
|
| 353 |
+
num = Math.abs(num);
|
| 354 |
+
const result = getAtomicOrCompound(num)
|
| 355 |
+
.filter((word) => word !== '')
|
| 356 |
+
.map((word) => (word.endsWith('ни') ? [word, ' '] : word))
|
| 357 |
+
.flat();
|
| 358 |
+
return isNegative ? [MINUS, ' ', ...result] : result;
|
| 359 |
+
}
|
| 360 |
+
function numToLezgi(num) {
|
| 361 |
+
const resultArray = numToLezgiArray(num);
|
| 362 |
+
return (resultArray
|
| 363 |
+
// .map((word) => (word.endsWith('ни') || word === MINUS ? word + ' ' : word))
|
| 364 |
+
.join('')
|
| 365 |
+
.replaceAll(' ', ' ')
|
| 366 |
+
.trim());
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
function replaceNumbersWithWords(inputString) {
|
| 370 |
+
return inputString.replaceAll(/\d+/g, (num) => numToLezgi(parseInt(num, 10)));
|
| 371 |
+
}
|
| 372 |
+
console.log(replaceNumbersWithWords(input_text))
|
| 373 |
+
return replaceNumbersWithWords(input_text)
|
| 374 |
+
}'''
|