import transformersimport datasetsimport torch model_id = "huwenjie333/whisper-v3-ft-af51-0703"processor = transformers.WhisperProcessor.from_pretrained(model_id)model = transformers.WhisperForConditionalGeneration.from_pretrained(model_id) SALT_LANGUAGE_TOKENS_WHISPER = { # Existing languges codes from Whisper "eng": 50259, "fra": 50265, "swa": 50318, "sna": 50324, "yor": 50325, "som": 50326, "afr": 50327, "amh": 50334, "mlg": 50349, "lin": 50353, "hau": 50354, # Overwrite unused language tokens "ach": 50357, "aka": 50356, "bam": 50355, "bem": 50352, "ber": 50351, "cgg": 50350, "dag": 50348, "dga": 50347, "ewe": 50346, "ful": 50345, "ibo": 50344, "kab": 50343, "kau": 50342, "kik": 50341, "kin": 50340, "kln": 50339, "koo": 50338, "kpo": 50337, "led": 50336, "lgg": 50335, "lth": 50333, "lug": 50332, "luo": 50331, "luy": 50330, "myx": 50329, "nbl": 50328, "nya": 50323, "nyn": 50322, "orm": 50321, "pcm": 50320, "ruc": 50319, "rwm": 50317, "sot": 50316, "teo": 50315, "tsn": 50314, "ttj": 50313, "wol": 50312, "xho": 50311, "xog": 50310, "zul": 50309,} # Get some test audiods = datasets.load_dataset('Sunbird/salt', 'multispeaker-lug', split='test')audio = ds[0]['audio']sample_rate = ds[0]['sample_rate'] # Specify a language from one of the above.lang = 'lug' # Apply the modeldevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")input_features = processor( audio, sampling_rate=sample_rate, return_tensors="pt").input_featuresinput_features = input_features.to(device) lang_tok = SALT_LANGUAGE_TOKENS_WHISPER[lang_code]transcribe_tok = processor.tokenizer.convert_tokens_to_ids("<|transcribe|>")notimestamps_tok = processor.tokenizer.convert_tokens_to_ids("<|notimestamps|>")forced_decoder_ids = [ (1, lang_tok), (2, transcribe_tok), (3, notimestamps_tok),] predicted_ids = model.to(device).generate( input_features, forced_decoder_ids=forced_decoder_ids, num_beams=1, do_sample=False,)transcription = processor.batch_decode( predicted_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False) print(transcription)# Ekikoola kya kasooli kya kyenvu wabula langi yaakyo etera okuba eya kitaka wansi.