update date consideration in chunk function
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
This commit is contained in:
parent
d874613f81
commit
30e1bbb327
@ -97,7 +97,9 @@ def chunk(outfolder, length):
|
|||||||
for file in os.listdir(outfolder):
|
for file in os.listdir(outfolder):
|
||||||
infile = os.path.join(outfolder, file)
|
infile = os.path.join(outfolder, file)
|
||||||
extension = infile.split(".")[-1]
|
extension = infile.split(".")[-1]
|
||||||
|
date = infile.siplit("_")[-2]
|
||||||
time = infile.split("_")[-1].split(".")[0]
|
time = infile.split("_")[-1].split(".")[0]
|
||||||
|
time = date + "_" + time
|
||||||
if not extension in ["wav", "WAV"]:
|
if not extension in ["wav", "WAV"]:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
@ -116,8 +118,8 @@ def chunk(outfolder, length):
|
|||||||
temp = data[i*samplerate*length: i *
|
temp = data[i*samplerate*length: i *
|
||||||
samplerate*length+samplerate*length]
|
samplerate*length+samplerate*length]
|
||||||
|
|
||||||
time_file = datetime.strptime(time, "%H%M%S") + timedelta(seconds = 5 * i)
|
time_file = datetime.strptime(time, "%Y%m%d_%H%M%S") + timedelta(seconds = 5 * i)
|
||||||
time_file = str(time_file.time().__format__("%H%M%S"))
|
time_file = str(time_file.time().__format__("%Y%m%d_%H%M%S"))
|
||||||
filename = infile.replace(f'{time}.wav', f'{time_file}_000.wav')
|
filename = infile.replace(f'{time}.wav', f'{time_file}_000.wav')
|
||||||
try:
|
try:
|
||||||
sf.write(filename, temp, samplerate)
|
sf.write(filename, temp, samplerate)
|
||||||
|
Loading…
Reference in New Issue
Block a user