mirror of
https://github.com/Mangio621/Mangio-RVC-Fork.git
synced 2026-09-01 19:50:07 +02:00
added check for filetype and file length
for preprocessing Co-Authored-By: kalomaze <66376113+kalomaze@users.noreply.github.com>
This commit is contained in:
25
my_utils.py
25
my_utils.py
@@ -108,3 +108,28 @@ def load_audio(file, sr, DoFormant, Quefrency, Timbre):
|
||||
converted = False
|
||||
|
||||
return np.frombuffer(out, np.float32).flatten()
|
||||
|
||||
|
||||
def check_audio_duration(file):
|
||||
try:
|
||||
# Strip whitespaces and unnecessary characters from the file name
|
||||
file = file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
||||
|
||||
# Probe the audio file for information
|
||||
probe = ffmpeg.probe(file)
|
||||
|
||||
# Extract the duration from the probe result
|
||||
duration = float(probe['streams'][0]['duration'])
|
||||
|
||||
# If the duration is less than 0.75 seconds, print the message and exit the loop
|
||||
if duration < 0.76:
|
||||
print(
|
||||
f"\n------------\n"
|
||||
f"Audio file, {file.split('/')[-1]}, under ~0.76s detected - file is too short. Target at least 1-2s for best results."
|
||||
f"\n------------\n\n"
|
||||
)
|
||||
return False
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to check audio duration: {e}")
|
||||
@@ -47,7 +47,7 @@ def main(model_name, save_freq, lastmdls):
|
||||
tfile = os.path.join(tensordir, latest_file)
|
||||
|
||||
ea = event_accumulator.EventAccumulator(tfile,
|
||||
size_guidance={ # see below regarding this argument
|
||||
size_guidance={
|
||||
event_accumulator.COMPRESSED_HISTOGRAMS: 500,
|
||||
event_accumulator.IMAGES: 4,
|
||||
event_accumulator.AUDIO: 4,
|
||||
|
||||
@@ -14,7 +14,7 @@ from slicer2 import Slicer
|
||||
import librosa, traceback
|
||||
from scipy.io import wavfile
|
||||
import multiprocessing
|
||||
from my_utils import load_audio
|
||||
from my_utils import load_audio, check_audio_duration
|
||||
import tqdm
|
||||
|
||||
DoFormant = False
|
||||
@@ -80,28 +80,38 @@ class PreProcess:
|
||||
)
|
||||
|
||||
def pipeline(self, path, idx0):
|
||||
|
||||
file_extension = path.split('.')[-1]
|
||||
supported_file_extensions = {'wav', 'mp3', 'flac', 'ogg', 'opus',
|
||||
'm4a', 'mp4', 'aac', 'alac', 'wma',
|
||||
'aiff', 'webm', 'ac3'}
|
||||
|
||||
try:
|
||||
audio = load_audio(path, self.sr, DoFormant, Quefrency, Timbre)
|
||||
# zero phased digital filter cause pre-ringing noise...
|
||||
# audio = signal.filtfilt(self.bh, self.ah, audio)
|
||||
audio = signal.lfilter(self.bh, self.ah, audio)
|
||||
if file_extension in supported_file_extensions:
|
||||
if not check_audio_duration(path): return
|
||||
audio = load_audio(path, self.sr, DoFormant, Quefrency, Timbre)
|
||||
# zero phased digital filter cause pre-ringing noise...
|
||||
# audio = signal.filtfilt(self.bh, self.ah, audio)
|
||||
audio = signal.lfilter(self.bh, self.ah, audio)
|
||||
|
||||
idx1 = 0
|
||||
for audio in self.slicer.slice(audio):
|
||||
i = 0
|
||||
while 1:
|
||||
start = int(self.sr * (self.per - self.overlap) * i)
|
||||
i += 1
|
||||
if len(audio[start:]) > self.tail * self.sr:
|
||||
tmp_audio = audio[start : start + int(self.per * self.sr)]
|
||||
self.norm_write(tmp_audio, idx0, idx1)
|
||||
idx1 += 1
|
||||
else:
|
||||
tmp_audio = audio[start:]
|
||||
idx1 += 1
|
||||
break
|
||||
self.norm_write(tmp_audio, idx0, idx1)
|
||||
# println("%s->Suc." % path)
|
||||
idx1 = 0
|
||||
for audio in self.slicer.slice(audio):
|
||||
i = 0
|
||||
while 1:
|
||||
start = int(self.sr * (self.per - self.overlap) * i)
|
||||
i += 1
|
||||
if len(audio[start:]) > self.tail * self.sr:
|
||||
tmp_audio = audio[start : start + int(self.per * self.sr)]
|
||||
self.norm_write(tmp_audio, idx0, idx1)
|
||||
idx1 += 1
|
||||
else:
|
||||
tmp_audio = audio[start:]
|
||||
idx1 += 1
|
||||
break
|
||||
self.norm_write(tmp_audio, idx0, idx1)
|
||||
# println("%s->Suc." % path)
|
||||
else:
|
||||
print(f"Unsupported audio format! - {path.split('/')[-1]}")
|
||||
except:
|
||||
println("%s->%s" % (path, traceback.format_exc()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user