From 30e1bbb327c4a1ed7dc7490bcde1557393bec500 Mon Sep 17 00:00:00 2001 From: babakounine Date: Fri, 6 Sep 2024 14:45:12 +0200 Subject: [PATCH] update date consideration in chunk function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when the recording starts at 23:59 and lasts more than 5 seconds the following splits get an accurate time 00:04, 00:09 and so on, but the date isn’t updated. I modified that in order to take into account both date and time so that timedelta, when adding 5secs also changes the date --- src/tadam.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tadam.py b/src/tadam.py index 1656883..023a819 100755 --- a/src/tadam.py +++ b/src/tadam.py @@ -97,7 +97,9 @@ def chunk(outfolder, length): for file in os.listdir(outfolder): infile = os.path.join(outfolder, file) extension = infile.split(".")[-1] + date = infile.siplit("_")[-2] time = infile.split("_")[-1].split(".")[0] + time = date + "_" + time if not extension in ["wav", "WAV"]: continue try: @@ -116,8 +118,8 @@ def chunk(outfolder, length): temp = data[i*samplerate*length: i * samplerate*length+samplerate*length] - time_file = datetime.strptime(time, "%H%M%S") + timedelta(seconds = 5 * i) - time_file = str(time_file.time().__format__("%H%M%S")) + time_file = datetime.strptime(time, "%Y%m%d_%H%M%S") + timedelta(seconds = 5 * i) + time_file = str(time_file.time().__format__("%Y%m%d_%H%M%S")) filename = infile.replace(f'{time}.wav', f'{time_file}_000.wav') try: sf.write(filename, temp, samplerate)