Commit
·
c725882
1
Parent(s):
6ab8bd8
Update README.md
Browse files
README.md
CHANGED
@@ -40,21 +40,26 @@ You need to install librosa package in order to convert wave to Mel Spectrogram.
|
|
40 |
|
41 |
```python
|
42 |
import librosa
|
|
|
|
|
|
|
|
|
43 |
file = "nlp-voice-3922/data/0002d3428f0ddfa5a48eec5cc351daa8.wav"
|
44 |
-
arr, sampling_rate = librosa.load(file, sr=16000)
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
import torch
|
49 |
|
50 |
-
#
|
51 |
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
52 |
model = WhisperForConditionalGeneration.from_pretrained("daekeun-ml/whisper-small-ko-finetuned-single-speaker-3922samples")
|
53 |
|
|
|
54 |
input_features = processor(arr, return_tensors="pt", sampling_rate=sampling_rate).input_features
|
|
|
|
|
55 |
forced_decoder_ids = processor.get_decoder_prompt_ids(language="ko", task="transcribe")
|
56 |
-
predicted_ids = model.generate(input_features, forced_decoder_ids
|
57 |
-
transcription = processor.batch_decode(predicted_ids, skip_special_tokens
|
58 |
|
59 |
print(transcription)
|
60 |
```
|
|
|
40 |
|
41 |
```python
|
42 |
import librosa
|
43 |
+
import torch
|
44 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
45 |
+
|
46 |
+
# prepare your sample data (.wav)
|
47 |
file = "nlp-voice-3922/data/0002d3428f0ddfa5a48eec5cc351daa8.wav"
|
|
|
48 |
|
49 |
+
# Convert to Mel Spectrogram
|
50 |
+
arr, sampling_rate = librosa.load(file, sr=16000)
|
|
|
51 |
|
52 |
+
# Load whisper model and processor
|
53 |
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
54 |
model = WhisperForConditionalGeneration.from_pretrained("daekeun-ml/whisper-small-ko-finetuned-single-speaker-3922samples")
|
55 |
|
56 |
+
# Preprocessing
|
57 |
input_features = processor(arr, return_tensors="pt", sampling_rate=sampling_rate).input_features
|
58 |
+
|
59 |
+
# Prediction
|
60 |
forced_decoder_ids = processor.get_decoder_prompt_ids(language="ko", task="transcribe")
|
61 |
+
predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
|
62 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
63 |
|
64 |
print(transcription)
|
65 |
```
|