Skip to content

Commit

Permalink
feat(cmd): add param --spk
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jun 29, 2024
1 parent 24ae4f0 commit 09ea2a0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions examples/cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sys.path.append(now_dir)

import argparse
from typing import Optional, List

import ChatTTS

Expand All @@ -24,7 +25,7 @@ def save_mp3_file(wav, index):
logger.info(f"Audio saved to {mp3_filename}")


def main(texts: list[str]):
def main(texts: List[str], spk: Optional[str] = None):
logger.info("Text input: %s", str(texts))

chat = ChatTTS.Chat(get_logger("ChatTTS"))
Expand All @@ -34,22 +35,32 @@ def main(texts: list[str]):
else:
logger.error("Models load failed.")
sys.exit(1)

if spk is None:
spk = chat.sample_random_speaker()
logger.info("Use speaker:")
print(spk)

wavs = chat.infer(texts, use_decoder=True)
logger.info("Inference completed. Audio generation successful.")
logger.info("Start inference.")
wavs = chat.infer(texts, params_infer_code=ChatTTS.Chat.InferCodeParams(
spk_emb=spk,
))
logger.info("Inference completed.")
# Save each generated wav file to a local file
for index, wav in enumerate(wavs):
save_mp3_file(wav, index)
logger.info("Audio generation successful.")


if __name__ == "__main__":
logger.info("Starting the TTS application...")
logger.info("Starting ChatTTS commandline demo...")
parser = argparse.ArgumentParser(
description="ChatTTS Command", usage="--stream hello, my name is bob."
description="ChatTTS Command", usage='[--spk xxx] "Your text 1." " Your text 2."'
)
parser.add_argument("--spk", help="Speaker (empty to sample a random one)", type=Optional[str], default=None)
parser.add_argument(
"text", help="Original text", default="YOUR TEXT HERE", nargs="*"
"texts", help="Original text", default="YOUR TEXT HERE", nargs="*"
)
args = parser.parse_args()
main(args.text)
logger.info("TTS application finished.")
main(args.texts, args.spk)
logger.info("ChatTTS process finished.")

0 comments on commit 09ea2a0

Please sign in to comment.