Views
No views yet
A Whisper-large-v3 model fine-tuned for noisy Turkish speech recognition (short utterances, real-world environments).
openai/whisper-large-v3tr)Note: This is a custom fine-tuned model; base capabilities come fromopenai/whisper-large-v3.
openai/whisper-large-v3Exact dataset is not public; this model should be treated as research / experimental.
pipeline)1!pip install -q transformers soundfile librosa
2
3import torch
4import librosa
5from transformers import WhisperProcessor, WhisperForConditionalGeneration
6
7MODEL_ID = "Cosmobillian/turkish_whisper_for_noisy_datas"
8
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
11processor = WhisperProcessor.from_pretrained(MODEL_ID)
12model = WhisperForConditionalGeneration.from_pretrained(MODEL_ID).to(device)
13
14# Dil/task prompt'unu zorla (TR + transcribe)
15forced_ids = processor.get_decoder_prompt_ids(
16 language="turkish",
17 task="transcribe",
18)
19model.config.forced_decoder_ids = forced_ids
20if hasattr(model, "generation_config"):
21 model.generation_config.forced_decoder_ids = forced_ids
22
23
24def load_audio(path, target_sr=16000):
25 audio, sr = librosa.load(path, sr=None, mono=True)
26 if sr != target_sr:
27 audio = librosa.resample(audio, orig_sr=sr, target_sr=target_sr)
28 sr = target_sr
29 return audio, sr
30
31
32def chunked_transcribe(path, chunk_sec=30.0, stride_sec=5.0, max_new_tokens=256):
33 speech, sr = load_audio(path, 16000)
34
35 chunk_size = int(chunk_sec * sr)
36 stride_size = int(stride_sec * sr)
37
38 texts = []
39 start = 0
40
41 while start < len(speech):
42 end = start + chunk_size
43 chunk = speech[start:end]
44
45 if len(chunk) == 0:
46 break
47
48 inputs = processor(
49 chunk,
50 sampling_rate=sr,
51 return_tensors="pt",
52 )
53 input_features = inputs.input_features.to(device)
54
55 with torch.no_grad():
56 generated_ids = model.generate(
57 input_features,
58 max_new_tokens=max_new_tokens,
59 do_sample=False,
60 num_beams=1,
61 no_repeat_ngram_size=3,
62 repetition_penalty=1.2,
63 )
64
65 text = processor.batch_decode(
66 generated_ids,
67 skip_special_tokens=True
68 )[0]
69
70 texts.append(text)
71
72 # bir sonraki chunk'a stride kadar kayarak git
73 start = end - stride_size
74
75 return " ".join(texts)
76
77
78# ÖRNEK KULLANIM
79AUDIO_PATH = "/content/uzun_kayit.wav"
80full_text = chunked_transcribe(AUDIO_PATH, chunk_sec=30, stride_sec=5, max_new_tokens=256)
81
82print("Tam transkripsiyon:\n")
83print(full_text)