utils.py 409 B

12345678910111213141516171819
  1. import time
  2. from tts_webui.utils.set_seed import set_seed
  3. from contextlib import contextmanager
  4. @contextmanager
  5. def Timer():
  6. start_time = time.time()
  7. yield
  8. end_time = time.time()
  9. elapsed_time = end_time - start_time
  10. print("Generated in", "{:.3f}".format(elapsed_time), "seconds")
  11. @contextmanager
  12. def Seed(seed):
  13. original_seed = set_seed(seed)
  14. yield
  15. set_seed(original_seed)