feat: if no input, try demo files

This commit is contained in:
ayo 2026-06-07 19:21:29 +02:00
parent aa03f6ed21
commit 1180124740

21
tts.py
View file

@ -42,8 +42,8 @@ prep_texts = [
"All systems green—let's make this a good one." "All systems green—let's make this a good one."
] ]
dir_path = os.path.dirname(os.path.realpath(__file__)) dir_path = os.path.expanduser('~')
demo_file = f"{dir_path}/demo/tongue-twister.txt" installed_demo_file = f"{dir_path}/.local/lib/simple-tts/demo/tongue-twister.txt"
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description="Simple TTS - machine learning text-to-speech for your terminal", allow_abbrev=False) parser = argparse.ArgumentParser(description="Simple TTS - machine learning text-to-speech for your terminal", allow_abbrev=False)
@ -59,7 +59,7 @@ def parse_args():
"-i", "-i",
required=False, required=False,
type=str, type=str,
default=demo_file, default=installed_demo_file,
help = "path to the input text file", help = "path to the input text file",
) )
parser.add_argument( parser.add_argument(
@ -169,10 +169,25 @@ def main():
else: else:
cwd = os.getcwd() cwd = os.getcwd()
file_path = os.path.join(cwd, args.input_file) file_path = os.path.join(cwd, args.input_file)
is_default = file_path == installed_demo_file
default_exists = is_default and os.path.isfile(file_path)
if is_default:
print(f"No input provided.")
if not default_exists:
script_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(script_dir, 'demo/tongue-twister.txt')
print(f"Using demo file: {file_path}")
if os.path.isfile(file_path):
directory, file_name = os.path.split(file_path) directory, file_name = os.path.split(file_path)
name = '.'.join(file_name.split('.')[:-1]) name = '.'.join(file_name.split('.')[:-1])
file = open(file_path, "r") file = open(file_path, "r")
text = file.read() text = file.read()
else:
print("not a file", file_path)
exit()
else: else:
name = "chat" name = "chat"
text = args.input_text text = args.input_text