Spaces:
Running
Running
alessandro trinca tornidor
commited on
Commit
•
e272322
1
Parent(s):
fd7a536
feat: refactor get_tts, get_speech_to_score_dict to raise immediatly errors in case of empty text/language/audio inputs
Browse files
aip_trainer/lambdas/lambdaSpeechToScore.py
CHANGED
@@ -53,6 +53,14 @@ def get_speech_to_score_dict(real_text: str, file_bytes_or_audiotmpfile: str | d
|
|
53 |
app_logger.info(f"real_text:{real_text} ...")
|
54 |
app_logger.debug(f"file_bytes:{file_bytes_or_audiotmpfile} ...")
|
55 |
app_logger.info(f"language:{language} ...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
start0 = time.time()
|
57 |
|
58 |
random_file_name = file_bytes_or_audiotmpfile
|
|
|
53 |
app_logger.info(f"real_text:{real_text} ...")
|
54 |
app_logger.debug(f"file_bytes:{file_bytes_or_audiotmpfile} ...")
|
55 |
app_logger.info(f"language:{language} ...")
|
56 |
+
|
57 |
+
if real_text is None or len(real_text) == 0:
|
58 |
+
raise ValueError(f"cannot read an empty/None text: '{real_text}'...")
|
59 |
+
if language is None or len(language) == 0:
|
60 |
+
raise NotImplementedError(f"Not tested/supported with '{language}' language...")
|
61 |
+
if file_bytes_or_audiotmpfile is None or len(file_bytes_or_audiotmpfile) == 0 or os.path.getsize(file_bytes_or_audiotmpfile) == 0:
|
62 |
+
raise ValueError(f"cannot read an empty/None file: '{file_bytes_or_audiotmpfile}'...")
|
63 |
+
|
64 |
start0 = time.time()
|
65 |
|
66 |
random_file_name = file_bytes_or_audiotmpfile
|
aip_trainer/lambdas/lambdaTTS.py
CHANGED
@@ -8,18 +8,20 @@ from aip_trainer import app_logger
|
|
8 |
def get_tts(text: str, language: str):
|
9 |
from aip_trainer.models import models
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
tmp_dir = Path(tempfile.gettempdir())
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
21 |
-
else:
|
22 |
-
raise NotImplementedError(f"Not yet tested with {language} error...")
|
23 |
app_logger.info(f"model speaker #0: {speaker} ...")
|
24 |
|
25 |
with tempfile.NamedTemporaryFile(prefix="audio_", suffix=".wav", delete=False) as tmp_audio_file:
|
@@ -27,26 +29,3 @@ def get_tts(text: str, language: str):
|
|
27 |
audio_paths = model.save_wav(text=text, speaker=speaker, sample_rate=sample_rate, audio_path=str(tmp_audio_file.name))
|
28 |
app_logger.info(f"audio_paths output: {audio_paths} ...")
|
29 |
return audio_paths
|
30 |
-
|
31 |
-
|
32 |
-
"""
|
33 |
-
Help on method save_wav:
|
34 |
-
|
35 |
-
save_wav(text=None, ssml_text=None, speaker: str = 'xenia', audio_path: str = '', sample_rate: int = 48000, put_accent=True, put_yo=True) method of <torch_package_0>.multi_acc_v3_package.TTSModelMultiAcc_v3 instance
|
36 |
-
|
37 |
-
|
38 |
-
tmp_dir = tempfile.gettempdir()
|
39 |
-
if language == "de":
|
40 |
-
model, decoder, _ = silero_stt(
|
41 |
-
language="de", version="v4", jit_model="jit_large", output_folder=tmp_dir
|
42 |
-
)
|
43 |
-
elif language == "en":
|
44 |
-
model, decoder, _ = silero_stt(language="en", output_folder=tmp_dir)
|
45 |
-
else:
|
46 |
-
raise NotImplementedError(
|
47 |
-
"currenty works only for 'de' and 'en' languages, not for '{}'.".format(
|
48 |
-
language
|
49 |
-
)
|
50 |
-
)
|
51 |
-
|
52 |
-
"""
|
|
|
8 |
def get_tts(text: str, language: str):
|
9 |
from aip_trainer.models import models
|
10 |
|
11 |
+
if text is None or len(text) == 0:
|
12 |
+
raise ValueError(f"cannot read an empty/None text: '{text}'...")
|
13 |
+
if language is None or len(language) == 0:
|
14 |
+
raise NotImplementedError(f"Not tested/supported with '{language}' language...")
|
15 |
+
|
16 |
tmp_dir = Path(tempfile.gettempdir())
|
17 |
+
try:
|
18 |
+
model, _, speaker, sample_rate = models.silero_tts(
|
19 |
+
language, output_folder=tmp_dir
|
20 |
+
)
|
21 |
+
except ValueError:
|
22 |
+
model, _, sample_rate, _, _, speaker = models.silero_tts(
|
23 |
+
language, output_folder=tmp_dir
|
24 |
+
)
|
|
|
|
|
|
|
25 |
app_logger.info(f"model speaker #0: {speaker} ...")
|
26 |
|
27 |
with tempfile.NamedTemporaryFile(prefix="audio_", suffix=".wav", delete=False) as tmp_audio_file:
|
|
|
29 |
audio_paths = model.save_wav(text=text, speaker=speaker, sample_rate=sample_rate, audio_path=str(tmp_audio_file.name))
|
30 |
app_logger.info(f"audio_paths output: {audio_paths} ...")
|
31 |
return audio_paths
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|