changes for gwen tts

This commit is contained in:
Wolfang Torres
2026-06-26 19:11:41 +08:00
parent 5896f0db66
commit 777f4b4de1
6 changed files with 22 additions and 15 deletions

View File

@@ -8,11 +8,12 @@ from .api import (
is_file, is_file,
list_input_files, list_input_files,
pre_process_a_dictionary_file, pre_process_a_dictionary_file,
process_a_dictation_file,
process_a_dictionary_file, process_a_dictionary_file,
process_a_phrases_file, process_a_phrases_file,
select_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 from .utility import ProcessFile
@@ -90,6 +91,12 @@ def main():
f"processing file {input_file.input_file} with language {language_id}" f"processing file {input_file.input_file} with language {language_id}"
) )
process_a_phrases_file(input_file, 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__": if __name__ == "__main__":

View File

@@ -221,7 +221,7 @@ def process_a_dictation_file(process_file: ProcessFile, language_id: str) -> Pat
with process_file.absolute_input_file.open( with process_file.absolute_input_file.open(
"r", encoding="utf8", newline="\n" "r", encoding="utf8", newline="\n"
) as file: ) 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) results = dictation_process(text_lines, process_file)
return output_anki_dictation(process_file, results) 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( with process_file.absolute_input_file.open(
"r", encoding="utf8", newline="\n" "r", encoding="utf8", newline="\n"
) as file: ) 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) results = translator_process(text_lines, process_file)
return output_anki_phrase(process_file, results) return output_anki_phrase(process_file, results)

View File

@@ -16,7 +16,7 @@ OUTPUT = DATA_FOLDER / "output"
OUTPUT.mkdir(exist_ok=True, parents=True) OUTPUT.mkdir(exist_ok=True, parents=True)
RESOURCES = DATA_FOLDER / "resources" RESOURCES = DATA_FOLDER / "resources"
RESOURCES.mkdir(exist_ok=True, parents=True) 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 # File Types
PHRASES_TYPE = ".phrases" PHRASES_TYPE = ".phrases"

View File

@@ -25,10 +25,10 @@ def dictation_process(
"""Process for Dictation translation""" """Process for Dictation translation"""
results = [] results = []
for n, line in enumerate(text_lines): for n, line in enumerate(text_lines):
line = line.strip() audio_line = line.strip()
line = " ".join(line.split()) # line = " ".join(line.split())
audio_line = " ".join(line) # audio_line = " ".join(line)
audio_line = audio_line.replace("", ",。。。]") # audio_line = audio_line.replace("", ",。。。]")
audio_path = process_file.resources / f"N{n:03n}.wav" audio_path = process_file.resources / f"N{n:03n}.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}")
@@ -48,10 +48,10 @@ def translator_process(
"""Process for phases or sentence translation""" """Process for phases or sentence translation"""
results = [] results = []
for n, line in enumerate(text_lines): for n, line in enumerate(text_lines):
line = line.strip() audio_line = line.strip()
line = " ".join(line.split()) # line = " ".join(line.split())
audio_line = " ".join(line) # audio_line = " ".join(line)
audio_line = audio_line.replace("", ",。。。]") # audio_line = audio_line.replace("", ",。。。]")
audio_path = process_file.resources / f"N{n:03n}.wav" audio_path = process_file.resources / f"N{n:03n}.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}")

View File

@@ -151,7 +151,7 @@ class TTS:
if TTS.DEVICE is None: if TTS.DEVICE is None:
# Automatically detect the best available device # Automatically detect the best available device
if torch.cuda.is_available(): if torch.cuda.is_available():
TTS.DEVICE = "cuda" TTS.DEVICE = "cuda:0"
elif torch.backends.mps.is_available(): elif torch.backends.mps.is_available():
TTS.DEVICE = "mps" TTS.DEVICE = "mps"
else: else:
@@ -161,7 +161,7 @@ class TTS:
GWEN_TTS, GWEN_TTS,
device_map=TTS.DEVICE, device_map=TTS.DEVICE,
dtype=torch.bfloat16, dtype=torch.bfloat16,
# attn_implementation="flash_attention_2", attn_implementation="flash_attention_2",
) )
@staticmethod @staticmethod