Spaces:
Runtime error
Runtime error
File size: 807 Bytes
a8c39f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import sys
import asyncio
import edge_tts
import os
async def main():
# Parse command line arguments
tts_file = str(sys.argv[1])
text = str(sys.argv[2])
voice = str(sys.argv[3])
rate = int(sys.argv[4])
output_file = str(sys.argv[5])
rates = f"+{rate}%" if rate >= 0 else f"{rate}%"
if tts_file and os.path.exists(tts_file):
text = ""
try:
with open(tts_file, "r", encoding="utf-8") as file:
text = file.read()
except UnicodeDecodeError:
with open(tts_file, "r") as file:
text = file.read()
await edge_tts.Communicate(text, voice, rate=rates).save(output_file)
print(f"TTS with {voice} completed. Output TTS file: '{output_file}'")
if __name__ == "__main__":
asyncio.run(main())
|