File size: 563 Bytes
f9f0314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b30e39a
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import librosa
import numpy as np
from torch import Tensor

def pad(x, max_len=64600):
    x_len = x.shape[0]
    if x_len >= max_len:
        return x[:max_len]
    # need to pad
    num_repeats = int(max_len / x_len)+1
    padded_x = np.tile(x, (1, num_repeats))[:, :max_len][0]
    return padded_x


def process_ssl_assist_input(filepath):
    X, fs = librosa.load(filepath, sr=16000)
    X_pad = pad(X)
    x_inp = Tensor(X_pad)
    x_inp = x_inp.unsqueeze(0)
    return x_inp

def process_assist_input(filepath):
    return process_ssl_assist_input(filepath)