1.1
This commit is contained in:
1 parent
122c47dd20
commit
bf68444629
11 files changed
+316
-1707
No files matched your search
+55
-26
@@ -78,6 +78,14 @@ def cli():
|
||||
type=click.Choice(["stream", "http"], case_sensitive=False),
|
||||
help="The mode to use for speech synthesis",
|
||||
)
|
||||
@click.option(
|
||||
"--form-chunk",
|
||||
help="Form chunk to say, 1 for first chunk, 2 for second chunk, etc.",
|
||||
)
|
||||
@click.option(
|
||||
"--to-chunk",
|
||||
help="To chunk to say, 1 for first chunk, 2 for second chunk, etc.",
|
||||
)
|
||||
@click.argument("input_file")
|
||||
def say(
|
||||
backend: str,
|
||||
@@ -94,6 +102,8 @@ def say(
|
||||
strict: bool,
|
||||
mode: str,
|
||||
split_length: int,
|
||||
form_chunk: int,
|
||||
to_chunk: int,
|
||||
):
|
||||
with open(input_file, "r", encoding="utf-8") as f:
|
||||
html = f.read()
|
||||
@@ -114,50 +124,51 @@ def say(
|
||||
codec_model=codec_model,
|
||||
)
|
||||
|
||||
for voice, text in result:
|
||||
logger.info(f"正在合成: voice={voice}, text={text}")
|
||||
tts_backend.smart_say(
|
||||
voice=voice,
|
||||
text=text,
|
||||
instruct=instruct,
|
||||
split_length=split_length,
|
||||
output_file_prefix=f"{output_dir}/{voice}_{text[0:9]}",
|
||||
)
|
||||
case "qtr":
|
||||
from backend import QTRTTSBackend
|
||||
|
||||
tts_backend = QTRTTSBackend(ws_uri=ws_uri, sample_rate=sample_rate)
|
||||
from tqdm import tqdm
|
||||
|
||||
for voice, text in tqdm(
|
||||
result,
|
||||
desc="合成语音",
|
||||
unit="段",
|
||||
total=len(result),
|
||||
colour="green",
|
||||
):
|
||||
logger.info(f"正在合成: voice={voice}, text={text}", mode=mode)
|
||||
tts_backend.smart_say(
|
||||
voice=voice,
|
||||
text=text,
|
||||
instruct=instruct,
|
||||
split_length=split_length,
|
||||
output_file_prefix=f"{output_dir}/{voice}_{text[0:9]}",
|
||||
)
|
||||
case _:
|
||||
raise ValueError(f"Unsupported backend: {backend}")
|
||||
|
||||
for voice, text in tqdm(
|
||||
result,
|
||||
desc="合成语音",
|
||||
unit="段",
|
||||
total=len(result),
|
||||
colour="green",
|
||||
):
|
||||
logger.info(f"正在合成: voice={voice}, text={text}", mode=mode)
|
||||
u
|
||||
tts_backend.smart_say(
|
||||
from_chunk=form_chunk,
|
||||
to_chunk=to_chunk,
|
||||
voice=voice,
|
||||
text=text,
|
||||
instruct=instruct,
|
||||
split_length=split_length,
|
||||
output_file_prefix=f"{output_dir}/{voice}_{text[0:9]}",
|
||||
)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("input_dir")
|
||||
@click.argument("output_file")
|
||||
@click.option(
|
||||
"--add-silence",
|
||||
default=0.5,
|
||||
type=float,
|
||||
help="Add silence between combined wav files in seconds",
|
||||
)
|
||||
@click.option("--format", default="wav", help="The output format, either wav or mp3")
|
||||
def combine(input_dir: str, output_file: str, format: str):
|
||||
def combine(input_dir: str, output_file: str, add_silence: float, format: str):
|
||||
from files import FileHandler
|
||||
|
||||
handler = FileHandler(input_dir)
|
||||
if format == "wav":
|
||||
handler.combine_waves(output_file)
|
||||
handler.combine_waves(output_file, add_silence=add_silence)
|
||||
elif format == "mp3":
|
||||
handler.combine_waves(output_file)
|
||||
handler.wavs_to_mp3(output_file, output_file.replace(".wav", ".mp3"))
|
||||
@@ -285,6 +296,24 @@ def add_bgms(
|
||||
main_audio.export(output_file, format="wav")
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
"--remove-silence",
|
||||
default=0.3,
|
||||
type=float,
|
||||
help="Remove silence from the beginning and end of the audio",
|
||||
)
|
||||
@click.argument("input_file")
|
||||
@click.argument("output_file")
|
||||
def pretty(remove_silence: float, input_file: str, output_file: str):
|
||||
if remove_silence > 0:
|
||||
from pretty import remove_silence as remove_silence_func
|
||||
|
||||
remove_silence_func(
|
||||
pydub.AudioSegment.from_wav(input_file), remove_silence
|
||||
).export(output_file, format="wav")
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("input_txt")
|
||||
@click.argument("output_xml")
|
||||
|
||||
Reference in new issue
Block a user