Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for stream mode. #366

Merged
merged 5 commits into from
Jun 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.")