Aku Rouhe commited on
Commit
8b70882
1 Parent(s): a0b8c90

New interface

Browse files
Files changed (2) hide show
  1. hyperparams.yaml +13 -0
  2. interface.py +15 -0
hyperparams.yaml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ feature_extractor: !new:speechbrain.lobes.features.Fbank
2
+ n_fft: 400
3
+ n_mels: 40
4
+
5
+ normalizer: !new:speechbrain.processing.features.InputNormalization
6
+ norm_type: global
7
+
8
+ modules:
9
+ normalizer: !ref <normalizer>
10
+
11
+ pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer
12
+ loadables:
13
+ normalizer: !ref <normalizer>
interface.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import speechbrain as sb
3
+
4
+ class Custom(sb.pretrained.interfaces.Pretrained):
5
+ MODULES_NEEDED = ["normalizer"]
6
+ HPARAMS_NEEDED = ["feature_extractor"]
7
+
8
+ def feats_from_audio(self, audio, lengths=torch.tensor([1.0])):
9
+ feats = self.hparams.feature_extractor(audio)
10
+ normalized = self.mods.normalizer(feats, lengths)
11
+ return normalized
12
+
13
+ def feats_from_file(self, path):
14
+ audio = self.load_audio(path)
15
+ return self.feats_from_audio(audio.unsqueeze(0)).squeeze(0)