refractoring

This commit is contained in:
2025-03-04 14:01:29 +01:00
parent fc15604b8e
commit 0f0c8a1040
5 changed files with 12 additions and 9 deletions

View File

@@ -35,3 +35,5 @@ LANG_CONFIG = {
}
os.makedirs(ANNOUNCEMENT_DIR, exist_ok=True)
# TODO. use dataclasses from Multicaster with inherit

View File

@@ -9,17 +9,20 @@ from multilang_translator.utils.resample import resample_array
from multilang_translator.text_to_speech import encode_lc3
TTS_DIR = os.path.join(os.path.dirname(__file__))
PIPER_DIR = f'{TTS_DIR}/piper'
os.makedirs(PIPER_DIR, exist_ok=True)
def synth_piper(text, model="en_US-lessac-medium",):
pwd = os.getcwd()
os.chdir(TTS_DIR)
start = time.time()
ret = subprocess.run( # TODO: wrap this whole thing in a class and open a permanent pipe to the model
[config.PIPER_EXE_PATH,
'--cuda',
'--data-dir', PIPER_DIR,
'--download-dir', PIPER_DIR,
'--model', model,
'--output-raw'],
'--output-raw'
],
input=text.encode('utf-8'),
capture_output=True
)
@@ -30,15 +33,13 @@ def synth_piper(text, model="en_US-lessac-medium",):
log.info("Running piper for model %s took %s s", model, round(time.time() - start, 3))
with open (f'{model}.onnx.json') as f: # TODO: wrap everything into a class, store the json permanently
with open (f'{PIPER_DIR}/{model}.onnx.json') as f: # TODO: wrap everyth0ing into a class, store the json permanently
model_json = json.load(f)
os.chdir(pwd)
return model_json, audio
# TODO: framework should probably be a dataclass that holds all the relevant informations, also model
# TODO: make a common repo that hold the configuration dataclasses ?
def synthesize(text, target_sample_rate, framework, model="en_US-lessac-medium", return_lc3=True):
if framework == 'piper':
@@ -74,7 +75,7 @@ if __name__ == '__main__':
)
target_rate=16000
audio = synthesize('Hello World', target_rate, 'piper', model= 'de_DE-kerstin-low', encode_lc3=False)
audio = synthesize('Hello World', target_rate, 'piper', model= 'de_DE-kerstin-low', return_lc3=False)
sf.write('hello.wav', audio, target_rate)

View File

@@ -1,4 +1,4 @@
from multilang_translator.main import announcement_from_german_text
from multilang_translator.main_local import announcement_from_german_text
from multilang_translator.translator import test_content

View File

@@ -1,6 +1,6 @@
from multilang_translator.translator.llm_translator import translator_de_en, translator_de_fr, translator_de_it
from multilang_translator.translator.test_content import TESTSENTENCE_DE_BROKER, TESTSENTENCE_DE_RAINBOW
from multilang_translator.main import translate_from_german
from multilang_translator.main_local import translate_from_german
import time