私は 30 分の mp3 でオーディオを取得し、それを unix タイムスタンプ付きの 2 番目の長さのファイルにスライスする Python スクリプトを作成しました。ソース オーディオ ファイルは、192kbps、441000Hz、ステレオ mp3 ファイルです。
ラジオ局 (私が働いている場所) からオーディオをアーカイブし、指定された開始時間と終了時間にわたってユーザーに配信できるサービスには、そのようにしたいと考えています。メンテナンスのためにサーバーを 1 時間シャットダウンし (そうしないようにしていますが、実際にシャットダウンしてしまいます)、その間、オーディオを 30 分のチャンクで保存した別のコンピューターを使用して録音しました。通常、このアーカイブ サーバーは 2 番目に長いチャンク自体を問題なく保存します。
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 (")")
私の問題は、このスクリプトによって変換されたすべての 2 番目のファイルが 1 秒よりも長く、先頭に平均 70 ミリ秒の無音があるように見えることです。アーカイバ サーバーからファイルをダウンロードすると、すべてのファイルが連結されて表示されるため、ひどくグリッチに聞こえます。
誰かが私を助けることができますか?このエラーがどこから来ているのかわかりません。
興味がある場合は、私の完全なスクリプト: