From 31c33f9fa208c472f261273b2cbf1e78c51b09ee Mon Sep 17 00:00:00 2001 From: Vuizur Date: Wed, 4 Jan 2023 20:10:29 +0100 Subject: [PATCH 1/2] Replace example because of playsound bugs on Win --- examples/input_example.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/input_example.py b/examples/input_example.py index dacea62..14ce848 100755 --- a/examples/input_example.py +++ b/examples/input_example.py @@ -4,25 +4,21 @@ Example Python script that shows how to use edge-tts as a module """ import asyncio -import tempfile - -from playsound import playsound - import edge_tts - async def main(): """ Main function """ - communicate = edge_tts.Communicate() - ask = input("What do you want TTS to say? ") - with tempfile.NamedTemporaryFile() as temporary_file: - async for i in communicate.run(ask): - if i[2] is not None: - temporary_file.write(i[2]) - playsound(temporary_file.name) + TEXT = "Hello World!" + VOICE = "en-GB-SoniaNeural" + OUTPUT_FILE = "test.mp3" + communicate = edge_tts.Communicate() + with open(OUTPUT_FILE, "wb") as f: + async for i in communicate.run(TEXT, voice=VOICE): + if i[2] is not None: + f.write(i[2]) if __name__ == "__main__": - asyncio.get_event_loop().run_until_complete(main()) + asyncio.get_event_loop().run_until_complete(main()) \ No newline at end of file From 3bc7f728c3feb8766a0058d3a03f6e4b47d00cbf Mon Sep 17 00:00:00 2001 From: Vuizur Date: Wed, 4 Jan 2023 20:12:07 +0100 Subject: [PATCH 2/2] Rename example file --- README.md | 2 +- examples/{input_example.py => example.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename examples/{input_example.py => example.py} (100%) mode change 100755 => 100644 diff --git a/README.md b/README.md index 53d71fb..d44f5c0 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ In addition, it is required to use `--pitch=-10Hz` instead of `--pitch -10Hz` ot It is possible to use the `edge-tts` module directly from Python. For a list of example applications: -* https://github.com/rany2/edge-tts/blob/master/examples/input_example.py +* https://github.com/rany2/edge-tts/blob/master/examples/example.py * https://github.com/rany2/edge-tts/blob/master/src/edge_tts/util.py * https://github.com/rany2/edge-srt-to-speech/blob/master/src/edge_srt_to_speech/__main__.py * https://github.com/hasscc/hass-edge-tts/blob/main/custom_components/edge_tts/tts.py diff --git a/examples/input_example.py b/examples/example.py old mode 100755 new mode 100644 similarity index 100% rename from examples/input_example.py rename to examples/example.py