Views
No views yet
1import soundfile as sf
2from transformers import (
3 SpeechT5Config,
4 SpeechT5FeatureExtractor,
5 SpeechT5ForSpeechToText,
6 SpeechT5Processor,
7 SpeechT5Tokenizer,
8)
9
10from custom_tokenizer import CustomTextTokenizer
11
12device = "cuda" if torch.cuda.is_available() else "cpu"
13
14tokenizer = SpeechT5Tokenizer.from_pretrained("mbzuai/artst_asr")
15processor = SpeechT5Processor.from_pretrained("mbzuai/artst_asr" , tokenizer=tokenizer)
16model = SpeechT5ForSpeechToText.from_pretrained("mbzuai/artst_asr").to(device)
17
18audio, sr = sf.read("audio.wav")
19
20inputs = processor(audio=audio, sampling_rate=sr, return_tensors="pt")
21predicted_ids = model.generate(**inputs.to(device), max_length=150, num_beams=10)
22
23transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
24print(transcription[0])@inproceedings{toyin-etal-2023-artst,
title = "{A}r{TST}: {A}rabic Text and Speech Transformer",
author = "Toyin, Hawau and
Djanibekov, Amirbek and
Kulkarni, Ajinkya and
Aldarmaki, Hanan",
booktitle = "Proceedings of ArabicNLP 2023",
month = dec,
year = "2023",
address = "Singapore (Hybrid)",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.arabicnlp-1.5",
doi = "10.18653/v1/2023.arabicnlp-1.5",
pages = "41--51",
}