1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| import os import shutil from pydub import AudioSegment from pydub.utils import make_chunks from selenium import webdriver import time import re
dir_parent = 'D:\\测试音频' dir_letter = dir_parent + '\\合并后的音频' dir_letter_letter = dir_parent + '\\切割后的音频' dir_letter_txt = dir_parent + '\\转换后的txt文件' add_sound = AudioSegment.from_wav('sample.wav') sum_sound = add_sound
for path,dir_list,file_list in os.walk(dir_parent): for dir_name in dir_list: dir_child = dir_parent + '\\' + dir_name for path,dir_list,file_list in os.walk(dir_child): for file_name in file_list: front_path = os.path.join(path, file_name) front_sound = AudioSegment.from_wav(front_path) sum_sound = sum_sound + front_sound + add_sound sum_sound.export(dir_child+'已合并.wav',format="wav") sum_sound = add_sound print(dir_child+'文件下的音频合并完成')
os.makedirs(dir_letter) for file in os.listdir(dir_parent): if os.path.isfile(dir_parent + '\\' + file): if '已合并' in file: shutil.move(dir_parent + '\\' + file,dir_letter) print("所有音频合并完成")
chunk_length_ms = 325000 os.makedirs(dir_letter_letter) for path,dir_list,file_list in os.walk(dir_letter): for file_name in file_list: audio = AudioSegment.from_file(dir_letter+'\\'+file_name , "wav") chunks = make_chunks(audio, chunk_length_ms) file_name_change1 = file_name.strip('已合并.wav') file_name_change2 = file_name_change1.strip('AAAAA') for i, chunk in enumerate(chunks): chunk_name = dir_letter_letter+"\\"+file_name_change2+"{0}.wav".format(i) chunk.export(chunk_name, format="wav") print ("音频"+file_name_change2+"切割完成") print("所有音频切割完成")
profile = webdriver.FirefoxProfile() profile.set_preference('browser.download.dir',dir_letter_letter) profile.set_preference('browser.download.folderList',2) profile.set_preference('browser.download.manager.showWhenStarting',False) profile.set_preference('browser.helperApps.neverAsk.saveToDisk','text/plain')
path_list = os.listdir(dir_letter_letter)
for file_name in path_list: driver1 = webdriver.Firefox(firefox_profile=profile) driver1.get("https://app.xunjiepdf.com/voice2text/") print('开始上传'+file_name+'音频文件') upload = driver1.find_element_by_name('file') upload.send_keys(dir_letter_letter+'\\'+file_name) print('音频文件'+file_name+'上传成功') time.sleep(50) print('开始下载文件') driver1.execute_script("arguments[0].click();", driver1.find_element_by_xpath("//a[contains(text(),'立即下载')]")) print('文件下载成功') print('所有文件下载完成')
|