Let say I have short mp3 file and my task is to detect if there is a human voice on selected piece of samples audio signal.
My first idea was:
- Extract from mp3 file only acapella wav file with librosa
import numpy as np
import librosa.display
import soundfile as sf
import matplotlib.pyplot as plt
import librosa
y, sr = librosa.load('one_test.mp3')
output_file_path = "one_test.wav"
S_full, phase = librosa.magphase(librosa.stft(y))
S_filter = librosa.decompose.nn_filter(S_full,
aggregate=np.median,
metric='cosine',
width=int(librosa.time_to_frames(2, sr=sr)))
S_filter = np.minimum(S_full, S_filter)
margin_i, margin_v = 2, 10
power = 2
mask_i = librosa.util.softmask(S_filter,
margin_i * (S_full - S_filter),
power=power)
mask_v = librosa.util.softmask(S_full - S_filter,
margin_v * S_filter,
power=power)
# Once we have the masks, simply multiply them with the input spectrum
# to separate the components
S_foreground = mask_v * S_full
S_background = mask_i * S_full
D_foreground = S_foreground * phase
y_foreground = librosa.istft(D_foreground)
sf.write(output_file_path, y_foreground, samplerate=sr)
- Read acapella wav file with scipy and select min-max value from selected range of samplerate
from scipy.io import wavfile
samplerate, data = wavfile.read('one_test.wav')
max(data[0:929])
>>> 3376
min(data[0:929])
>>> -5134
But for that moment I am not sure that It is a correct approach for my task. I still don't know which part of samples have human voice or not. Please provide me an approach or give me an advice where find the answer. My task is not hard I need only find voice on my ROI, no voice segmentation or text detection are not needed.


