Привет, пожалуйста, оптимизируй вот этот код: import numpy as np
import librosa as lr
import os
import webrtcvad
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

def load_dataset(path):
    audio_signals = []
    labels = []
    sr = None
    files = []

    for file in os.listdir(path):
        if file.endswith(".wav"):
            file_path = os.path.join(path, file)
            audio_data, sample_rate = lr.load(file_path, sr=None)
            audio_signals.append(audio_data)
            sr = sample_rate
            files.append(file)

            label = [int(digit) for digit in file.split('.')[0].split('_')]
            labels.append(label)

    return audio_signals, labels, sr, files

def vad(audio_data, sample_rate):
    vad = webrtcvad.Vad()
    vad.set_mode(3)
    
    frame_duration = 20  # Duration of a frame in ms
    frame_length = int(sample_rate * frame_duration / 1000)  # Calculate frame length in samples
    
    # Convert float audio data to 16-bit PCM
    audio_data_int16 = np.array(audio_data * (2**15 - 1), dtype=np.int16)
    
    frames = []
    for i in range(0, len(audio_data_int16), frame_length):
        frame = audio_data_int16[i:i + frame_length]
        if len(frame) < frame_length:
            frame = np.pad(frame, (0, frame_length - len(frame)))
        frames.append(frame)
    
    voiced_frames = [frame for frame in frames if vad.is_speech(frame.tobytes(), sample_rate)]
    
    return voiced_frames

def make_dataset(samples, labels, vad_segments):
    X, y = [], []
    for sample in range(len(samples)):
        for segment in range(len(vad_segments[sample])):
            start = vad_segments[sample][segment][0]
            stop = vad_segments[sample][segment][1]
            voice = samples[sample][start:stop]
            stft = librosa.stft(voice).mean(axis=1)
            stft_db = librosa.amplitude_to_db(abs(stft))

            X.append(stft_db)
            if segment < len(labels[sample]):
                y.append(labels[sample][segment])
            else:
                y.append(-1)  # Use -1 as a placeholder for missing labels

    return np.array(X), np.array(y)

audio_signals, labels, sr, files = load_dataset('/content/drive/MyDrive/School21/day09/datasets/audio_yes_no/waves_yesno 2')

vad_segments = []
for audio_data in audio_signals:
    audio_data_resampled = lr.resample(audio_data, orig_sr=sr, target_sr=8000)
    segments = vad(audio_data_resampled, 8000)
    vad_segments.append(segments)

indices = list(range(len(audio_signals)))
train_indices, test_indices = train_test_split(indices, test_size=0.2, random_state=42)

audio_signals_train = [audio_signals[i] for i in train_indices]
labels_train = [labels[i] for i in train_indices]
vad_segments_train = [vad_segments[i] for i in train_indices]

audio_signals_test = [audio_signals[i] for i in test_indices]
labels_test = [labels[i] for i in test_indices]
vad_segments_test = [vad_segments[i] for i in test_indices]

X_train, y_train = make_dataset(audio_signals_train, labels_train, vad_segments_train)
X_test, y_test = make_dataset(audio_signals_test, labels_test, vad_segments_test)

svm_classifier = SVC()
svm_classifier.fit(X_train, y_train)

y_pred_svm = svm_classifier.predict(X_test)
accuracy_svm = accuracy_score(y_test, y_pred_svm)
print(f"SVM accuracy: {accuracy_svm}")

logreg_classifier = LogisticRegression()
logreg_classifier.fit(X_train, y_train)

y_pred_logreg = logreg_classifier.predict(X_test)
accuracy_logreg = accuracy_score(y_test, y_pred_logreg)
print(f"Logistic Regression accuracy: {accuracy_logreg}"). Добавь пояснения по каждой функции на русском языке.