danhtran2mind commited on
Commit
27c4d46
·
verified ·
1 Parent(s): d49e6db

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -0
README.md CHANGED
@@ -9,3 +9,38 @@ tags:
9
  - viet-asr
10
  ---
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  - viet-asr
10
  ---
11
 
12
+ ## Usage
13
+ Use below Python to do ASR task:
14
+ ```python
15
+ import torch
16
+ import librosa
17
+ from transformers import WhisperProcessor, WhisperForConditionalGeneration
18
+
19
+ # Load model and processor
20
+ processor = WhisperProcessor.from_pretrained("danhtran2mind/Vi-Whisper-tiny-finetuning")
21
+ model = WhisperForConditionalGeneration.from_pretrained("danhtran2mind/Vi-Whisper-tiny-finetuning")
22
+ model.config.forced_decoder_ids = None
23
+ # Move model to GPU if available
24
+ device = "cuda" if torch.cuda.is_available() else "cpu"
25
+ model.to(device)
26
+
27
+ # Load audio file (replace 'audio.wav' with your audio file path)
28
+ audio_path = "<audio_path>"
29
+ audio, sr = librosa.load(audio_path, sr=16000)
30
+
31
+ # Preprocess audio
32
+ inputs = processor(audio, sampling_rate=16000, return_tensors="pt").to(device)
33
+
34
+ # Perform inference with max_length and language
35
+ with torch.no_grad():
36
+ generated_ids = model.generate(
37
+ inputs["input_features"],
38
+ max_length=448,
39
+ )
40
+
41
+ # Decode the output
42
+ transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
43
+
44
+ # Print the transcription
45
+ print("Transcription:\n", transcription)
46
+ ```