def compare_urls(): UPLOAD_FOLDER = './Unknown/' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER sourceDir = "./Unknown/" destDir = "./Unknown/" trainSourceDir="./uploads/" chunk_length_ms = 1000 if request.method == 'POST': uploaded_files=[] urlnames = [] urlnames.append(request.form['filelink1']) convertedFileName = convertURLToFile(urlnames[0]) uploaded_files.append(convertedFileName) urlnames.append(request.form['filelink2']) convertedFileName = convertURLToFile(urlnames[1]) uploaded_files.append(convertedFileName) for filename in uploaded_files: isMP3 = False if filename.endswith(".mp3"): isMP3 = True #file.save(os.path.join('Unknown',secure_filename(file.filename))) #filenames.append(replace_filename) #Convert mp3 to wav and save to audio_sources with appended guid getWavfile(8000,1,filename,replace_filename,"./Unknown/","./Unknown/") audio_split(uploaded_files[0], isMP3 , sourceDir, chunk_length_ms) training_result = model_train(uploaded_files[0],trainSourceDir,destDir) audio_split(uploaded_files[1], isMP3 , sourceDir, chunk_length_ms) training_result = model_train(uploaded_files[1],trainSourceDir,destDir) responseJson = {} appurl = request.url.split("/compare") if training_result == "Modelling completed": print("*********",uploaded_files[1]) flag, _similarityProbScore, _compareMatch = compare_test(uploaded_files,sourceDir,destDir) responseJson = {} confidenceThreshold = 0.75 if(_similarityProbScore == 1): responseJson = jsonify( status = 200, message = _compareMatch ) else: responseJson = jsonify( status = 200, message = _compareMatch, similarityProbScore =format(_similarityProbScore, '.8f') ) return responseJson return '''
def upload_file(): UPLOAD_FOLDER = './audio_sources/' #app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER sourceDir = "./uploads/" destDir = "./Speakers_models/" wavSourceDir = "./audio_sources/" chunk_length_ms = 3000 if request.method == 'POST': file = request.files['file'] personname = request.form['personname'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) guid = str(uuid.uuid1()).replace("-", "") replace_filename = str(personname).replace( " ", "") + '-' + str(guid) + '.wav' isMP3 = False print("@@@@@@@@", replace_filename) if filename.endswith(".mp3"): isMP3 = True file.save( os.path.join('audio_sources', secure_filename(file.filename))) #Convert mp3 to wav and save to audio_sources with appended guid getWavfile(8000, 1, filename, replace_filename, "./audio_sources/", "./audio_sources/") else: file.save( os.path.join('audio_sources', secure_filename(file.filename))) #Save the uploaded wav file to audio_sources with appended guid os.rename('./audio_sources/' + filename, './audio_sources/' + replace_filename) #rename file name #os.rename('./audio_sources/' + filename, './audio_sources/' + replace_filename) audio_split(replace_filename, isMP3, wavSourceDir, chunk_length_ms) training_result = model_train(replace_filename, sourceDir, destDir) responseJson = {} appurl = request.url.split("/upload") if training_result == "Modelling completed": responseJson = jsonify(status=200, message="Enrollment Successful", guid=str(guid), name=personname, link=appurl[0] + "/audiofile/" + replace_filename) else: responseJson = jsonify(status=500, message="Enrollment Failed", guid=str(guid), name=personname) return responseJson return '''
def compare_files(): UPLOAD_FOLDER = './Unknown/' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER sourceDir = "./Unknown/" destDir = "./Unknown/" trainSourceDir="./uploads/" chunk_length_ms = 1000 if request.method == 'POST': uploaded_files = request.files.getlist("file[]") filenames = [] for file in uploaded_files: if file and allowed_file(file.filename): filename = secure_filename(file.filename) guid = str(uuid.uuid1()).replace("-", "") replace_filename = str(filename.split(".wav")[0]).replace(" ", "") + '-' + str(guid) + '.wav' isMP3 = False if filename.endswith(".mp3"): isMP3 = True file.save(os.path.join('Unknown',secure_filename(file.filename))) filenames.append(replace_filename) #Convert mp3 to wav and save to audio_sources with appended guid getWavfile(8000,1,filename,replace_filename,"./Unknown/","./Unknown/") else: file.save(os.path.join('Unknown',secure_filename(file.filename))) filenames.append(replace_filename) #Save the uploaded wav file to audio_sources with appended guid os.rename('./Unknown/' + filename, './Unknown/' + replace_filename) #rename file name #os.rename('./audio_sources/' + filename, './audio_sources/' + replace_filename) print("*******",filenames) audio_split(filenames[0], isMP3 , sourceDir, chunk_length_ms) training_result = model_train(filenames[0],trainSourceDir,destDir) audio_split(filenames[1], isMP3 , sourceDir, chunk_length_ms) training_result = model_train(filenames[1],trainSourceDir,destDir) responseJson = {} appurl = request.url.split("/compare") if training_result == "Modelling completed": print("*********",filenames[1]) flag, _similarityProbScore, _compareMatch = compare_test(filenames,sourceDir,destDir) responseJson = {} confidenceThreshold = 0.75 if(_similarityProbScore == 1): responseJson = jsonify( status = 200, message = _compareMatch ) else: responseJson = jsonify( status = 200, message = _compareMatch, similarityProbScore =format(_similarityProbScore, '.8f') ) return responseJson return '''