Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,8 +63,18 @@ feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("facebook/wav2vec2-
|
|
| 63 |
model = Wav2Vec2Model.from_pretrained("facebook/wav2vec2-base-960h")
|
| 64 |
|
| 65 |
# Function to convert audio file into embeddings
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
inputs = feature_extractor(audio, sampling_rate=sr, return_tensors="pt", padding=True)
|
| 69 |
with torch.no_grad():
|
| 70 |
embeddings = model(**inputs).last_hidden_state.mean(dim=1)
|
|
|
|
| 63 |
model = Wav2Vec2Model.from_pretrained("facebook/wav2vec2-base-960h")
|
| 64 |
|
| 65 |
# Function to convert audio file into embeddings
|
| 66 |
+
from io import BytesIO
|
| 67 |
+
import librosa
|
| 68 |
+
|
| 69 |
+
# Updated function for Streamlit-compatible audio processing
|
| 70 |
+
def get_audio_embedding(uploaded_file):
|
| 71 |
+
# Convert uploaded file to in-memory buffer
|
| 72 |
+
audio_bytes = BytesIO(uploaded_file.read())
|
| 73 |
+
|
| 74 |
+
# Load audio using librosa from the BytesIO buffer
|
| 75 |
+
audio, sr = librosa.load(audio_bytes, sr=16000)
|
| 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():
|
| 80 |
embeddings = model(**inputs).last_hidden_state.mean(dim=1)
|