Update README.md
Browse files
README.md
CHANGED
@@ -69,7 +69,47 @@ Users (both direct and downstream) should be made aware of the risks, biases and
|
|
69 |
|
70 |
Use the code below to get started with the model.
|
71 |
|
72 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
## Training Details
|
75 |
|
|
|
69 |
|
70 |
Use the code below to get started with the model.
|
71 |
|
72 |
+
[### Running the model on a CPU
|
73 |
+
|
74 |
+
<details>
|
75 |
+
#<summary> Click to expand </summary>
|
76 |
+
|
77 |
+
```python
|
78 |
+
|
79 |
+
!pip install transformers datasets torchaudio
|
80 |
+
|
81 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
82 |
+
import torch
|
83 |
+
import torchaudio
|
84 |
+
|
85 |
+
model_id = "fastinom/ASR_fassy"
|
86 |
+
# Load model and processor
|
87 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_id)
|
88 |
+
processor = Wav2Vec2Processor.from_pretrained(model_id)
|
89 |
+
|
90 |
+
def load_audio(file_path):
|
91 |
+
speech_array, sampling_rate = torchaudio.load(file_path)
|
92 |
+
resampler = torchaudio.transforms.Resample(sampling_rate, 16000)
|
93 |
+
speech = resampler(speech_array).squeeze().numpy()
|
94 |
+
return speech
|
95 |
+
# Example audio file path
|
96 |
+
audio_file = "/content/drive/MyDrive/recordings/wavefiles/1.wa"#YOUR AUDIO PATH
|
97 |
+
speech = load_audio(audio_file)
|
98 |
+
|
99 |
+
# Preprocess the audio
|
100 |
+
inputs = processor(speech, sampling_rate=16000, return_tensors="pt", padding=True)
|
101 |
+
|
102 |
+
# Perform inference
|
103 |
+
with torch.no_grad():
|
104 |
+
logits = model(inputs.input_values).logits
|
105 |
+
|
106 |
+
# Decode the output
|
107 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
108 |
+
transcription = processor.batch_decode(predicted_ids)
|
109 |
+
print(transcription[0])
|
110 |
+
```
|
111 |
+
|
112 |
+
</details>]
|
113 |
|
114 |
## Training Details
|
115 |
|