rany2 / edge-tts

Use Microsoft Edge's online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API key
https://pypi.org/project/edge-tts/
GNU General Public License v3.0
4.24k stars 447 forks source link

Why does this come up when i try to run edge tts in my code #131

Closed furkanshaikh313 closed 10 months ago

furkanshaikh313 commented 10 months ago

E:\RVC-beta-v2-0618\AniVoiceChanger>Warning: TTS output will be written to the terminal. Use --write-media to write to a file. Press Ctrl+C to cancel the operation. Press Enter to continue.

MY code def edge_playback(output): subprocess.Popen(["edge-tts", "--text", '"' + output + '--write-media hello.mp3'])

rany2 commented 10 months ago

Hi, can you change line 41 in src/edge_tts/util.py to if sys.stdout.isatty() and not args.write_media:?

diff --git a/src/edge_tts/util.py b/src/edge_tts/util.py
index a26c9bd..ad80a61 100644
--- a/src/edge_tts/util.py
+++ b/src/edge_tts/util.py
@@ -38,7 +38,7 @@ 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:
+        if 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"
furkanshaikh313 commented 10 months ago

sure let me try

furkanshaikh313 commented 10 months ago

Ir is rhis

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

rany2 commented 10 months ago

Yes

furkanshaikh313 commented 10 months ago

but it still gives error ok can u tell me any other way i can run tts in python using subprocess or anything i just need to save a variable as speech in a particular place

rany2 commented 10 months ago

Why can't you use the library directly? If you don't want to use async, you could do something like: https://github.com/rany2/edge-tts/issues/127#issuecomment-1658996740