Exemple #1
0
def vad():
    logger.info(vad_sh)
    os.system(vad_sh)
    if not os.path.exists(segment):
        logger.error("vad failed!")
        os._exit(0)
    else:
        logger.info("vad succsee!")
Exemple #2
0
def main(wavspath, outputpath, value, tocut):
    result_error = {}
    for root, dirs, files in os.walk(wavspath):

        for file in files:
            if not file.endswith('wav'):
                continue

            package_name = file.rstrip('.wav')
            logger.info(f'处理{package_name}中.')

            wav_path = os.path.join(root, package_name + '.wav')
            txt_path = os.path.join(root, package_name + '.txt')

            wavmaps = read_txttime(txt_path)

            wavslist = sorttime(wavmaps, txt_path)

            tail_time = read_tail_time(wavslist)
            wave_time = read_wavtime(wav_path)

            time_ = tail_time - wave_time
            diff_time = round(time_, 3)
            logger.info(f'时间点差为{diff_time}.')

            if not judgement_time(time_, threshold=value):
                result_error[package_name] = {'tail_time': tail_time, 'wave_time': wave_time}
                continue

            if tocut:
                outputpath = mkdir(os.path.join(outputpath, package_name))
                pool = Pool(processes=8)

                logger.info(f'切割 {file} 中...')
                for item in wavslist:
                    wavname = item.get('wavname')
                    outputwav = os.path.join(outputpath, wavname)
                    start = item.get('start')
                    end = item.get('end')

                    pool.apply_async(wavcut, (wav_path, outputwav, start, end))

                pool.close()
                pool.join()

    logger.info('检测完成!')

    if result_error:
        logger.error('%s 未通过检测,需手动调整切割 [%s]' % (list(result_error.keys()), result_error))

    else:
        logger.info('全部音频通过检测!')
Exemple #3
0
def run_decode():
    # 数据vad
    if not os.path.exists(segment):
        vad()
    else:
        logger.info("sgements file has exist, vad pass!")

    # 数据准备
    cmd = f"cp -r {segment_dir} data/"
    logger.info(cmd)
    os.system(cmd)

    # 解码操作
    logger.info(decode_sh)
    os.system(decode_sh)

    if os.path.exists(decode_file):
        logger.info("####------解码完成!--------####")
    else:
        logger.error("####------解码失败!--------####")
Exemple #4
0
    result_map, whsum = CreatPTFile(project_txts_path, dic_map, classify).run()

    save_to_file(save_upfile, result_map)

    logger.info("Success!!! 共【%s】包【%s】条音频" %
                (len(list(result_map.keys())), whsum))

    if uposs:

        updirpath, amount = uploadpre(project_root, project_wavs_path,
                                      save_upname)
        logger.info("音频准备完成")

        if whsum != amount:
            logger.error(f"音频数【{amount}】与文本数【{whsum}】不对应,请检查!")

        else:

            cmd = f"ossutil64 cp -r -u {updirpath} oss://cn-wav-crowd/{save_upname}"
            logger.info(cmd)
            os.system(cmd)

            dirname = f"updir_{save_upname}"
            os.chdir(project_root)

            cmd = f'ossutil64 ls -s oss://cn-wav-crowd/{save_upname} | grep ".wav" | wc -l'
            out, err = exe_command(cmd)

            try:
                upcount = int(out)
Exemple #5
0
parser.add_argument('-cutwav', type=bool, default=True, help='是否切割音频')
parser.add_argument('-outpath', default=None, help='包含音频文件与对应文本文件的文件夹路径')
parser.add_argument('-sleep_time', type=int, default=2, help='(选填)设置停顿时间')

args = parser.parse_args()

CUTWAV = args.cutwav
WAVSPATH = args.path
OUTPUTPATH = args.outpath
VALUE = args.sleep_time  # 录音停顿时间

if OUTPUTPATH == None:
    OUTPUTPATH = WAVSPATH

if not os.path.isdir(WAVSPATH):
    logger.error('路径不正确,检查后请重试')
    sys.exit()


def mkdir(path):
    if not os.path.exists(path):
        os.makedirs(path)
    return path


def sorttime(maps, txt_path):
    wavinfo = list()
    with open(txt_path, 'w', encoding='utf-8') as fw:
        fw.write(maps.pop('header'))
        for wavname, values in sorted(maps.items(), key=lambda x: float(x[1].get('start'))):
            start = values.get('start')