threaded
This commit is contained in:
parent
eaaf419614
commit
843b99a4f7
@ -1,10 +1,10 @@
|
||||
import argparse, json, sys, time, random, logging, signal
|
||||
import argparse, json, sys, time, random, logging, signal, threading
|
||||
import utterance.voice
|
||||
import utterance.utils
|
||||
import utterance.osc
|
||||
import examine.metric
|
||||
|
||||
UTTERANCE_LEN = 16
|
||||
UTTERANCE_LEN = 16 #<--------------- these should be in config
|
||||
NUM_METRIC_GEN = 50
|
||||
NUM_SAMPLE_VOICES = 3
|
||||
broadcast = None
|
||||
@ -57,6 +57,24 @@ def broadcast_utterance(v, utterance):
|
||||
broadcast.command('clear')
|
||||
time.sleep(2)
|
||||
|
||||
def find_candidates(v, uv_vec, voices, results):
|
||||
logging.info(f"LOOP::finding candidates")
|
||||
|
||||
start = time.time()
|
||||
candidates = random.sample(voices, NUM_SAMPLE_VOICES)
|
||||
for c in candidates:
|
||||
if exit:
|
||||
break
|
||||
if c == v:
|
||||
continue
|
||||
results += utter_n_vectorise_distance(c, NUM_METRIC_GEN, uv_vec)
|
||||
|
||||
results.sort(key=lambda t: t[0], reverse=True)
|
||||
|
||||
lapse = time.time() - start
|
||||
logging.info(f"LOOP::done - {lapse} secs")
|
||||
|
||||
|
||||
|
||||
def signal_terminate(signum, frame):
|
||||
global exit
|
||||
@ -117,23 +135,14 @@ def main() -> int:
|
||||
|
||||
while not exit:
|
||||
|
||||
results = []
|
||||
t = threading.Thread(target=find_candidates, args=[v, uv_vec, voices, results])
|
||||
t.start()
|
||||
|
||||
logging.info(f"LOOP::broadcasting {v.name}")
|
||||
broadcast_utterance(v, uv)
|
||||
|
||||
logging.info(f"LOOP::finding candidates")
|
||||
start = time.time()
|
||||
candidates = random.sample(voices, NUM_SAMPLE_VOICES)
|
||||
results = []
|
||||
for c in candidates:
|
||||
if exit:
|
||||
break
|
||||
if c == v:
|
||||
continue
|
||||
results += utter_n_vectorise_distance(c, NUM_METRIC_GEN, uv_vec)
|
||||
|
||||
results.sort(key=lambda t: t[0], reverse=True)
|
||||
lapse = time.time() - start
|
||||
logging.info(f"LOOP::done - {lapse} secs")
|
||||
t.join()
|
||||
|
||||
# ok here we need to randomise maybe...?!
|
||||
# ([d, t, v])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user