Automatic Speech Recognition
Transformers
TensorBoard
Safetensors
msp_audio
Generated from Trainer
custom_code
Instructions to use MahmoodAnaam/MSP-ASR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MahmoodAnaam/MSP-ASR with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="MahmoodAnaam/MSP-ASR", trust_remote_code=True)# Load model directly from transformers import AutoModelForCTC model = AutoModelForCTC.from_pretrained("MahmoodAnaam/MSP-ASR", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update feature_extraction_msp_audio.py
Browse files- feature_extraction_msp_audio.py +17 -17
feature_extraction_msp_audio.py
CHANGED
|
@@ -2,7 +2,7 @@ from pathlib import Path
|
|
| 2 |
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
-
|
| 6 |
from transformers.feature_extraction_sequence_utils import SequenceFeatureExtractor
|
| 7 |
from transformers.feature_extraction_utils import BatchFeature
|
| 8 |
from transformers.utils import PaddingStrategy, TensorType, logging
|
|
@@ -52,20 +52,20 @@ class MSPAudioFeatureExtractor(SequenceFeatureExtractor):
|
|
| 52 |
normed = [(x - x.mean()) / np.sqrt(x.var() + 1e-7) for x in input_values]
|
| 53 |
return normed
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
def __call__(
|
| 71 |
self,
|
|
@@ -112,8 +112,8 @@ class MSPAudioFeatureExtractor(SequenceFeatureExtractor):
|
|
| 112 |
raw_speech = [raw_speech]
|
| 113 |
|
| 114 |
# Load from file paths or bytes
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
encoded = BatchFeature({"input_values": raw_speech})
|
| 119 |
|
|
|
|
| 2 |
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
+
from torchcodec.decoders import AudioDecoder
|
| 6 |
from transformers.feature_extraction_sequence_utils import SequenceFeatureExtractor
|
| 7 |
from transformers.feature_extraction_utils import BatchFeature
|
| 8 |
from transformers.utils import PaddingStrategy, TensorType, logging
|
|
|
|
| 52 |
normed = [(x - x.mean()) / np.sqrt(x.var() + 1e-7) for x in input_values]
|
| 53 |
return normed
|
| 54 |
|
| 55 |
+
def _load_audio(
|
| 56 |
+
self,
|
| 57 |
+
src: str | Path | bytes | torch.Tensor,
|
| 58 |
+
start_seconds: float = 0.0,
|
| 59 |
+
stop_seconds: float | None = None,
|
| 60 |
+
) -> np.ndarray:
|
| 61 |
+
"""Load audio waveform from file path or bytes as a 1-D numpy array."""
|
| 62 |
+
audio_decoder = AudioDecoder(source=src, sample_rate=self.sampling_rate)
|
| 63 |
+
if stop_seconds is None:
|
| 64 |
+
stop_seconds = audio_decoder.metadata.duration_seconds_from_header
|
| 65 |
+
waveform = audio_decoder.get_samples_played_in_range(
|
| 66 |
+
start_seconds, stop_seconds
|
| 67 |
+
).data.numpy()
|
| 68 |
+
return waveform.squeeze() # shape: (T,)
|
| 69 |
|
| 70 |
def __call__(
|
| 71 |
self,
|
|
|
|
| 112 |
raw_speech = [raw_speech]
|
| 113 |
|
| 114 |
# Load from file paths or bytes
|
| 115 |
+
if isinstance(raw_speech[0], (str, Path, bytes)):
|
| 116 |
+
raw_speech = [self._load_audio(src) for src in raw_speech]
|
| 117 |
|
| 118 |
encoded = BatchFeature({"input_values": raw_speech})
|
| 119 |
|