<commit_before>import shutil
import uuid
import os, os.path
from piwho import recognition

MAX_RECOGNISE_RATE = 0.40

rc = recognition.SpeakerRecognizer()

rc.train_new_data('./records/majid', 'majid')
rc.train_new_data('./records/abi', 'abi')
rc.train_new_data('./records/adela', 'adela')

def recognise_voice(filename):
    name = rc.identify_speaker(filename)
    scores = rc.get_speaker_scores()
    best = 1.0
    name = None
    for key in scores:
        rate = float(scores.get(key))
        if rate < best:
            best = rate
            name = key
    if rate > MAX_RECOGNISE_RATE:
        return None
    return dict(name=name, rate=rate)

def collect(id, filename):
    filecount = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join('./records/{}/'.format(id), name))])
    p, e, = filename.split('.')
    shutil.copy(filename, './records/{}/sample-{}.{}'.format(id, filecount, e))<commit_msg>Sample recording<commit_after>import shutil
import uuid
import os, os.path
from piwho import recognition

MAX_RECOGNISE_RATE = 0.40

rc = recognition.SpeakerRecognizer()

rc.train_new_data('./records/majid', 'majid')
rc.train_new_data('./records/abi', 'abi')
rc.train_new_data('./records/adela', 'adela')

def recognise_voice(filename):
    name = rc.identify_speaker(filename)
    scores = rc.get_speaker_scores()
    best = 1.0
    name = None
    for key in scores:
        rate = float(scores.get(key))
        if rate < best:
            best = rate
            name = key
    if rate > MAX_RECOGNISE_RATE:
        return None
    return dict(name=name, rate=rate)

def collect(id, filename):
    outpath = './records/{}/'.format(id)
    filecount = len([name for name in os.listdir(outpath) if os.path.isfile(os.path.join(outpath, name))])
    p, e, = filename.split('.')
    shutil.copy(filename, '{}sample-{}.{}'.format(outpath, filecount, e))
{'fraction_non_alphanumeric': 0.14741883980840872, 'fraction_numerical': 0.005321979776476849, 'mean_word_length': 3.32183908045977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '449306', 'n_tokens_mistral': 657, 'n_tokens_neox': 640, 'n_words': 144}