Spaces:
Sleeping
Sleeping
boumehdi
Browse files
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import librosa
|
2 |
+
import torch
|
3 |
+
from transformers import Wav2Vec2CTCTokenizer, Wav2Vec2ForCTC, Wav2Vec2Processor, TrainingArguments, Wav2Vec2FeatureExtractor, Trainer
|
4 |
|
5 |
+
tokenizer = Wav2Vec2CTCTokenizer("./vocab.json", unk_token="[UNK]", pad_token="[PAD]", word_delimiter_token="|")
|
6 |
+
processor = Wav2Vec2Processor.from_pretrained('boumehdi/wav2vec2-large-xlsr-moroccan-darija', tokenizer=tokenizer)
|
7 |
+
model=Wav2Vec2ForCTC.from_pretrained('boumehdi/wav2vec2-large-xlsr-moroccan-darija')
|
8 |
|
9 |
+
|
10 |
+
# load the audio data (use your own wav file here!)
|
11 |
+
input_audio, sr = librosa.load('file.wav', sr=16000)
|
12 |
+
|
13 |
+
# tokenize
|
14 |
+
input_values = processor(input_audio, return_tensors="pt", padding=True).input_values
|
15 |
+
|
16 |
+
# retrieve logits
|
17 |
+
logits = model(input_values).logits
|
18 |
+
|
19 |
+
tokens = torch.argmax(logits, axis=-1)
|
20 |
+
|
21 |
+
# decode using n-gram
|
22 |
+
transcription = tokenizer.batch_decode(tokens)
|
23 |
+
|
24 |
+
# print the output
|
25 |
+
print(transcription)
|