Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,13 +67,19 @@ from io import BytesIO
|
|
| 67 |
import librosa
|
| 68 |
|
| 69 |
# Updated function for Streamlit-compatible audio processing
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Extract features using the Wav2Vec2 model
|
| 78 |
inputs = feature_extractor(audio, sampling_rate=sr, return_tensors="pt", padding=True)
|
| 79 |
with torch.no_grad():
|
|
|
|
| 67 |
import librosa
|
| 68 |
|
| 69 |
# Updated function for Streamlit-compatible audio processing
|
| 70 |
+
import soundfile as sf
|
| 71 |
+
from io import BytesIO
|
| 72 |
+
|
| 73 |
+
# Update the function to handle both file paths and Streamlit-uploaded files
|
| 74 |
+
def get_audio_embedding(file_input):
|
| 75 |
+
# Determine if input is a file path (string) or a file-like object (uploaded file)
|
| 76 |
+
if isinstance(file_input, str):
|
| 77 |
+
# If the input is a file path, use it directly with librosa
|
| 78 |
+
audio, sr = librosa.load(file_input, sr=16000)
|
| 79 |
+
else:
|
| 80 |
+
# If the input is an uploaded file (BytesIO), use soundfile to read it
|
| 81 |
+
audio, sr = sf.read(BytesIO(file_input.read()), dtype='float32')
|
| 82 |
+
|
| 83 |
# Extract features using the Wav2Vec2 model
|
| 84 |
inputs = feature_extractor(audio, sampling_rate=sr, return_tensors="pt", padding=True)
|
| 85 |
with torch.no_grad():
|