장재혁

change py-file name

from flask import Flask, request, send_file
from extract_feature4 import extract
from verification4_merge import load_model, load_enroll_embeddings,perform_verification
from identification4 import perform_identification
from enroll4_merge import split_enroll_and_test,enroll_per_spk
from extract_server import extract
from verification_server import load_model, load_enroll_embeddings, perform_verification
from identification_server import perform_identification
from enroll_server import split_enroll_and_test, enroll_per_spk
import os
import shutil
app = Flask(__name__)
log_dir = '../new_model4_merge' # Where the checkpoints are saved
embedding_dir = '../enroll_embeddings4_merge' # Where embeddings are saved
test_dir = '../feat_logfbank_nfilt40/test/' # Where test features are saved
log_dir = '../new_model4_merge' # Where the checkpoints are saved
embedding_dir = '../enroll_embeddings4_merge' # Where embeddings are saved
test_dir = '../feat_logfbank_nfilt40/test/' # Where test features are saved
# Settings
use_cuda = True # Use cuda or not
embedding_size = 128 # Dimension of speaker embeddings
cp_num = 50 # Which checkpoint to use?
n_classes = 348 # How many speakers in training data?
test_frames = 100 # Split the test utterance
# Settings
use_cuda = True # Use cuda or not
embedding_size = 128 # Dimension of speaker embeddings
cp_num = 50 # Which checkpoint to use?
n_classes = 348 # How many speakers in training data?
test_frames = 100 # Split the test utterance
model = load_model(use_cuda, log_dir, cp_num, embedding_size, n_classes)
embeddings = load_enroll_embeddings(embedding_dir)
......@@ -31,21 +31,23 @@ def enrollment():
enroll_DB, test_DB = split_enroll_and_test(test_dir)
enroll_per_spk(use_cuda, test_frames, model, enroll_DB, embedding_dir)
embeddings = load_enroll_embeddings(embedding_dir)
except Exception as e:
print(e)
def verification(enroll_speaker):
test_speaker = 'TEST_SPEAKER'
test_speaker = 'TEST_SPEAKER'
thres = 0.95
# Perform the test
return perform_verification(use_cuda, model, embeddings, enroll_speaker, test_path, test_frames, thres)
def identification():
best_spk = perform_identification(use_cuda, model, embeddings, test_path, test_frames, spk_list)
return best_spk
# Perform the test
return perform_verification(use_cuda, model, embeddings, enroll_speaker,
test_path, test_frames, thres)
def identification():
best_spk = perform_identification(use_cuda, model, embeddings, test_path,
test_frames, spk_list)
return best_spk
@app.route('/enroll', methods=['POST', "GET"])
......@@ -55,10 +57,10 @@ def enroll_controller():
enroll_speaker = request.form['enroll_speaker']
print(f.name)
f.save('./myrequest_enroll.wav')
extract('./myrequest_enroll.wav',enroll_speaker)
new_path = '../feat_logfbank_nfilt40/test/'+enroll_speaker+'/'
extract('./myrequest_enroll.wav', enroll_speaker)
new_path = '../feat_logfbank_nfilt40/test/' + enroll_speaker + '/'
os.mkdir(new_path)
shutil.move('./enroll.p',new_path+'enroll.p')
shutil.move('./enroll.p', new_path + 'enroll.p')
try:
enrollment()
......@@ -66,13 +68,11 @@ def enroll_controller():
return 'enroll_complete'
except:
return 'failed'
#return 'post'
return 'get'
@app.route('/verification', methods=['POST', "GET"])
def verfication_controller():
if request.method == 'POST':
......@@ -82,11 +82,12 @@ def verfication_controller():
f.save('./myrequest.wav')
extract('./myrequest.wav')
speak, score = verification(enroll_speaker)
return score
return score
#return 'post'
return 'get'
@app.route('/identification', methods=['POST', "GET"])
def identification_controller():
if request.method == 'POST':
......@@ -100,14 +101,16 @@ def identification_controller():
#return 'post'
return 'get'
@app.route('/debugger', methods=['GET'])
def debugger():
def debugger():
return anything
@app.route('/robots.txt',methods=['GET'])
@app.route('/robots.txt', methods=['GET'])
def antirobot():
return send_file('robots.txt')
if __name__ == '__main__':
app.run(host='0.0.0.0', port="7777", debug=True)
......
import librosa
import numpy as np
from python_speech_features import fbank
import pickle
sample_rate=16000
#filename='./sunghwan/8sec2.wav'
def normalize_frames(m,Scale=True):
if Scale:
return (m - np.mean(m, axis=0)) / (np.std(m, axis=0) + 2e-12)
else:
return (m - np.mean(m, axis=0))
def extract(filename,savename='test.p'):
audio, sr = librosa.load(filename, sr=sample_rate, mono=True)
filter_banks, energies = fbank(audio, samplerate=sample_rate, nfilt=40, winlen=0.025)
filter_banks = 20 * np.log10(np.maximum(filter_banks,1e-5))
feature = normalize_frames(filter_banks, Scale=False)
label = savename.split('.')[0]
todump = {'feat': feature, 'label': label}
with open(savename,'wb') as f:
pickle.dump(todump,f)