def group_install(self, groups, exclude=[]): if self.rpmdb_fixed: raise Exception("Can't install anything after RPM DB was fixed") exclude_opts = ["--exclude=" + pkg for pkg in exclude] sh.run(self._yum_call() + exclude_opts + ["groupinstall"] + mklist(groups), env=self.yum_conf.env)
def run_combination(alg, num_flows, delay, rate, qsize): print( "running combination alg: {alg}, num_flows: {num_flows}, delay: {delay}, rate: {rate}, qsize: {qsize}" .format(alg=alg, num_flows=num_flows, delay=delay, rate=rate, qsize=qsize)) sh.run('''python3 scripts/run-fidelity-exp.py \ --outdir {alg}/{num_flows}/{delay}/{rate}/{qsize} \ --duration 15 \ --alg {alg} \ --scenario fixed \ --ipcs netlink \ --kernel \ --delay {delay} \ --rate {rate} \ --qsize {qsize} \ --iters 1 \ --num-flows {num_flows}'''.format(alg=alg, num_flows=num_flows, delay=delay, rate=rate, qsize=qsize), shell=True)
def plot(dest, algs_to_plot, scenarios_to_plot): print("Cwnd Evolution Plots") print("=========================") print("> Parsing logs") sh.run( 'python3 parse/parseCwndEvo.py {0}/* > {0}/cwndevo.log'.format(dest), shell=True) print("> Subsampling logs for plotting") sh.run( 'python3 parse/sampleCwndEvo.py {0}/cwndevo.log 1000 > {0}/cwndevo-subsampled.log' .format(dest), shell=True) print("> Plotting") for alg in algs_to_plot: for s in scenarios_to_plot: sh.run( './plot/cwnd-evo.r {0}/cwndevo-subsampled.log {1} {2} {0}/{1}-{2}-cwndevo.pdf' .format(dest, alg, s), shell=True) print("> wrote {0}/{1}-cwndevo.pdf".format(dest, alg)) print("Throughput-Delay CDF Plots") print("=========================") print("> Parsing logs") sh.run('python3 parse/parseTputDelayCdf.py {0}/* > {0}/tput-delay-cdf.log'. format(dest), shell=True) print("> Plotting") # all experiments combined, not separate sh.run( './plot/tput-delay-cdf.r {0}/tput-delay-cdf.log {0}/tput-cdf.pdf {0}/delay-cdf.pdf' .format(dest), shell=True) print("> wrote {0}/tput-cdf.pdf, {0}/delay-cdf.pdf".format(dest))
def convert(m4a_dir): path, filename, suffix = split(m4a_dir) mp3_dir = str(path) + "/" + str(filename) + ".mp3" cmd = "ffmpeg -v 5 -y -i " + m4a_dir + " -acodec libmp3lame -ac 2 -ab 192k " + mp3_dir sh.run(cmd) return mp3_dir
def cut(input_file, delimit_points): if len(delimit_points) <= 2: return name, suffix = split(input_file) for i in range(0, len(delimit_points) - 1): cmd = "ffmpeg -i " + input_file + " -acodec copy -ss " + str( delimit_points[i]) + " -to " + str( delimit_points[i + 1]) + " " + name + "_" + str(i) + "." + suffix sh.run(cmd)
def main(): mp3_file = "mp3/ezm150324.mp3" wav_dir = "wav" mfcc_dir = "feature/0324" sh.run("mkdir -p " + mfcc_dir) modi_file = "feature/0324_modi.txt" result_file = "result/0324.txt" mfcc_feat.run(mp3_file, wav_dir, mfcc_dir) modi_feat.run(mfcc_dir, modi_file)
def combine_results(alg, num_flows, delay, rate, qsize): sh.run( '''cp {alg}/{num_flows}/{delay}/{rate}/{qsize}/cubic-fixed-cwndevo.pdf \ fidelity-experiments/{alg}-{num_flows}-{delay}-{rate}-{qsize}-cwndevo.pdf''' .format(alg=alg, num_flows=num_flows, delay=delay, rate=rate, qsize=qsize), shell=True)
def install(self, packages, exclude=[]): if self.rpmdb_fixed: raise Exception("Can't install anything after RPM DB was fixed") exclude_opts = ["--exclude=" + pkg for pkg in exclude] sh.run( self._yum_call() + exclude_opts + ['install'] + mklist(packages), env=self.yum_conf.env, )
def install(self, packages, exclude = []): if self.rpmdb_fixed: raise Exception("Can't install anything after RPM DB was fixed") exclude_opts = ["--exclude=" + pkg for pkg in exclude] sh.run( self._yum_call() + exclude_opts + ['install'] + mklist(packages), env = self.yum_conf.env, )
def predict(features, model): net2 = torch.load(model) x = torch.from_numpy(features).float() x = Variable(torch.unsqueeze(x, dim=1), requires_grad=False) test_output, _ = net2(x) pred_y = torch.max(test_output, 1)[1].data.numpy().squeeze() # print(pred_y, 'prediction number') cmd = "rm -rf window/cnn_result.txt" sh.run(cmd) np.savetxt("window/cnn_result.txt", pred_y)
def run(number, num): cmd1 = "ffmpeg -i " + "Obama" + str( number) + ".mp4" + " -acodec copy -vn -ar 16000 " + "mp4/Obama" + str( num) + ".mp4" rs1 = sh.run(cmd1) cmd2 = "ffmpeg -i " + "mp4/Obama" + str( num) + ".mp4" + " -ar 16000 mp3/Obama" + str(num) + ".mp3" rs2 = sh.run(cmd2) cmd3 = "ffmpeg -i " + "mp3/Obama" + str( num) + ".mp3" + " -ar 16000 wav/Obama" + str(num) + ".wav" rs3 = sh.run(cmd3)
def cut(mp3_file, cut_point, wav_dir): for i in range(0, len(cut_point)): if i < len(cut_point) - 1: duration = cut_point[i+1] - cut_point[i] else: cmd = """./ffmpeg -i """ + mp3_file + """ 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'""" rs = sh.run(cmd, True) duration_in_s = rs.stdout() duration = int(float(duration_in_s)) - cut_point[i] cmd = "./ffmpeg -ss " + str(cut_point[i]) + " -t " + str(duration)+ " -i " + mp3_file + " " + wav_dir + "/" + str(i) + ".wav" sh.run(cmd)
def fix_rpmdb(self, expected_rpmdb_dir=None, db_load='db_load', rpm='rpm'): logger.info("fixing RPM database for guest") current_rpmdb_dir = rpm_mod.expandMacro('%{_dbpath}') if expected_rpmdb_dir is None: expected_rpmdb_dir = sh.run( [ 'python', '-c', 'import rpm; print rpm.expandMacro("%{_dbpath}")' ], chroot=self.chroot, pipe=sh.READ, env=self.yum_conf.env, ).strip() # input directory rpmdb_dir = os.path.join(self.chroot, current_rpmdb_dir.lstrip('/')) logger.info('converting "Packages" file') in_pkg_db = os.path.join(rpmdb_dir, 'Packages') tmp_pkg_db = os.path.join(expected_rpmdb_dir, 'Packages.tmp') out_pkg_db = os.path.join(expected_rpmdb_dir, 'Packages') out_command = sh.run( [db_load, tmp_pkg_db], chroot=self.chroot, pipe=sh.WRITE, env=self.yum_conf.env, ) bdb.db_dump(in_pkg_db, out_command) out_command.close() os.rename(os.path.join(self.chroot, tmp_pkg_db.lstrip('/')), os.path.join(self.chroot, out_pkg_db.lstrip('/'))) logger.info('removing all the files except "Packages"') for f in os.listdir(rpmdb_dir): if f in ('.', '..', 'Packages'): continue os.unlink(os.path.join(rpmdb_dir, f)) logger.info("running `rpm --rebuilddb'") sh.run( [rpm, '--rebuilddb'], chroot=self.chroot, env=self.yum_conf.env, ) if current_rpmdb_dir != expected_rpmdb_dir: # Red Hat under Debian; delete old directory (~/.rpmdb possibly) logger.info("removing old RPM DB directory: $TARGET%s", current_rpmdb_dir) shutil.rmtree( os.path.join(self.chroot, current_rpmdb_dir.lstrip('/'))) self.rpmdb_fixed = True
def predict(features_normalisation, model): net2 = torch.load(model) prediction_x1 = torch.from_numpy(features_normalisation).float() prediction_x = Variable(prediction_x1, requires_grad=False).type(torch.FloatTensor) prediction_output = net2(prediction_x.view(-1, 1, 13)) # prediction_output = net2(prediction_x.view(-1,1,12)) # 0 is Ba, 1 is Bm, 2 is Eg pred_y = torch.max(prediction_output, 1)[1].data.numpy().squeeze() print("predicition is ", pred_y) cmd = "rm -rf window/lstm_result.txt" sh.run(cmd) np.savetxt("window/lstm_result.txt", pred_y)
def run(mp3_file, wav_dir): print(mp3_file) cmd = """ffmpeg -i """ + mp3_file + """ 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'""" rs = sh.run(cmd, True) duration_in_s = rs.stdout() print(duration_in_s) print("total duration is " + duration_in_s + "s") step_s = 60 for i in range(0, int(float(duration_in_s)), step_s): wav_file = wav_dir + "/" + str(i) + ".wav" cmd = "ffmpeg -ss " + str(i) + " -t " + str( step_s) + " -i " + mp3_file + " -f wav " + wav_file sh.run(cmd) print("convert mp3 to wav finish, " + str(i))
def run(number, num): cmd1 = "ffmpeg -i " + "stream/Obama" + str( number) + ".mp4" + " -acodec copy -vn -ar 16000 " + "mp4/Obama" + str( num) + ".mp4" rs1 = sh.run(cmd1) cmd2 = "ffmpeg -i " + "mp4/Obama" + str( num) + ".mp4" + " -ar 16000 mp3/Obama" + str(num) + ".mp3" rs2 = sh.run(cmd2) cmd3 = "ffmpeg -i " + "mp3/Obama" + str( num) + ".mp3" + " -ar 16000 wav/Obama" + str(num) + ".wav" rs3 = sh.run(cmd3) cmd4 = "sox wav/Obama" + str(num) + ".wav " + "wav/Obama" + str( num) + "_.wav noisered ../noise/noise.prof 0.3" rs4 = sh.run(cmd4) cmd5 = "rm -rf wav/Obama" + str(num) + ".wav" rs5 = sh.run(cmd5)
def _apply_template(chart_path: str, namespace: str, helm_args: List[str], intermediate_file_path: str) -> None: logging.info('applying chart at %s in namespace %s', chart_path, namespace) sh.run_kubectl(['create', 'namespace', namespace]) yaml = sh.run( ['helm', 'template', chart_path, '--namespace', namespace, *helm_args], check=True).stdout kubectl.apply_text(yaml, intermediate_file_path=intermediate_file_path) wait.until_deployments_are_ready(namespace)
def run(mp3_file, wav_dir, mfcc_feat_dir): cmd = """./ffmpeg -i """ + mp3_file + """ 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'""" rs = sh.run(cmd, True) duration_in_s = rs.stdout() print "total duration is " + duration_in_s + "s" step_s = 600 for i in range(0, int(float(duration_in_s)), step_s): wav_file = wav_dir + "/" + str(i) + ".wav" mfcc_feat_file = mfcc_feat_dir + "/" + str(i) + ".txt" cmd = "./ffmpeg -ss " + str(i) + " -t " + str(step_s) + " -i " + mp3_file + " -f wav " + wav_file sh.run(cmd) print "convert mp3 to wav finish, " + str(i) # extract feature mfcc_feat(wav_file, mfcc_feat_file) # clean files cmd = "rm -rf " + wav_dir + "/*" sh.run(cmd)
def run(mp3_file, wav_dir, mfcc_feat_dir): cmd = """./ffmpeg -i """ + mp3_file + """ 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'""" rs = sh.run(cmd, True) duration_in_s = rs.stdout() print "total duration is " + duration_in_s + "s" step_s = 600 for i in range(0, int(float(duration_in_s)), step_s): wav_file = wav_dir + "/" + str(i) + ".wav" mfcc_feat_file = mfcc_feat_dir + "/" + str(i) + ".txt" cmd = "./ffmpeg -ss " + str(i) + " -t " + str( step_s) + " -i " + mp3_file + " -f wav " + wav_file sh.run(cmd) print "convert mp3 to wav finish, " + str(i) # extract feature mfcc_feat(wav_file, mfcc_feat_file) # clean files cmd = "rm -rf " + wav_dir + "/*" sh.run(cmd)
def read_audio(read_dir, sub_dirs, T_total, padding_dir, labels): for k, sub_dir in enumerate(sub_dirs): #print("label: %s" % (label)) print("sub_dir: %s" % (sub_dir)) for i, f in enumerate( glob.glob(read_dir + os.sep + sub_dir + os.sep + '*.wav')): # for each WAV file wavFile = f print wavFile waveFile_name = (os.path.splitext(wavFile)[0]).split(os.sep)[2] print waveFile_name quality = util.splitext(waveFile_name)[2] print quality # Read the wav file in_data, fs = librosa.load(wavFile) #print("fs is ",fs) #print("data is ", in_data) #print os.path.splitext(wavFile)[0] cmd = """ffmpeg -i """ + wavFile + """ 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'""" rs = sh.run(cmd, True) duration_in_wavFile = rs.stdout() print("the duration of wavfile is ", duration_in_wavFile) print type(duration_in_wavFile) if float(T_total) >= float(duration_in_wavFile): out_data = padding_audio(in_data, fs, T_total) # Save the output file for l in labels: if quality == l: out_wav = padding_dir + "/" + l + "/" + waveFile_name + ".wav" # if quality == "Eg": # out_wav = result_padding_dir +"/"+ eg_padding_dir +"/" +waveFile_name+".wav" librosa.output.write_wav(out_wav, out_data, fs) else: int_num = int(float(duration_in_wavFile) / T_total) + 1 number = float(duration_in_wavFile) % T_total print number, int_num if number != 0: T = T_total * int_num out_data = padding_audio(in_data, fs, T) for l in labels: if quality == l: out_wav = padding_dir + "/" + l + "/" + waveFile_name + ".wav" # if quality == "Eg": # out_wav = result_padding_dir +"/"+ eg_padding_dir +"/" +waveFile_name+".wav" librosa.output.write_wav(out_wav, out_data, fs)
def fix_rpmdb(self, expected_rpmdb_dir = None, db_load = 'db_load'): logger.info("fixing RPM database for guest") current_rpmdb_dir = rpm.expandMacro('%{_dbpath}') if expected_rpmdb_dir is None: expected_rpmdb_dir = sh.run( ['python', '-c', 'import rpm; print rpm.expandMacro("%{_dbpath}")'], chroot = self.chroot, pipe = sh.READ, env = self.yum_conf.env, ).strip() # input directory rpmdb_dir = os.path.join(self.chroot, current_rpmdb_dir.lstrip('/')) for db in os.listdir(rpmdb_dir): if db.startswith('.') or db.startswith('_'): continue logger.info("processing file %s", db) in_file = os.path.join(rpmdb_dir, db) tmp_file = os.path.join(expected_rpmdb_dir, db + '.tmp') out_file = os.path.join(expected_rpmdb_dir, db) out_command = sh.run( [db_load, tmp_file], chroot = self.chroot, pipe = sh.WRITE, env = self.yum_conf.env, ) bdb.db_dump(in_file, out_command) out_command.close() os.rename( os.path.join(self.chroot, tmp_file.lstrip('/')), os.path.join(self.chroot, out_file.lstrip('/')) ) if current_rpmdb_dir != expected_rpmdb_dir: # Red Hat under Debian; delete old directory (~/.rpmdb possibly) logger.info("removing old RPM DB directory: $TARGET%s", current_rpmdb_dir) shutil.rmtree(os.path.join(self.chroot, current_rpmdb_dir.lstrip('/'))) self.rpmdb_fixed = True
def fix_rpmdb(self, expected_rpmdb_dir=None, db_load="db_load", rpm="rpm"): logger.info("fixing RPM database for guest") current_rpmdb_dir = rpm_mod.expandMacro("%{_dbpath}") if expected_rpmdb_dir is None: expected_rpmdb_dir = sh.run( ["python", "-c", 'import rpm; print rpm.expandMacro("%{_dbpath}")'], chroot=self.chroot, pipe=sh.READ, env=self.yum_conf.env, ).strip() # input directory rpmdb_dir = os.path.join(self.chroot, current_rpmdb_dir.lstrip("/")) logger.info('converting "Packages" file') in_pkg_db = os.path.join(rpmdb_dir, "Packages") tmp_pkg_db = os.path.join(expected_rpmdb_dir, "Packages.tmp") out_pkg_db = os.path.join(expected_rpmdb_dir, "Packages") out_command = sh.run([db_load, tmp_pkg_db], chroot=self.chroot, pipe=sh.WRITE, env=self.yum_conf.env) bdb.db_dump(in_pkg_db, out_command) out_command.close() os.rename(os.path.join(self.chroot, tmp_pkg_db.lstrip("/")), os.path.join(self.chroot, out_pkg_db.lstrip("/"))) logger.info('removing all the files except "Packages"') for f in os.listdir(rpmdb_dir): if f in (".", "..", "Packages"): continue os.unlink(os.path.join(rpmdb_dir, f)) logger.info("running `rpm --rebuilddb'") sh.run([rpm, "--rebuilddb"], chroot=self.chroot, env=self.yum_conf.env) if current_rpmdb_dir != expected_rpmdb_dir: # Red Hat under Debian; delete old directory (~/.rpmdb possibly) logger.info("removing old RPM DB directory: $TARGET%s", current_rpmdb_dir) shutil.rmtree(os.path.join(self.chroot, current_rpmdb_dir.lstrip("/"))) self.rpmdb_fixed = True
def write_csv(wavFile, window_size, step_size, result): cmd = """ffmpeg -i """ + wavFile + """ 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'""" rs = sh.run(cmd, True) duration_in_wavFile = rs.stdout() # print("the duration of wavfile is ", duration_in_wavFile) # print wavFile name = wavFile.split(os.sep)[2] # print name projet = name.split("_")[:3] # print projet date1 = name.split("_")[3] day = date1[-2:] date2 = name.split("_")[4].split(".")[0] second = date2[-2:] minite = date2[-4:-2] hour = date2[:2] # print date1 # print day # print date2,hour,minite,second len_result = len(result) # print int(duration_in_wavFile)/3600 str_start = '20' + date1[:2] + "/" + date1[-4:-2] + "/" + date1[ -2:] + " " + date2[:2] + ":" + date2[-4:-2] + ":" + date2[-2:] # print str_start start = pd.to_datetime(str_start, format='%Y/%m/%d %H:%M:%S') # print start start_time = pd.date_range(start, periods=len_result, freq='1s') # print start_time # print type(start_time) # print len(start_time) first_end_time = start_time[0] + 1 # print first_end_time end_time = pd.date_range(first_end_time, periods=len_result, freq='1min') # print end_time csvFile = open("window/lstm_test.csv", "w") writer = csv.writer(csvFile) fileHead = ["name", "site", "start_time", "end_time", "label"] writer.writerow(fileHead) for i in range(len_result): if result[i] == 0: label = 'Bm' elif result[i] == 1: label = 'Eg' d1 = [projet[0], projet[1], start_time[i], end_time[i], label] writer.writerow(d1) csvFile.close()
def cut(input_file, delimit_points): # 切分点加入终止点3600 delimit_points.append(3600) # 记录分段起止时间 delimit_list = [] if len(delimit_points) <= 2: return path, name, suffix = split(input_file) for i in range(0, len(delimit_points) - 1, 2): # 切出speech段落,文件名为"时间_开始-结束" delimit_list.append( [str(delimit_points[i]), str(delimit_points[i + 1])]) cmd = "ffmpeg -i " + input_file + " -acodec copy -ss " + str( delimit_points[i]) + " -to " + str(delimit_points[ i + 1]) + " " + path + "/" + name + "/" + name + "_" + str( delimit_points[i]) + "-" + str( delimit_points[i + 1]) + "." + suffix sh.run(cmd) print delimit_list return delimit_list
def concat(cut_point, wav_dir, mp3_dir): part_0 = "" part_1 = "" size_0 = 0 size_1 = 0 for i in range(0, len(cut_point),2): part_0 += "-i " + wav_dir + "/" + str(i) + ".wav " size_0+=1 if i + 1 < len(cut_point) - 1: part_1 += "-i " + wav_dir + "/" + str(i+1) + ".wav " size_1+=1 cmd = "./ffmpeg " + part_0 + " -filter_complex '[0:0][1:0][2:0][3:0]concat=n=" + str(size_0) + ":v=0:a=1[out]' -map '[out]' " + wav_dir + "/concat_0.wav" sh.run(cmd) cmd = "./ffmpeg " + part_1 + " -filter_complex '[0:0][1:0][2:0][3:0]concat=n=" + str(size_1) + ":v=0:a=1[out]' -map '[out]' " + wav_dir + "/concat_1.wav" sh.run(cmd) # to mp3 cmd = "./ffmpeg -i " + wav_dir + "/concat_0.wav" + " -q:a 8 " + mp3_dir + "/rs_0.mp3" sh.run(cmd) cmd = "./ffmpeg -i " + wav_dir + "/concat_1.wav" + " -q:a 8 " + mp3_dir + "/rs_1.mp3" sh.run(cmd)
signal = norm_signal(x) # signal_txt = "feature/signal.txt" # Fs_txt = "feature/Fs.txt" # # np.savetxt(signal_txt, signal) # np.savetxt(Fs_txt, Fs) # # signal = np.loadtxt(signal_txt) # Fs = np.loadtxt(Fs_txt) features = feature_extraction(signal, Fs, window_size, step_size) features_normalisation = normaliser_features(features) # cmd = "rm -rf feature/window.txt" # sh.run(cmd) np.savetxt("feature/window.txt", features_normalisation) features_normalisation = np.loadtxt("feature/window.txt") model_path = 'model/mfcc_model_lstm.pkl' # model_path = 'model/rnn_wavelet.pkl' predict(features_normalisation, model_path) cmd = "rm -rf window/lstm_test.csv" sh.run(cmd) result = np.loadtxt("window/lstm_result.txt") write_csv(wavFile, window_size, step_size, result) ''' wav_prediction_dir = 'wav/prediction' file_ext = '*.wav' for wavFile in glob.glob(os.path.join(wav_prediction_dir, file_ext)): x,Fs = read_audio(wavFile) feature_extraction(x,Fs,window_size,step_size) '''
import sh sh.run("ls")
def run(cmd, *args): sh.run(cmd, args=args)
def _download_file(url: str, out_path: str) -> None: logging.info('downloading %s to %s', url, out_path) sh.run(['curl', '--output', out_path, url], check=True)
def test_basic(sub_run): result = sh.run('ls -l') assert sub_run.called
delay=delay, rate=rate, qsize=qsize), shell=True) def combine_results(alg, num_flows, delay, rate, qsize): sh.run( '''cp {alg}/{num_flows}/{delay}/{rate}/{qsize}/cubic-fixed-cwndevo.pdf \ fidelity-experiments/{alg}-{num_flows}-{delay}-{rate}-{qsize}-cwndevo.pdf''' .format(alg=alg, num_flows=num_flows, delay=delay, rate=rate, qsize=qsize), shell=True) if __name__ == '__main__': parsed = parser.parse_args() product = itertools.product(parsed.algs, parsed.flows, parsed.delays, parsed.rate, parsed.qsize) if parsed.combine_results: sh.run('mkdir -p fidelity-experiments', shell=True) for p in product: if parsed.combine_results: combine_results(*p) else: run_combination(*p)
# -*- coding:UTF-8 -*- #multi_detect.py,是运行代码,实现音谱图的识别,语音的切分! python3 ./multi_detect.py from __future__ import print_function #__future__ 至少确保在2.1之前版本的Python可以正常运行一些新的语言特性 import speech_segmentation as seg import sh frame_size = 256 frame_shift =128 sr = 16000 for i in range(1,101): string = "Obama"+str(i)+".wav" seg_point,num = seg.multi_segmentation(string,sr,frame_size,frame_shift,plot_seg=True) print(seg_point) print(len(seg_point)) for j in num: if j<len(seg_point)-1: #经过浮点数转换 mm=int(seg_point[j]/60) ss=int(((seg_point[j]/60)-mm)*60) M=int(seg_point[j+1]/60) S=int(((seg_point[j+1]/60)-M)*60) cmd="ffmpeg -i "+"Obama"+str(i)+".wav"+" -ss 00:"+str(mm)+":"+str(ss)+" -to 00:"+str(M)+":"+str(S)+" -y ../wav/Obama"+str(i)+"_"+str(j)+".wav" rs= sh.run(cmd) #multi_segmentation("Obama1.wav",sr=16000,frame_size=256,frame_shift=128,plot_seg=True)
def run_exps(exps, dest, iters, dur, scenarios, delay, rate, qsize_pkts, num_flows): if iters != 1: print('can only do single iterations') sys.exit(1) print("Running Experiments") print("=========================") for alg, sockopt, name in exps: for trace in scenarios: for i in range(iters): outprefix = "{}-{}-{}".format(name, trace, i) if os.path.exists("./{}/{}-mahimahi.log".format( dest, outprefix)): print(">", outprefix, 'done') continue if sockopt == 'ccp': sh.run('sudo killall reno cubic bbr copa 2> /dev/null', shell=True) ccp_args = '' if alg == 'reno' or alg == 'cubic': ccp_args = '--deficit_timeout=20' threading.Thread( target=ccp_start, args=(dest, alg, 'netlink' if 'netlink' in name else 'chardev', '{}-{}-{}'.format(name, trace, i), ccp_args), daemon=True).start() time.sleep(1) print(">", outprefix) sh.run( "sudo dd if=/dev/null of=/proc/net/tcpprobe 2> /dev/null", shell=True) sh.run( 'sudo dd if=/proc/net/tcpprobe of="./{}/{}-tmp.log" 2> /dev/null &' .format(dest, outprefix), shell=True) if trace == 'fixed': sh.run('mm-delay {4} \ mm-link ./mm-traces/bw{5}.mahi ./mm-traces/bw{5}.mahi \ --uplink-queue=droptail \ --downlink-queue=droptail \ --uplink-queue-args="packets={6}" \ --downlink-queue-args="packets={6}" \ --uplink-log="./{0}/{1}-mahimahi.log" \ -- ./scripts/run-iperf.sh {0} {1} {2} {3} {7}'. format(dest, outprefix, sockopt, dur, delay, rate, qsize_pkts, num_flows), shell=True) elif trace == 'cell': sh.run('mm-delay 10 \ mm-link ./mm-traces/Verizon-LTE-short.up ./mm-traces/Verizon-LTE-short.down \ --uplink-queue=droptail \ --downlink-queue=droptail \ --uplink-queue-args="packets=100" \ --downlink-queue-args="packets=100" \ --uplink-log="./{0}/{1}-mahimahi.log" \ -- ./scripts/run-iperf.sh {0} {1} {2} {3} {4}'. format(dest, outprefix, sockopt, dur, num_flows), shell=True) elif trace == 'drop': sh.run('mm-delay {4} \ mm-link ./mm-traces/bw{5}.mahi ./mm-traces/bw{5}.mahi \ --uplink-log="./{0}/{1}-mahimahi.log" \ mm-loss uplink 0.0001 \ -- ./scripts/run-iperf.sh {0} {1} {2} {3} {6}'. format(dest, outprefix, sockopt, dur, delay, rate, num_flows), shell=True) else: print('unknown', trace) sys.exit(1) sh.run("sudo killall dd 2> /dev/null", shell=True) sh.run( 'grep ":4242" "./{0}/{1}-tmp.log" > "./{0}/tcpprobe-tmp.log"' .format(dest, outprefix), shell=True) sh.run('rm -f "./{}/{}-tmp.log"'.format(dest, outprefix), shell=True) # Create tcpprobes for each flow masquarading as an iteration for flow_num in range(1, num_flows + 1): flow_outprefix = "{}-{}-{}".format(name, trace, flow_num) with open( "./{0}/{1}-iperf-{2}.log".format( dest, outprefix, flow_num), 'r') as f: # Iterate to the 4th line, then find the port line_num = 1 for line in f: if line_num <= 4: line_num += 1 continue m = IPERF_PORT_REGEX.match(line) assert m grp = m.groups() assert len(grp) == 1 port = int(grp[0]) sh.run( 'grep ":{2}" "./{0}/tcpprobe-tmp.log" > "./{0}/{1}-tcpprobe.log"' .format(dest, flow_outprefix, port), shell=True) break sh.run( "mm-graph ./{0}/{1}-mahimahi.log 30 > ./{0}/{1}-mahimahi.eps 2> ./{0}/{1}-mmgraph.log" .format(dest, outprefix), shell=True) if sockopt == 'ccp': sh.run('sudo killall reno cubic bbr copa 2> /dev/null', shell=True) time.sleep(1) print(">", outprefix, 'done') sh.run('sudo killall iperf 2> /dev/null', shell=True)
#!/usr/bin/env python2.7 import imp, time, sh sh = imp.load_source('sh', 'sh/sh.py') print sh prev = [] while 1: lines = sh.run('netstat -vetupan').split('\n')[2:] for line in lines: if hash(line) not in prev: print line prev = [ hash(line) for line in lines ] time.sleep(0.5)
def test_empty_input(sub_run): result = sh.run('') assert not sub_run.called
sr, frame_size, frame_shift, plot_seg=True) print(seg_point) print(len(seg_point)) for j in num: if j < len(seg_point) - 1: #经过浮点数转换 mm = int(seg_point[j] / 60) ss = int(((seg_point[j] / 60) - mm) * 60) M = int(seg_point[j + 1] / 60) S = int(((seg_point[j + 1] / 60) - M) * 60) #cmd1="ffmpeg -i"+"Obama"+str(i)+".wav"+" -ac 1 -q:a 1 -y Obama"+str(i)+".wav" #rs1=sh.run(cmd1) cmd = "ffmpeg -i " + "../1/wav/Obama" + str( i) + "_.wav" + " -ss 00:" + str(mm) + ":" + str( ss) + " -to 00:" + str(M) + ":" + str( S) + " -ac 1 -q:a 1 -y ../1/Wav_crop/Obama" + str( i) + "_" + str(j) + ".wav" #cmd="ffmpeg -i "+"Obama"+str(i)+".wav"+" -ss 00:"+str(mm)+":"+str(ss)+" -to 00:"+str(M)+":"+str(S)+" -y ../Wav_crop/Obama"+str(i)+"_"+str(j)+".wav" rs = sh.run(cmd) cmd1 = "ffmpeg -i ../1/Wav_crop/Obama" + str(i) + "_" + str( j) + ".wav -vol 1000 ../1/Wav_crop/" + str(i) + "_" + str( j) + ".wav" rs1 = sh.run(cmd1) cmd2 = "rm -rf ../1/Wav_crop/Obama" + str(i) + "_" + str( j) + ".wav" rs2 = sh.run(cmd2)