update bugs in bulk production
This commit is contained in:
@@ -3,4 +3,4 @@
|
||||
# SPDX-FileCopyrightText: 2026-present Wolfang Torres <wolfang.torres@gmail.com>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
__version__ = "0.2.1"
|
||||
__version__ = "0.2.3"
|
||||
|
||||
@@ -15,7 +15,7 @@ from .api import (
|
||||
select_file,
|
||||
select_folder,
|
||||
)
|
||||
from .constants import DICTATION_TYPE, DICT_TYPE, LANGUAGES, PHRASES_TYPE
|
||||
from .constants import DICTATION_TYPE, DICT_TYPE, INPUT, LANGUAGES, PHRASES_TYPE
|
||||
from .utility import ProcessFile, ProcessFolder
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ def cli_select_files() -> ProcessFile:
|
||||
return input_file
|
||||
|
||||
|
||||
def cli_select_folder() -> ProcessFile:
|
||||
def cli_select_folder() -> ProcessFolder:
|
||||
"""Loops until it finds a valid input_folder"""
|
||||
print("Select data folder:")
|
||||
in_folder = None
|
||||
@@ -138,10 +138,15 @@ def main():
|
||||
print(f"processing file {input_file} with language {language_id}")
|
||||
process_a_dictation_file(input_file, language_id)
|
||||
elif option == "f":
|
||||
in_folder = cli_select_folder()
|
||||
language_id = cli_select_language()
|
||||
print(f"Selected: {in_folder} with language {language_id}")
|
||||
folder_proccess(in_folder, language_id=language_id)
|
||||
for language_id in LANGUAGES.AvailableLanguages:
|
||||
in_folder = cli_select_folder()
|
||||
print(f"Selected: {in_folder} with language {language_id}")
|
||||
for dirpath, dirnames, filenames in tuple(
|
||||
in_folder.absolute_input_folder.walk()
|
||||
)[1:]:
|
||||
if not dirnames and filenames:
|
||||
folder = select_folder(dirpath.relative_to(INPUT))
|
||||
folder_proccess(folder, language_id=language_id)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -12,8 +12,8 @@ from genanki import Deck, Model, Note, Package
|
||||
from pinyin_tone_converter.pinyin_tone_converter import PinyinToneConverter
|
||||
|
||||
# Local
|
||||
from .constants import DICTATION_TYPE, DICT_TYPE, PHRASES_TYPE
|
||||
from .utility import DictionaryResult, ProcessFile, ProcessFolder, TranslationResult
|
||||
from .constants import DICT_TYPE, DICTATION_TYPE, PHRASES_TYPE
|
||||
|
||||
# Constants
|
||||
|
||||
@@ -262,12 +262,12 @@ def output_anki_package(
|
||||
fields=[
|
||||
result.translated,
|
||||
result.line,
|
||||
f"[sound:{result.audio_path}]",
|
||||
f"[sound:{result.audio_path.name}]",
|
||||
],
|
||||
)
|
||||
deck.add_note(note)
|
||||
audios.append(result.audio_path)
|
||||
elif process_file.file_type is DICT_TYPE:
|
||||
elif process_file.file_type is DICT_TYPE:
|
||||
for result in results:
|
||||
note = Note(
|
||||
model=HSK_MODEL,
|
||||
@@ -277,19 +277,19 @@ def output_anki_package(
|
||||
PinyinToneConverter().convert_text(result.pinyin),
|
||||
result.simplified,
|
||||
result.traditional,
|
||||
f"[sound:{result.audio_path}]",
|
||||
f"[sound:{result.audio_path.name}]",
|
||||
],
|
||||
)
|
||||
deck.add_note(note)
|
||||
audios.append(result.audio_path)
|
||||
elif process_file.file_type is PHRASES_TYPE:
|
||||
elif process_file.file_type is PHRASES_TYPE:
|
||||
for result in results:
|
||||
note = Note(
|
||||
model=PHRASE_MODEL,
|
||||
fields=[
|
||||
result.translated,
|
||||
result.line,
|
||||
f"[sound:{result.audio_path}]",
|
||||
f"[sound:{result.audio_path.name}]",
|
||||
],
|
||||
)
|
||||
deck.add_note(note)
|
||||
|
||||
@@ -11,8 +11,8 @@ from . import DATA_FOLDER
|
||||
from .anki_generation import (
|
||||
output_anki_dictation,
|
||||
output_anki_dictionary,
|
||||
output_anki_phrase,
|
||||
output_anki_package,
|
||||
output_anki_phrase,
|
||||
)
|
||||
from .constants import (
|
||||
DICTATION_TYPE,
|
||||
|
||||
@@ -27,7 +27,11 @@ def dictation_process(
|
||||
results = []
|
||||
for n, line in enumerate(text_lines):
|
||||
audio_line = line.strip()
|
||||
audio_path = process_file.resources / f"N{n:03n}.wav"
|
||||
posible_name = tuple(process_file.resources.glob(f"N{n:03n}-*.wav"))
|
||||
if posible_name:
|
||||
audio_path = posible_name[0]
|
||||
else:
|
||||
audio_path = process_file.resources / f"N{n:03n}-{uuid.uuid1()}.wav"
|
||||
if not audio_path.exists():
|
||||
wavs, sr = TTS.generate(f"{audio_line}。")
|
||||
sf.write(audio_path, wavs[0], sr)
|
||||
@@ -47,7 +51,11 @@ def translator_process(
|
||||
results = []
|
||||
for n, line in enumerate(text_lines):
|
||||
audio_line = line.strip()
|
||||
audio_path = process_file.resources / f"N{n:03n}.wav"
|
||||
posible_name = tuple(process_file.resources.glob(f"N{n:03n}-*.wav"))
|
||||
if posible_name:
|
||||
audio_path = posible_name[0]
|
||||
else:
|
||||
audio_path = process_file.resources / f"N{n:03n}-{uuid.uuid1()}.wav"
|
||||
if not audio_path.exists():
|
||||
wavs, sr = TTS.generate(f"{audio_line}。")
|
||||
sf.write(audio_path, wavs[0], sr)
|
||||
|
||||
@@ -196,6 +196,7 @@ class TTS:
|
||||
print(f"finish to generate {text}")
|
||||
return audio
|
||||
|
||||
|
||||
# Clases
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user