fix for windows users

This commit is contained in:
rany 2022-03-13 13:25:41 +02:00
parent 7d03764943
commit 393233ecf9
2 changed files with 33 additions and 25 deletions

View File

@ -1,6 +1,6 @@
[metadata]
name = edge-tts
version = 4.0.8
version = 4.0.9
author = rany
author_email = ranygh@riseup.net
description = Microsoft Edge's TTS

View File

@ -4,6 +4,7 @@
Playback TTS with subtitles using edge-tts and mpv.
"""
import os
import subprocess
import sys
import tempfile
@ -15,31 +16,38 @@ def main():
Main function.
"""
if which("mpv") and which("edge-tts"):
with tempfile.NamedTemporaryFile() as media:
with tempfile.NamedTemporaryFile() as subtitle:
print()
print(f"Media file: {media.name}")
print(f"Subtitle file: {subtitle.name}\n")
with subprocess.Popen(
[
"edge-tts",
"--boundary-type=2",
f"--write-media={media.name}",
f"--write-subtitles={subtitle.name}",
]
+ sys.argv[1:]
) as process:
process.communicate()
media = tempfile.NamedTemporaryFile(delete=False)
subtitle = tempfile.NamedTemporaryFile(delete=False)
try:
media.close()
subtitle.close()
with subprocess.Popen(
[
"mpv",
"--keep-open=yes",
f"--sub-file={subtitle.name}",
media.name,
]
) as process:
process.communicate()
print()
print(f"Media file: {media.name}")
print(f"Subtitle file: {subtitle.name}\n")
with subprocess.Popen(
[
"edge-tts",
"--boundary-type=2",
f"--write-media={media.name}",
f"--write-subtitles={subtitle.name}",
]
+ sys.argv[1:]
) as process:
process.communicate()
with subprocess.Popen(
[
"mpv",
"--keep-open=yes",
f"--sub-file={subtitle.name}",
media.name,
]
) as process:
process.communicate()
finally:
os.unlink(media.name)
os.unlink(subtitle.name)
else:
print("This script requires mpv and edge-tts.")