import pyttsx3 import time import json import time import random import maths def words(config): engine = pyttsx3.init() words_list = [] with open(f'languages/{config['language']}.json', 'r') as file: dump = json.load(file) words_list = dump['words'] dictation = [] for i in range(0, config['mode_modifier']): word = words_list[maths.biased_random(len(words_list)-1)] dictation.append(word) print(word,end=' ') for word in dictation: engine.say(word) engine.runAndWait() time.sleep(1/(config['wpm']/60)) def timed(config): engine = pyttsx3.init() words_list = [] with open(f'languages/{config['language']}.json', 'r') as file: dump = json.load(file) words_list = dump['words'] # For keeping track of time start = time.time() while 1==1: word = words_list[maths.biased_random(len(words_list)-1)] engine.say(word) print(f'{word} ') engine.runAndWait() time.sleep(1/(config['wpm']/60)) # check if too much time has elapsed for mode: time now = time.time() # Break condition if (now-start) > config['mode_modifier']: break def quote(config): engine = pyttsx3.init() with open(f'quotes/{config['language']}.json', 'r') as file: quotes = json.load(file) if 'mode_modifier' in config: quote = quotes[config['mode_modifier']] else: x = random.randint(0, len(quotes)-1) quote = quotes[x] print(f'{quote['quote']}\n\t\t\t - {quote['author']}') dictation = quote['quote'].split(' ') for word in dictation: engine.say(word) engine.runAndWait() time.sleep(1/(config['wpm']/60)) def file(config): engine = pyttsx3.init() with open(f'{config['mode_modifier']}', 'r') as file: lines = file.readlines() for line in lines: for word in line.split(' '): print(word,end=' ') engine.say(word) engine.runAndWait() time.sleep(1/(config['wpm']/60))