File size: 1,674 Bytes
b3e6cf8
 
 
 
 
 
 
 
 
 
 
 
92cc3f4
 
65f57bc
92cc3f4
65f57bc
92cc3f4
65f57bc
92cc3f4
 
 
 
65f57bc
92cc3f4
65f57bc
92cc3f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
license: mit
datasets:
- mozilla-foundation/common_voice_11_0
language:
- fa
metrics:
- wer
base_model:
- openai/whisper-tiny
pipeline_tag: automatic-speech-recognition
library_name: transformers
---
how to use the model in colab:

!pip install torch torchaudio transformers librosa gradio

from transformers import WhisperProcessor, WhisperForConditionalGeneration

import torch

# Load your fine-tuned Whisper model and processor
model_name = "hackergeek98/tinyyyy_whisper"

processor = WhisperProcessor.from_pretrained(model_name)

model = WhisperForConditionalGeneration.from_pretrained(model_name)

# Force the model to transcribe in Persian
model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language="fa", task="transcribe")

# Move model to GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
import librosa

def transcribe_audio(audio_file):
    # Load audio file using librosa (supports multiple formats)
    audio_data, sampling_rate = librosa.load(audio_file, sr=16000)  # Resample to 16kHz

    # Preprocess the audio
    inputs = processor(audio_data, sampling_rate=sampling_rate, return_tensors="pt").input_features.to(device)

    # Generate transcription
    with torch.no_grad():
        predicted_ids = model.generate(inputs)

    # Decode the transcription
    transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
    return transcription
from google.colab import files

# Upload an audio file
uploaded = files.upload()
audio_file = list(uploaded.keys())[0]

# Transcribe the audio
transcription = transcribe_audio(audio_file)
print("Transcription:", transcription)