fix: input file directories

This commit is contained in:
ayo 2026-06-07 18:34:24 +02:00
parent b7d4b1ac5e
commit aa03f6ed21

11
tts.py
View file

@ -18,6 +18,8 @@ from tqdm import tqdm
import pyperclip
from yaspin import yaspin
import os
# See voices: https://huggingface.co/hexgrad/Kokoro-82M/blob/main/VOICES.md
voices = {
'pro': 'af_heart',
@ -40,6 +42,9 @@ prep_texts = [
"All systems green—let's make this a good one."
]
dir_path = os.path.dirname(os.path.realpath(__file__))
demo_file = f"{dir_path}/demo/tongue-twister.txt"
def parse_args():
parser = argparse.ArgumentParser(description="Simple TTS - machine learning text-to-speech for your terminal", allow_abbrev=False)
parser.add_argument(
@ -54,7 +59,7 @@ def parse_args():
"-i",
required=False,
type=str,
default="demo/tongue-twister.txt",
default=demo_file,
help = "path to the input text file",
)
parser.add_argument(
@ -162,8 +167,8 @@ def main():
text = pyperclip.paste()
name = 'copied'
else:
dirname = os.path.dirname(__file__)
file_path = os.path.join(dirname, args.input_file)
cwd = os.getcwd()
file_path = os.path.join(cwd, args.input_file)
directory, file_name = os.path.split(file_path)
name = '.'.join(file_name.split('.')[:-1])
file = open(file_path, "r")