2022-01-30 15:47:24 +01:00
|
|
|
import argparse, json, sys, time, random
|
|
|
|
|
import spacy
|
|
|
|
|
from aitextgen import aitextgen
|
2022-02-26 15:28:46 +01:00
|
|
|
import string
|
2022-01-30 15:47:24 +01:00
|
|
|
|
2022-02-26 15:28:46 +01:00
|
|
|
def clean(text: str) -> str:
|
|
|
|
|
|
|
|
|
|
s = text.split('\n')
|
|
|
|
|
|
|
|
|
|
if(len(s) > 0):
|
|
|
|
|
tok_1 = s[0].split(' ')
|
|
|
|
|
if len(tok_1) > 0 and tok_1[0].strip() in string.punctuation:
|
|
|
|
|
s_1 = ' '.join(tok_1[1:])
|
|
|
|
|
s[0] = s_1.capitalize()
|
|
|
|
|
else:
|
|
|
|
|
s[0] = s[0].capitalize()
|
|
|
|
|
|
|
|
|
|
return '\n'.join(s)
|
|
|
|
|
|
|
|
|
|
def format(text: str) -> str:
|
|
|
|
|
|
|
|
|
|
return text.replace('\r\n', '\n').replace('\n\n', '\n')
|
|
|
|
|
|
2022-01-30 15:47:24 +01:00
|
|
|
def main() -> int:
|
|
|
|
|
|
|
|
|
|
p = argparse.ArgumentParser()
|
|
|
|
|
p.add_argument("-c", "--config", type=str, default="config.json", help="configuratin file")
|
|
|
|
|
p.add_argument("-i", "--iterations", type=int, default=10, help="number of iterations")
|
|
|
|
|
args = p.parse_args()
|
|
|
|
|
|
|
|
|
|
print(args)
|
|
|
|
|
|
|
|
|
|
with open(args.config) as f:
|
|
|
|
|
conf = json.load(f)
|
|
|
|
|
|
|
|
|
|
voices = []
|
|
|
|
|
for v in conf['voices']:
|
|
|
|
|
a = aitextgen(model_folder=v['model_dir'], tokenizer_file=v['tokeniser_file'])
|
2022-02-26 15:28:46 +01:00
|
|
|
voices.append({"name": v["name"].upper(), "a": a, "temp": float(v["temperature"])})
|
2022-01-30 15:47:24 +01:00
|
|
|
|
|
|
|
|
nbr_voices = len(voices)
|
|
|
|
|
current_voice = ""
|
|
|
|
|
for i in range(args.iterations):
|
|
|
|
|
rindex = random.randint(0, nbr_voices - 1)
|
|
|
|
|
v = voices[rindex]
|
|
|
|
|
if v['name'] != current_voice:
|
|
|
|
|
print("==========")
|
|
|
|
|
print(v['name'] + ":")
|
|
|
|
|
current_voice = v['name']
|
2022-02-26 15:28:46 +01:00
|
|
|
t = v['a'].generate(n=1, max_lenght=32, temperature=v['temp'], return_as_list=True)[0]
|
|
|
|
|
if t != None:
|
|
|
|
|
t = clean(t)
|
|
|
|
|
t = format(t)
|
|
|
|
|
print(t)
|
2022-01-30 15:47:24 +01:00
|
|
|
|
2022-02-26 15:28:46 +01:00
|
|
|
time.sleep(4)
|
2022-01-30 15:47:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
sys.exit(main())
|