changes for gwen tts
This commit is contained in:
@@ -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__":
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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}。")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user