Answer the question
In order to leave comments, you need to log in
How to simplify (optimize) the code in the voice assistant in pythone?
Hello, help me simplify the code.
I have a JSON file that stores answers to questions
dicts = open('body.json', 'r')
opening = json.load(dicts)
radiant0 = random.choice(opening["привет"])
radiant1 = random.choice(opening["как дела"])
value0 = radiant0
value1 = radiant1
alisa0 = 'echo '+value0+'|RHVoice-test -p anna'
subprocess.call(alisa0, shell=True)
alisa1 = 'echo ' + value1 + '|RHVoice-test -p anna'
subprocess.call(alisa1, shell=True)
Answer the question
In order to leave comments, you need to log in
what can I do so that I don’t write a lot of these variables like value0,1 and randiant0
subprocess.call('echo '+random.choice(opening["привет"])+'|RHVoice-test -p anna', shell=True)
subprocess.call('echo '+random.choice(opening["как дела"])+'|RHVoice-test -p anna', shell=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question