장재혁

change py-file name

1 from flask import Flask, request, send_file 1 from flask import Flask, request, send_file
2 -from extract_feature4 import extract 2 +from extract_server import extract
3 -from verification4_merge import load_model, load_enroll_embeddings,perform_verification 3 +from verification_server import load_model, load_enroll_embeddings, perform_verification
4 -from identification4 import perform_identification 4 +from identification_server import perform_identification
5 -from enroll4_merge import split_enroll_and_test,enroll_per_spk 5 +from enroll_server import split_enroll_and_test, enroll_per_spk
6 import os 6 import os
7 import shutil 7 import shutil
8 8
...@@ -11,7 +11,7 @@ log_dir = '../new_model4_merge' # Where the checkpoints are saved ...@@ -11,7 +11,7 @@ log_dir = '../new_model4_merge' # Where the checkpoints are saved
11 embedding_dir = '../enroll_embeddings4_merge' # Where embeddings are saved 11 embedding_dir = '../enroll_embeddings4_merge' # Where embeddings are saved
12 test_dir = '../feat_logfbank_nfilt40/test/' # Where test features are saved 12 test_dir = '../feat_logfbank_nfilt40/test/' # Where test features are saved
13 13
14 - # Settings 14 +# Settings
15 use_cuda = True # Use cuda or not 15 use_cuda = True # Use cuda or not
16 embedding_size = 128 # Dimension of speaker embeddings 16 embedding_size = 128 # Dimension of speaker embeddings
17 cp_num = 50 # Which checkpoint to use? 17 cp_num = 50 # Which checkpoint to use?
...@@ -35,19 +35,21 @@ def enrollment(): ...@@ -35,19 +35,21 @@ def enrollment():
35 except Exception as e: 35 except Exception as e:
36 print(e) 36 print(e)
37 37
38 +
38 def verification(enroll_speaker): 39 def verification(enroll_speaker):
39 test_speaker = 'TEST_SPEAKER' 40 test_speaker = 'TEST_SPEAKER'
40 thres = 0.95 41 thres = 0.95
41 # Perform the test 42 # Perform the test
42 - return perform_verification(use_cuda, model, embeddings, enroll_speaker, test_path, test_frames, thres) 43 + return perform_verification(use_cuda, model, embeddings, enroll_speaker,
44 + test_path, test_frames, thres)
45 +
43 46
44 def identification(): 47 def identification():
45 - best_spk = perform_identification(use_cuda, model, embeddings, test_path, test_frames, spk_list) 48 + best_spk = perform_identification(use_cuda, model, embeddings, test_path,
49 + test_frames, spk_list)
46 return best_spk 50 return best_spk
47 51
48 52
49 -
50 -
51 @app.route('/enroll', methods=['POST', "GET"]) 53 @app.route('/enroll', methods=['POST', "GET"])
52 def enroll_controller(): 54 def enroll_controller():
53 if request.method == 'POST': 55 if request.method == 'POST':
...@@ -55,10 +57,10 @@ def enroll_controller(): ...@@ -55,10 +57,10 @@ def enroll_controller():
55 enroll_speaker = request.form['enroll_speaker'] 57 enroll_speaker = request.form['enroll_speaker']
56 print(f.name) 58 print(f.name)
57 f.save('./myrequest_enroll.wav') 59 f.save('./myrequest_enroll.wav')
58 - extract('./myrequest_enroll.wav',enroll_speaker) 60 + extract('./myrequest_enroll.wav', enroll_speaker)
59 - new_path = '../feat_logfbank_nfilt40/test/'+enroll_speaker+'/' 61 + new_path = '../feat_logfbank_nfilt40/test/' + enroll_speaker + '/'
60 os.mkdir(new_path) 62 os.mkdir(new_path)
61 - shutil.move('./enroll.p',new_path+'enroll.p') 63 + shutil.move('./enroll.p', new_path + 'enroll.p')
62 64
63 try: 65 try:
64 enrollment() 66 enrollment()
...@@ -67,12 +69,10 @@ def enroll_controller(): ...@@ -67,12 +69,10 @@ def enroll_controller():
67 except: 69 except:
68 return 'failed' 70 return 'failed'
69 71
70 -
71 #return 'post' 72 #return 'post'
72 return 'get' 73 return 'get'
73 74
74 75
75 -
76 @app.route('/verification', methods=['POST', "GET"]) 76 @app.route('/verification', methods=['POST', "GET"])
77 def verfication_controller(): 77 def verfication_controller():
78 if request.method == 'POST': 78 if request.method == 'POST':
...@@ -87,6 +87,7 @@ def verfication_controller(): ...@@ -87,6 +87,7 @@ def verfication_controller():
87 #return 'post' 87 #return 'post'
88 return 'get' 88 return 'get'
89 89
90 +
90 @app.route('/identification', methods=['POST', "GET"]) 91 @app.route('/identification', methods=['POST', "GET"])
91 def identification_controller(): 92 def identification_controller():
92 if request.method == 'POST': 93 if request.method == 'POST':
...@@ -100,14 +101,16 @@ def identification_controller(): ...@@ -100,14 +101,16 @@ def identification_controller():
100 #return 'post' 101 #return 'post'
101 return 'get' 102 return 'get'
102 103
104 +
103 @app.route('/debugger', methods=['GET']) 105 @app.route('/debugger', methods=['GET'])
104 def debugger(): 106 def debugger():
105 return anything 107 return anything
106 108
107 -@app.route('/robots.txt',methods=['GET']) 109 +
110 +@app.route('/robots.txt', methods=['GET'])
108 def antirobot(): 111 def antirobot():
109 return send_file('robots.txt') 112 return send_file('robots.txt')
110 113
114 +
111 if __name__ == '__main__': 115 if __name__ == '__main__':
112 app.run(host='0.0.0.0', port="7777", debug=True) 116 app.run(host='0.0.0.0', port="7777", debug=True)
113 -
......
1 -import librosa
2 -import numpy as np
3 -from python_speech_features import fbank
4 -import pickle
5 -sample_rate=16000
6 -#filename='./sunghwan/8sec2.wav'
7 -
8 -def normalize_frames(m,Scale=True):
9 - if Scale:
10 - return (m - np.mean(m, axis=0)) / (np.std(m, axis=0) + 2e-12)
11 - else:
12 - return (m - np.mean(m, axis=0))
13 -
14 -def extract(filename,savename='test.p'):
15 - audio, sr = librosa.load(filename, sr=sample_rate, mono=True)
16 - filter_banks, energies = fbank(audio, samplerate=sample_rate, nfilt=40, winlen=0.025)
17 - filter_banks = 20 * np.log10(np.maximum(filter_banks,1e-5))
18 - feature = normalize_frames(filter_banks, Scale=False)
19 - label = savename.split('.')[0]
20 - todump = {'feat': feature, 'label': label}
21 - with open(savename,'wb') as f:
22 - pickle.dump(todump,f)
23 -
24 -