def main(): MODE = 'TIMIT' # 加载参数 args = get_option(MODE) speaker_cfg = args.speaker_cfg # speaker recognition识别的网络模型的配置参数 args_speaker = read_conf(speaker_cfg, deepcopy(args)) args_speaker.model_path = args.speaker_model print(args_speaker.model_path) pretrained_models = get_pretrained_models(args_speaker) # 读取数据 speak_file = r'DR1/FCJF0/SA2.WAV.wav' real_data, fs = sf.read(speak_file) # 输出说话人的真实标签 # 主要输入要小写 print("当前人的人名:", speak_file.split('/')[1].lower()) print("当前人的label:", get_label_by_name('FCJF0'.lower())) # 归一化数据 real_data_norm = real_data / np.abs(real_data).max() # 计算预测值,预测值是个标签 pred_real, pred_pro = sentence_test( pretrained_models['speaker'].eval(), torch.from_numpy(real_data_norm).float().cuda().unsqueeze(0)) print("预测的label:", pred_real) print("根据预测的label获得的人名:", get_name_by_label(pred_real)) print(pred_pro.shape)
def to_excerpt_dict(self): return { 'name': self.name, 'category': self.category.name, 'tags': [x.name for x in self.tags], 'updated': rfc3339(self.updated), 'excerpt': self.text[:option.get_option(Config.excerptLength)] }
def get_speaker_model(MODE): args = get_option(MODE) speaker_cfg = args.speaker_cfg # speaker recognition识别的网络模型的配置参数 args_speaker = read_conf(speaker_cfg, deepcopy(args)) args_speaker.model_path = args.speaker_model print(args_speaker.model_path) pretrained_models = get_pretrained_models(args_speaker) return pretrained_models['speaker']
def post(): try: option.get_option(Site.title) abort(410) except NotInitializedError as e: # database not set up properly, ok to do OOBE # set up database from models.AboutPage import AboutPage # add options option.set_option(Config.username, request.json['username']) option.set_option(Config.passwordHash, generate_password_hash(request.json['password'])) option.set_option(Config.captcha, request.json['captcha']) BlogMeta.from_dict(request.json['blogMeta']).write_to_options() # noinspection PyArgumentList db.session.add(AboutPage(text=request.json['aboutPage']['text'])) db.session.commit() return api_jsonify(payload=None)
def get(): if not option.get_option(Config.captcha): abort(404) answer = ''.join([choice(alphabet) for i in range(4)]) captcha = ImageCaptcha().generate_image(answer) buf = BytesIO() captcha.save(buf, format='GIF') b64_payload = b64encode(buf.getvalue()) payload = { 'image': 'data:image/gif;base64,' + b64_payload.decode('ascii'), 'answer_enc': jwt_encode(interval=timedelta(minutes=5), data={'answer': answer}) } return api_jsonify(payload)
def load_from_options(): return BlogMeta(site_title_=option.get_option(Site.title), author_=option.get_option(Site.author), contact_=option.get_option(Site.contact), friends_=option.get_option(Site.friends), description_=option.get_option(Site.description))
def get(): try: option.get_option(Site.title) abort(410) except NotInitializedError as e: # database not set up properly, ok to do OOBE return '', 204
def jwt_auth(token): try: return jwt_decode(token, audience=get_option(Config.username)) except InvalidTokenError as e: raise Unauthorized from e
def basic_auth(username, password, required_scopes): if option.get_option(Config.username) != username \ or not check_password_hash(option.get_option(Config.passwordHash), password): return None else: return {'sub': username}
def wrapped_func(*args, **kwargs): if get_option(Config.captcha) and\ not check_captcha(request.json.get('captcha')): abort(403, 'bad captcha') return func(*args, **kwargs)