feat: if no input, try demo files
This commit is contained in:
parent
aa03f6ed21
commit
1180124740
1 changed files with 22 additions and 7 deletions
21
tts.py
21
tts.py
|
|
@ -42,8 +42,8 @@ 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"
|
||||
dir_path = os.path.expanduser('~')
|
||||
installed_demo_file = f"{dir_path}/.local/lib/simple-tts/demo/tongue-twister.txt"
|
||||
|
||||
def parse_args():
|
||||
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",
|
||||
required=False,
|
||||
type=str,
|
||||
default=demo_file,
|
||||
default=installed_demo_file,
|
||||
help = "path to the input text file",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
|
@ -169,10 +169,25 @@ def main():
|
|||
else:
|
||||
cwd = os.getcwd()
|
||||
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)
|
||||
name = '.'.join(file_name.split('.')[:-1])
|
||||
file = open(file_path, "r")
|
||||
text = file.read()
|
||||
else:
|
||||
print("not a file", file_path)
|
||||
exit()
|
||||
else:
|
||||
name = "chat"
|
||||
text = args.input_text
|
||||
|
|
|
|||
Loading…
Reference in a new issue