diff --git a/.vscode/launch.json b/.vscode/launch.json index bdf185c..ecff1bf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,4 +12,4 @@ "module": "anki_hsk_creator" } ] -} \ No newline at end of file +} diff --git a/src/anki_hsk_creator/__main__.py b/src/anki_hsk_creator/__main__.py index 252016f..4047ae4 100644 --- a/src/anki_hsk_creator/__main__.py +++ b/src/anki_hsk_creator/__main__.py @@ -8,11 +8,12 @@ from .api import ( is_file, list_input_files, pre_process_a_dictionary_file, + process_a_dictation_file, process_a_dictionary_file, process_a_phrases_file, select_file, ) -from .constants import DICT_TYPE, LANGUAGES, PHRASES_TYPE +from .constants import DICTATION_TYPE, DICT_TYPE, LANGUAGES, PHRASES_TYPE from .utility import ProcessFile @@ -90,6 +91,12 @@ def main(): f"processing file {input_file.input_file} with language {language_id}" ) process_a_phrases_file(input_file, language_id) + elif DICTATION_TYPE in input_file.input_file.suffixes: + language_id = cli_select_language() + print( + f"processing file {input_file.input_file} with language {language_id}" + ) + process_a_dictation_file(input_file, language_id) if __name__ == "__main__": diff --git a/src/anki_hsk_creator/api.py b/src/anki_hsk_creator/api.py index 4e6f134..16a1af2 100644 --- a/src/anki_hsk_creator/api.py +++ b/src/anki_hsk_creator/api.py @@ -221,7 +221,7 @@ def process_a_dictation_file(process_file: ProcessFile, language_id: str) -> Pat with process_file.absolute_input_file.open( "r", encoding="utf8", newline="\n" ) as file: - text_lines = [line.strip() for line in file.read().split("。")] + text_lines = [line.strip() for line in file.read().split("。") if line.strip()] results = dictation_process(text_lines, process_file) return output_anki_dictation(process_file, results) @@ -234,6 +234,6 @@ def process_a_phrases_file(process_file: ProcessFile, language_id: str) -> Path: with process_file.absolute_input_file.open( "r", encoding="utf8", newline="\n" ) as file: - text_lines = [line.strip() for line in file.readlines()] + text_lines = [line.strip() for line in file.readlines() if line.strip()] results = translator_process(text_lines, process_file) return output_anki_phrase(process_file, results) diff --git a/src/anki_hsk_creator/constants.py b/src/anki_hsk_creator/constants.py index b274cbb..d9689a6 100644 --- a/src/anki_hsk_creator/constants.py +++ b/src/anki_hsk_creator/constants.py @@ -16,7 +16,7 @@ OUTPUT = DATA_FOLDER / "output" OUTPUT.mkdir(exist_ok=True, parents=True) RESOURCES = DATA_FOLDER / "resources" RESOURCES.mkdir(exist_ok=True, parents=True) -GWEN_TTS = GWEN_FOLDER / "Qwen3-TTS-12Hz-1.7B-CustomVoice" +GWEN_TTS = GWEN_FOLDER / "Qwen3-TTS-12Hz-0.6B-CustomVoice" # File Types PHRASES_TYPE = ".phrases" diff --git a/src/anki_hsk_creator/proccessor.py b/src/anki_hsk_creator/proccessor.py index 110b4a2..b90f71b 100644 --- a/src/anki_hsk_creator/proccessor.py +++ b/src/anki_hsk_creator/proccessor.py @@ -25,10 +25,10 @@ def dictation_process( """Process for Dictation translation""" results = [] for n, line in enumerate(text_lines): - line = line.strip() - line = " ".join(line.split()) - audio_line = " ".join(line) - audio_line = audio_line.replace(",", ",。。。]") + audio_line = line.strip() + # line = " ".join(line.split()) + # audio_line = " ".join(line) + # audio_line = audio_line.replace(",", ",。。。]") audio_path = process_file.resources / f"N{n:03n}.wav" if not audio_path.exists(): wavs, sr = TTS.generate(f"{audio_line}。") @@ -48,10 +48,10 @@ def translator_process( """Process for phases or sentence translation""" results = [] for n, line in enumerate(text_lines): - line = line.strip() - line = " ".join(line.split()) - audio_line = " ".join(line) - audio_line = audio_line.replace(",", ",。。。]") + audio_line = line.strip() + # line = " ".join(line.split()) + # audio_line = " ".join(line) + # audio_line = audio_line.replace(",", ",。。。]") audio_path = process_file.resources / f"N{n:03n}.wav" if not audio_path.exists(): wavs, sr = TTS.generate(f"{audio_line}。") diff --git a/src/anki_hsk_creator/utility.py b/src/anki_hsk_creator/utility.py index ff063dd..7469aeb 100644 --- a/src/anki_hsk_creator/utility.py +++ b/src/anki_hsk_creator/utility.py @@ -151,7 +151,7 @@ class TTS: if TTS.DEVICE is None: # Automatically detect the best available device if torch.cuda.is_available(): - TTS.DEVICE = "cuda" + TTS.DEVICE = "cuda:0" elif torch.backends.mps.is_available(): TTS.DEVICE = "mps" else: @@ -161,7 +161,7 @@ class TTS: GWEN_TTS, device_map=TTS.DEVICE, dtype=torch.bfloat16, - # attn_implementation="flash_attention_2", + attn_implementation="flash_attention_2", ) @staticmethod