Merge pull request 'Actualiser src/tadam.py' (#1) from babakounine/TadaridaTools:master into master

Reviewed-on: #1
This commit is contained in:
Samuel Ortion 2024-01-09 13:22:50 +01:00
commit 182a37a672
1 changed files with 9 additions and 2 deletions

View File

@ -22,6 +22,8 @@ import os
import sys
import numpy as np
import getopt
from datetime import datetime
from datetime import timedelta
verbose = False
@ -92,6 +94,7 @@ def chunk(outfolder, length):
for file in os.listdir(outfolder):
infile = os.path.join(outfolder, file)
extension = infile.split(".")[-1]
time = infile.split("_")[-1].split(".")[0]
if not extension in ["wav", "WAV"]:
continue
try:
@ -105,10 +108,14 @@ def chunk(outfolder, length):
for i in range(sections):
if verbose:
print(
f"\t {str(i).zfill(len(str(sections)))}/{sections} \t {infile}")
filename = infile.replace('.wav', f'_{str(i).zfill(3)}.wav')
f"\t {str(i + 1).zfill(len(str(sections)))}/{sections} \t {infile}")
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"))
filename = infile.replace(f'{time}.wav', f'{time_file}_000.wav')
try:
sf.write(filename, temp, samplerate)
except: