Provide warning before writing binary to stdout

* Writing binary data to terminal could cause unintended behavior
  and mess up a terminal. Print a warning before doing such a thing.
This commit is contained in:
rany2 2023-04-30 23:39:14 +03:00
parent 4f70613c03
commit 6c55e815bb

View File

@ -36,6 +36,21 @@ async def _print_voices(*, proxy: str) -> None:
async def _run_tts(args: Any) -> None:
"""Run TTS after parsing arguments from command line."""
try:
if sys.stdin.isatty() and sys.stdout.isatty() and not args.write_media:
print(
"Warning: TTS output will be written to the terminal. "
"Use --write-media to write to a file.\n"
"Press Ctrl+C to cancel the operation. "
"Press Enter to continue.",
file=sys.stderr,
)
input()
except KeyboardInterrupt:
print("\nOperation canceled.", file=sys.stderr)
return
tts: Communicate = Communicate(
args.text,
args.voice,