Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-2-capstone-design1
/
LYG_project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
장재혁
2020-12-11 10:50:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c5747087b94f9d3ad00e4672cda2816d7419fad9
c5747087
1 parent
92577e50
change py-file name
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
54 deletions
source/server/app.py
source/server/enroll4_merge.py → source/server/enroll_server.py
source/server/extract_feature.py
source/server/extract_feature4.py → source/server/extract_server.py
source/server/identification4.py → source/server/identification_server.py
source/server/verification4_merge.py → source/server/verification_server.py
source/server/app.py
View file @
c574708
from
flask
import
Flask
,
request
,
send_file
from
extract_
feature4
import
extract
from
verification
4_merge
import
load_model
,
load_enroll_embeddings
,
perform_verification
from
identification
4
import
perform_identification
from
enroll
4_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
)
...
...
source/server/enroll
4_merge
.py
→
source/server/enroll
_server
.py
View file @
c574708
File moved
source/server/extract_feature.py
deleted
100755 → 0
View file @
92577e5
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
)
source/server/extract_
feature4
.py
→
source/server/extract_
server
.py
View file @
c574708
File moved
source/server/identification
4
.py
→
source/server/identification
_server
.py
View file @
c574708
File moved
source/server/verification
4_merge
.py
→
source/server/verification
_server
.py
View file @
c574708
File moved
Please
register
or
login
to post a comment