def recursive_download(download_folder_): # print(toolbox.alert + "Recursion depth : " + str(len(inspect.stack()))) recursive_spaces = " " * (2 * (len(inspect.stack()) - 1)) printout = subprocess.run(['icd', download_folder_], stdout=subprocess.PIPE) if "No such directory" in printout.stdout.decode('utf-8'): return print(toolbox.warning + "./" + os.getcwd()[len(original_working_directory) + 1:] + "/") printout = subprocess.run(['ils'], stdout=subprocess.PIPE) ls_list = printout.stdout.decode('utf-8').split('\n')[1:] element_list = list() for element in ls_list: element = element[2:] if element == "": continue element_list.append(element) print(toolbox.warning + recursive_spaces + "├─ " + element) for element in element_list: if "C-" in element: current_dir = os.getcwd() recurse_head_folder = element.split('/')[-1] # Preparing new folder toolbox.mkdir(recurse_head_folder) os.chdir(current_dir + "/" + recurse_head_folder) recursive_download(download_folder_ + "/" + recurse_head_folder) # Back to the original folder os.chdir(current_dir) subprocess.run(['icd', download_folder_], stdout=subprocess.PIPE) else: print(toolbox.info + "Downloading " + element) if os.path.exists(element): if not do_overwrite: if is_verbose_mode: print( toolbox.warning + element + " already exists (it may have already been downloaded)." ) print(toolbox.warning + "Add '-f' option to allow overwrite.") continue else: if is_verbose_mode: print("rm " + element) os.system("rm " + element) command_line = ['iget', element, "./"] if is_verbose_mode: command_line.append("-vP") print(" ".join(['iget', element, "./"])) subprocess.run(command_line)
else: if arg_id >= 1: parameters_dict["pull_folders"].append(sys.argv[arg_id]) for pull_folder in parameters_dict["pull_folders"]: printout = subprocess.run(['icd', pull_folder], stdout=subprocess.PIPE) if "No such directory" in printout.stdout.decode('utf-8'): print(toolbox.alert + "Directory \"" + pull_folder + "\" has not been found.") continue if pull_folder[-1] == '/': pull_folder = pull_folder[:-1] head_folder = pull_folder.split('/')[-1] toolbox.mkdir(head_folder) os.chdir(original_working_directory + "/" + head_folder) def recursive_download(download_folder_): # print(toolbox.alert + "Recursion depth : " + str(len(inspect.stack()))) recursive_spaces = " " * (2 * (len(inspect.stack()) - 1)) printout = subprocess.run(['icd', download_folder_], stdout=subprocess.PIPE) if "No such directory" in printout.stdout.decode('utf-8'): return print(toolbox.warning + "./" + os.getcwd()[len(original_working_directory) + 1:] + "/")
print(toolbox.info + "Selected bash script : " + parameters_dict["bash_script"].split(" ")[0]) if len(parameters_dict["bash_script"].split(" ")) > 1: print(toolbox.info + "Command line arguments : " + " ".join(parameters_dict["bash_script"].split(" ")[1:-1])) print(toolbox.info + "The script will be launched from : " + current_working_directory) logs_folder_path = os.getenv( "JOBS_DIR") + "/logs/" + this_script_file_name + "/" + parameters_dict[ "bash_script"].split(" ")[0] scripts_folder_path = os.getenv( "JOBS_DIR") + "/scripts/" + this_script_file_name + "/" + parameters_dict[ "bash_script"].split(" ")[0] toolbox.mkdir(logs_folder_path) toolbox.mkdir(scripts_folder_path) dynamic_log_file_path = logs_folder_path + "/" + now_time_string + ".log" job_log_file_path = logs_folder_path + "/" + now_time_string + ".job.log" job_err_file_path = logs_folder_path + "/" + now_time_string + ".job.err" job_script_file_path = scripts_folder_path + "/job_" + now_time_string + "_" + parameters_dict[ "bash_script"].split(" ")[0].split(".")[0] + ".sh" print(toolbox.info + "Log file : " + dynamic_log_file_path) print(toolbox.info + "Job script : " + job_script_file_path) launch_script_str = "#! /bin/bash\n" launch_script_str += "\n" launch_script_str += "cd " + current_working_directory + "\n" launch_script_str += "echo '*******************************************************************'\n"
toolbox.nb_threads = 8 # Define a function to normalize a chunk to a target amplitude. def match_target_amplitude(aChunk, target_dBFS): """ Normalize given audio chunk """ change_in_dBFS = target_dBFS - aChunk.dBFS return aChunk.apply_gain(change_in_dBFS) file_name = file_path.split("/")[-1].split(".")[0] file_name = "_".join(file_name.split(" ")) # Export all of the individual chunks as wav files output_folder = os.getenv("TEMP_DIR") + "/transcript/" + in_out_path[1] + "_" + speech_language + "_" + split_by_option + "/" chunks_subfolder = output_folder + "chunks/" toolbox.mkdir(chunks_subfolder) os.system("rm " + chunks_subfolder + "/*") audio_file_path = output_folder + file_name + ".wav" # ffmpeg -i "2020-05-15 14-17-03.mkv" # to find audio chanel if not os.path.isfile(audio_file_path + ".mp3"): os.system("rm " + audio_file_path) os.system("ffmpeg -i \"" + file_path + "\" -map " + audio_chanel + " -acodec pcm_s16le -ac 2 " + audio_file_path) full_length_audio_file = AudioSegment.from_file(audio_file_path, "wav") print(toolbox.info, "Converting to mp3...") full_length_audio_file.export(audio_file_path + ".mp3",bitrate="192k",format="mp3") os.system("rm " + audio_file_path)
if len(argument_str) > 20: argument_str = ".." + argument_str[-20:-1] out_filename_item_list.append(argument_str) outfiles_base_name = toolbox.get_now_time_string() + "_" + "_".join( out_filename_item_list) if len(outfiles_base_name) > 200: outfiles_base_name = outfiles_base_name[0:200] print(toolbox.gold_color + "Outfiles base name : " + toolbox.reset_color + outfiles_base_name) this_python_script_path = os.path.dirname(os.path.realpath(__file__)) log_folder = JOBS_DIR + "/logs/" + command_arg_list[0] + "/" script_reservoir_folder = JOBS_DIR + "/scripts/" + command_arg_list[0] + "/" toolbox.mkdir(log_folder) toolbox.mkdir(script_reservoir_folder) if not here: execution_folder = RESULTS_DIR + "/" + script_names toolbox.mkdir(execution_folder) #> Preparing launch script lauch_script_string = "#!/bin/bash\n" lauch_script_string += "\n" lauch_script_string += "echo cd " + execution_folder + "\n" lauch_script_string += "cd " + execution_folder + "\n" lauch_script_string += "\n" lauch_script_string += "echo '*******************************************************************'\n" lauch_script_string += "echo COMPUTATION BEGINS\n" lauch_script_string += "echo '*******************************************************************'\n"