Aloukik21 commited on
Commit
9aaf10c
·
verified ·
1 Parent(s): 6281a64

Upload audio/DF_Arena_1B_V_1/feature_extraction_antispoofing.py with huggingface_hub

Browse files
audio/DF_Arena_1B_V_1/feature_extraction_antispoofing.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import SequenceFeatureExtractor
2
+ import numpy as np
3
+ import torch
4
+
5
+ class AntispoofingFeatureExtractor(SequenceFeatureExtractor):
6
+ def __init__(
7
+ self,
8
+ feature_size=1,
9
+ sampling_rate=16000,
10
+ padding_value=0.0,
11
+ return_attention_mask=True,
12
+ **kwargs
13
+ ):
14
+ super().__init__(
15
+ feature_size=feature_size,
16
+ sampling_rate=sampling_rate,
17
+ padding_value=padding_value,
18
+ **kwargs
19
+ )
20
+ self.return_attention_mask = return_attention_mask
21
+
22
+ def __call__(self, audio, sampling_rate=None, return_tensors=True, **kwargs):
23
+ audio = self.pad(audio, 64600)
24
+ audio = torch.Tensor(audio)
25
+ return {
26
+ "input_values": audio
27
+
28
+ }
29
+
30
+ def pad(self, x, max_len):
31
+ x_len = x.shape[0]
32
+ if x_len >= max_len:
33
+ return x[:max_len]
34
+ num_repeats = int(max_len / x_len)+1
35
+ padded_x = np.tile(x, (1, num_repeats))[:, :max_len][0]
36
+ return padded_x