Views
No views yet
1from transformers import pipeline
2
3# Load the model
4pipe = pipeline(model="vitouphy/wav2vec2-xls-r-300m-timit-phoneme")
5# Process raw audio
6output = pipe("audio_file.wav", chunk_length_s=10, stride_length_s=(4, 2))1
2from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
3from datasets import load_dataset
4import torch
5import soundfile as sf
6
7# load model and processor
8processor = Wav2Vec2Processor.from_pretrained("vitouphy/wav2vec2-xls-r-300m-timit-phoneme")
9model = Wav2Vec2ForCTC.from_pretrained("vitouphy/wav2vec2-xls-r-300m-timit-phoneme")
10
11# Read and process the input
12audio_input, sample_rate = sf.read("audio_file.wav")
13inputs = processor(audio_input, sampling_rate=16_000, return_tensors="pt", padding=True)
14
15with torch.no_grad():
16 logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
17
18# Decode id into string
19predicted_ids = torch.argmax(logits, axis=-1)
20predicted_sentences = processor.batch_decode(predicted_ids)
21print(predicted_sentences)
22@misc { phy22-phoneme,
author = {Phy, Vitou},
title = {{Automatic Phoneme Recognition on TIMIT Dataset with Wav2Vec 2.0}},
year = 2022,
note = {{If you use this model, please cite it using these metadata.}},
publisher = {Hugging Face},
version = {1.0},
doi = {10.57967/hf/0125},
url = {https://huggingface.co/vitouphy/wav2vec2-xls-r-300m-timit-phoneme}
}