Files
aladeen/args.py
2026-03-30 15:21:29 +01:00

72 lines
2.4 KiB
Python

import os
import json
def handle_arguments(arguments, config, engine):
for index, arg in enumerate(arguments[1:]):
match arg:
case '--wpm'|'-w':
config['wpm'] = int(arguments[index+2])
case '--language'|'-l':
config['language'] = arguments[index+2]
case '--voice'|'-v':
config['voice'] = arguments[index+2]
case '--mode'|'-m':
config['mode'] = arguments[index+2]
case '--words'|'-o':
config['words'] = int(arguments[index+2])
case '--time'|'-t':
config['time'] = int(arguments[index+2])
case '--filename'|'-f':
config['filename'] = arguments[index+2]
case '--quote'|'-q':
config['quoteid'] = int(arguments[index+2])
case '--list-languages'|'-i':
languages = os.listdir('languages')
for lang in languages:
print(lang.replace('.json',''))
exit()
case '--list-quotes'|'-u':
with open(f'quotes/{config['language']}.json') as file:
quotes = json.load(file)
for index,quote in enumerate(quotes):
print(f'{index}: {quote['quote']} - {quote['author']}')
exit()
case '--list-voices'|'-c':
voices = engine.getProperty('voices')
for voice in voices:
print(voice)
exit()
case '--help'|'h':
print('''Command line options
All these options overide configuration in config.json
c,f,h,i,l,m,o,q,t,u,v,w
--wpm, -w <int>
set the rate of dictation, defaults to 50, note: this is not exact as it measures the time between words in order to avoid a very short gap after a long word.
--mode, -m <mode>
Sets a mode, one of 'timed', 'words','quote' or 'file' followed by an optional modifier representing either the time (in seconds) or the number of words, or the quote ID, or the file name.
--filename, -f <filename>
Passes a filename as parameter for the file mode
--words, -o <number of words>
Number of words for words mode
--time, -t <time>
Time in seconds for timed mode
--quote, -q <time>
Specify a quote ID for quotes mode, see all quotes in your selected language with -u
--language, -l <language>
Selects a language, defaults to english, must be a listed language in -i
--voice, -v <voice id>
Selects a voice to use, defaults to gwm/en in config.json
--list-voices, -c
Lists all the available voices you can use, also see [voices.txt](voices.txt)
--list-quotes, -u
Lists the available quotes and exits
--list-languages, -i
Lists the installed languages and exits
--help, -h
Output's this help text and exits
''')
exit()
case _:
continue
return config