Pj12 commited on
Commit
6537431
·
verified ·
1 Parent(s): a6ea000

Update extract_feature_print.py

Browse files
Files changed (1) hide show
  1. extract_feature_print.py +14 -1
extract_feature_print.py CHANGED
@@ -1,6 +1,6 @@
1
  import os, sys, traceback
2
  from transformers import HubertModel
3
- import os
4
  from torch import nn
5
  import torch
6
 
@@ -157,6 +157,19 @@ class Config:
157
  )
158
  config = Config()
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  #HuggingFacePlaceHolder = None
161
  class HubertModelWithFinalProj(HubertModel):
162
  def __init__(self, config):
 
1
  import os, sys, traceback
2
  from transformers import HubertModel
3
+ import librosa
4
  from torch import nn
5
  import torch
6
 
 
157
  )
158
  config = Config()
159
 
160
+ def load_audio(file, sample_rate):
161
+ try:
162
+ file = file.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
163
+ audio, sr = sf.read(file)
164
+ if len(audio.shape) > 1:
165
+ audio = librosa.to_mono(audio.T)
166
+ if sr != sample_rate:
167
+ audio = librosa.resample(audio, orig_sr=sr, target_sr=sample_rate)
168
+ except Exception as error:
169
+ raise RuntimeError(f"An error occurred loading the audio: {error}")
170
+
171
+ return audio.flatten()
172
+
173
  #HuggingFacePlaceHolder = None
174
  class HubertModelWithFinalProj(HubertModel):
175
  def __init__(self, config):