장재혁

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
......@@ -11,7 +11,7 @@ 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
# Settings
use_cuda = True # Use cuda or not
embedding_size = 128 # Dimension of speaker embeddings
cp_num = 50 # Which checkpoint to use?
......@@ -35,19 +35,21 @@ def enrollment():
except Exception as e:
print(e)
def verification(enroll_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)
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)
best_spk = perform_identification(use_cuda, model, embeddings, test_path,
test_frames, spk_list)
return best_spk
@app.route('/enroll', methods=['POST', "GET"])
def enroll_controller():
if request.method == 'POST':
......@@ -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()
......@@ -67,12 +69,10 @@ def enroll_controller():
except:
return 'failed'
#return 'post'
return 'get'
@app.route('/verification', methods=['POST', "GET"])
def verfication_controller():
if request.method == 'POST':
......@@ -87,6 +87,7 @@ def verfication_controller():
#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():
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)