Skip to content

Commit a41ce63

Browse files
Ox0400fumiama
andauthored
feat(cmd): add multiple texts (#366)
Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
1 parent 12cc9f6 commit a41ce63

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

examples/cmd/run.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
now_dir = os.getcwd()
77
sys.path.append(now_dir)
88

9+
import wave
10+
import argparse
11+
912
from dotenv import load_dotenv
1013
load_dotenv("sha256.env")
1114

12-
import wave
1315
import ChatTTS
1416

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

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

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

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

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

0 commit comments

Comments
 (0)