0
我写了一个python脚本,用30分钟的mp3取出音频,并将它分成unix时间戳,第二个长文件。源音频文件是192kbps,441000Hz,stero mp3文件。Pydub音频导出在开始时保持沉默?
我希望能够从一个广播电台(我工作的地方)存档音频的服务,并且可以在给定的开始和结束时间将其传送给用户,到第二个时间。我们将服务器关闭了一个小时以进行维护(我们尽量不要发生这种情况),并使用不同的计算机在30分钟的时间段内将音频保存起来。通常情况下,这个归档服务器本身保存第二大块本身没有问题。
执行转换的功能,给予30分钟的输入音频文件,该目录保存在输出块和文件作为UNIX时间戳的开始时间:
def slice_file(infile, workingdir, start):
#find the duration of the input clip in millliseconds
duration_in_milliseconds = len(infile)
print ("Converting " + working_file + " (", end="", flush=True)
song = infile
#grab each one second slice and save it from the first second to the last whole second in the file
for i in range(0,duration_in_milliseconds,1*one_second):
#get the folder where this second goes:
arr = datefolderfromtimestamp(int(start) + (int(i/1000)))
#print ("Second number: %s \n" % (int(i/1000)))
offset = (i + one_second)
current_second = song[i:offset]
ensure_dir(working_directory + "/" + arr[0] + "/" + arr[1] + "/" + arr[2] + "/")
filename = os.path.normpath(working_directory + "/" + arr[0] + "/" + arr[1] + "/" + arr[2] + "/" + str(int(start) + (int(i/1000))) + "-second.mp3")
current_second.export(filename, format="mp3")
#indicate some sort of progress is happening by printing a dot every three minutes processed
if(i % (3*60*one_second) == 0):
print ('.', end="", flush=True)
print (")")
我的问题是所有通过这个脚本转换的第二个文件似乎都比一秒钟长,平均开始时有70 ms的静音。当我从归档器服务器上下载文件时,它会将所有文件连接在一起,因此听起来很糟糕。
有人可以帮我吗?我不确定这个错误来自哪里。
我,如果你很好奇完整的脚本:
这是我的坏音频听起来像。请注意,它应该是2分钟长,但相反2:07由于所有小沉默加起来由于连接120个第二长文件:http://www.citr.ca/?attachment_id=69907 – Scott