Skip to content

Commit

Permalink
feat(cmd): add multiple texts (#366)
Browse files Browse the repository at this point in the history
Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
  • Loading branch information
Ox0400 and fumiama authored Jun 22, 2024
1 parent 12cc9f6 commit a41ce63
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions examples/cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
now_dir = os.getcwd()
sys.path.append(now_dir)

import wave
import argparse

from dotenv import load_dotenv
load_dotenv("sha256.env")

import wave
import ChatTTS

from tools.audio import unsafe_float_to_int16
Expand All @@ -26,10 +28,8 @@ def save_wav_file(wav, index):
wf.writeframes(unsafe_float_to_int16(wav))
logger.info(f"Audio saved to {wav_filename}")

def main():
# Retrieve text from command line argument
text_input = sys.argv[1] if len(sys.argv) > 1 else "<YOUR TEXT HERE>"
logger.info("Text input: %s", text_input)
def main(texts: list[str]):
logger.info("Text input: %s", str(texts))

chat = ChatTTS.Chat(get_logger("ChatTTS"))
logger.info("Initializing ChatTTS...")
Expand All @@ -39,13 +39,16 @@ def main():
logger.error("Models load failed.")
sys.exit(1)

wavs = chat.infer((text_input), use_decoder=True)
wavs = chat.infer(texts, use_decoder=True)
logger.info("Inference completed. Audio generation successful.")
# Save each generated wav file to a local file
for index, wav in enumerate(wavs):
save_wav_file(wav, index)

if __name__ == "__main__":
logger.info("Starting the TTS application...")
main()
parser = argparse.ArgumentParser(description='ChatTTS Command', usage="--stream hello, my name is bob.")
parser.add_argument("text", help="Original text", default='YOUR TEXT HERE', nargs='*')
args = parser.parse_args()
main(args.text)
logger.info("TTS application finished.")

0 comments on commit a41ce63

Please sign in to comment.