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-FileCopyrightText: 2026-present Wolfang Torres <wolfang.torres@gmail.com>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# 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_file,
|
||||||
select_folder,
|
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
|
from .utility import ProcessFile, ProcessFolder
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ def cli_select_files() -> ProcessFile:
|
|||||||
return input_file
|
return input_file
|
||||||
|
|
||||||
|
|
||||||
def cli_select_folder() -> ProcessFile:
|
def cli_select_folder() -> ProcessFolder:
|
||||||
"""Loops until it finds a valid input_folder"""
|
"""Loops until it finds a valid input_folder"""
|
||||||
print("Select data folder:")
|
print("Select data folder:")
|
||||||
in_folder = None
|
in_folder = None
|
||||||
@@ -138,10 +138,15 @@ def main():
|
|||||||
print(f"processing file {input_file} with language {language_id}")
|
print(f"processing file {input_file} with language {language_id}")
|
||||||
process_a_dictation_file(input_file, language_id)
|
process_a_dictation_file(input_file, language_id)
|
||||||
elif option == "f":
|
elif option == "f":
|
||||||
|
for language_id in LANGUAGES.AvailableLanguages:
|
||||||
in_folder = cli_select_folder()
|
in_folder = cli_select_folder()
|
||||||
language_id = cli_select_language()
|
|
||||||
print(f"Selected: {in_folder} with language {language_id}")
|
print(f"Selected: {in_folder} with language {language_id}")
|
||||||
folder_proccess(in_folder, language_id=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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ from genanki import Deck, Model, Note, Package
|
|||||||
from pinyin_tone_converter.pinyin_tone_converter import PinyinToneConverter
|
from pinyin_tone_converter.pinyin_tone_converter import PinyinToneConverter
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
|
from .constants import DICTATION_TYPE, DICT_TYPE, PHRASES_TYPE
|
||||||
from .utility import DictionaryResult, ProcessFile, ProcessFolder, TranslationResult
|
from .utility import DictionaryResult, ProcessFile, ProcessFolder, TranslationResult
|
||||||
from .constants import DICT_TYPE, DICTATION_TYPE, PHRASES_TYPE
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ def output_anki_package(
|
|||||||
fields=[
|
fields=[
|
||||||
result.translated,
|
result.translated,
|
||||||
result.line,
|
result.line,
|
||||||
f"[sound:{result.audio_path}]",
|
f"[sound:{result.audio_path.name}]",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
deck.add_note(note)
|
deck.add_note(note)
|
||||||
@@ -277,7 +277,7 @@ def output_anki_package(
|
|||||||
PinyinToneConverter().convert_text(result.pinyin),
|
PinyinToneConverter().convert_text(result.pinyin),
|
||||||
result.simplified,
|
result.simplified,
|
||||||
result.traditional,
|
result.traditional,
|
||||||
f"[sound:{result.audio_path}]",
|
f"[sound:{result.audio_path.name}]",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
deck.add_note(note)
|
deck.add_note(note)
|
||||||
@@ -289,7 +289,7 @@ def output_anki_package(
|
|||||||
fields=[
|
fields=[
|
||||||
result.translated,
|
result.translated,
|
||||||
result.line,
|
result.line,
|
||||||
f"[sound:{result.audio_path}]",
|
f"[sound:{result.audio_path.name}]",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
deck.add_note(note)
|
deck.add_note(note)
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ from . import DATA_FOLDER
|
|||||||
from .anki_generation import (
|
from .anki_generation import (
|
||||||
output_anki_dictation,
|
output_anki_dictation,
|
||||||
output_anki_dictionary,
|
output_anki_dictionary,
|
||||||
output_anki_phrase,
|
|
||||||
output_anki_package,
|
output_anki_package,
|
||||||
|
output_anki_phrase,
|
||||||
)
|
)
|
||||||
from .constants import (
|
from .constants import (
|
||||||
DICTATION_TYPE,
|
DICTATION_TYPE,
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ def dictation_process(
|
|||||||
results = []
|
results = []
|
||||||
for n, line in enumerate(text_lines):
|
for n, line in enumerate(text_lines):
|
||||||
audio_line = line.strip()
|
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():
|
if not audio_path.exists():
|
||||||
wavs, sr = TTS.generate(f"{audio_line}。")
|
wavs, sr = TTS.generate(f"{audio_line}。")
|
||||||
sf.write(audio_path, wavs[0], sr)
|
sf.write(audio_path, wavs[0], sr)
|
||||||
@@ -47,7 +51,11 @@ def translator_process(
|
|||||||
results = []
|
results = []
|
||||||
for n, line in enumerate(text_lines):
|
for n, line in enumerate(text_lines):
|
||||||
audio_line = line.strip()
|
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():
|
if not audio_path.exists():
|
||||||
wavs, sr = TTS.generate(f"{audio_line}。")
|
wavs, sr = TTS.generate(f"{audio_line}。")
|
||||||
sf.write(audio_path, wavs[0], sr)
|
sf.write(audio_path, wavs[0], sr)
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ class TTS:
|
|||||||
print(f"finish to generate {text}")
|
print(f"finish to generate {text}")
|
||||||
return audio
|
return audio
|
||||||
|
|
||||||
|
|
||||||
# Clases
|
# Clases
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user