Skip to content

Instantly share code, notes, and snippets.

# 在末尾加上,显示当前在第几个窗口。
caption always "%{= kw}%-w%{= kG}%{+b}[%n %t]%{-b}%{= kw}%+w %=%d %M %0c %{g}%H%{-}"
@aqzlpm11
aqzlpm11 / string_enum.cpp
Last active July 11, 2017 11:55
C++: string enum
/////////// self defined ENUM_STR, have a string val
#define ENUM_STR_BEGIN(type_name) \
class type_name { \
std::string v; \
public: \
static std::set<std::string>* vals() { static std::set<std::string> s; return &s; }\
type_name(const std::string& a): v(a){} \
std::string toString() { return v; } \
bool isValid() { return vals()->find(v) != vals()->end(); }
@aqzlpm11
aqzlpm11 / performance_analyse.py
Last active July 16, 2017 08:01
python: performance analysing example.
#encoding=utf-8
import cProfile
import pstats
def fun():
return sum([i for i in range(10000000)])
if __name__ == "__main__":
cProfile.run('fun()', "result")
@aqzlpm11
aqzlpm11 / lcs.py
Created June 28, 2017 09:33
python: Longest common subsequence (LCS) algorithm
from functools import lru_cache
@lru_cache(maxsize=2**20)
def LCS(a, b):
""" Longest common subsequence """
if len(a) == 0 or len(b) == 0:
return 0
res = max(
@aqzlpm11
aqzlpm11 / vad.py
Last active April 20, 2021 13:52
python: vad script
import bob.io.audio
import bob.kaldi # https://www.idiap.ch/software/bob/docs/bob/docs/stable/bob/doc/install.html
import matplotlib.pyplot as plt
def vad(sig, sr, vad_energy_mean_scale=0.5, vad_energy_th=9, vad_frames_context=20, vad_proportion_th=0.4):
""" Energy Based Voice Activate Detection algorithm. (based on kaldi)
Param:
sig: list or np.array
the signal, list of samples
sr: int
@aqzlpm11
aqzlpm11 / cooledit2_labelling_helper.py
Created July 9, 2017 06:43
python: cooledit2_labelling_helper. 把所有的wav合成一个,做好标记后,再分开。
import librosa
import wave
from pathlib import Path
import numpy as np
import os
all_in_one_wav = "@all_in_one.wav"
all_in_one_wav_info = "@all_in_one.txt"
all_in_one_label = "@all_in_one_vad.txt"
label_file = "@label.txt"
@aqzlpm11
aqzlpm11 / pcm2wav.py
Last active March 26, 2020 08:19
python: pcm2wav. 给pcm加上wav的头
import wave
import os
def is_wav(f):
res = True
try:
wave.open(f)
except wave.Error as e:
res = False
@aqzlpm11
aqzlpm11 / python_like.h
Created July 16, 2017 07:56
c++: python_like code in c++. 在C++中以python的方式写部分代码
#ifndef __PYTHON_LIKE__
#define __PYTHON_LIKE__
#include <stdio.h>
#include <string>
#include <fstream>
#include <streambuf>
#include <vector>
#include <iostream>
#include <stdarg.h>
@aqzlpm11
aqzlpm11 / ping_all.py
Last active July 26, 2017 13:12
python: explore available ips in the LAN
# coding=utf-8
import os
from multiprocessing.dummy import Pool
def can_ping(ip):
ret = os.system('ping -n 1 -w 1 %s > nul' % ip)
can_ping = True if ret == 0 else False
return can_ping, ip
@aqzlpm11
aqzlpm11 / cal_eer.py
Last active May 31, 2022 04:17
python: ROC curve, EER. (algorithm)
from sklearn import metrics
from scipy.optimize import brentq
from scipy.interpolate import interp1d
def cal_eer(score_true, score_false):
""" 计算EER
Args:
scores_true: 正样例的分数列表
scores_false: 负样例的分数列表