Vietnamese ASR sequence-to-sequence model. This model supports output normalizing text, labeling timestamps, and segmenting multiple speakers.
# !pip install transformers, sentencepiecefrom transformers import SpeechEncoderDecoderModel
from transformers import AutoFeatureExtractor, AutoTokenizer, GenerationConfig
import torchaudio
import torch
model_path = 'nguyenvulebinh/wav2vec2-bartpho'
model = SpeechEncoderDecoderModel.from_pretrained(model_path).eval()
feature_extractor = AutoFeatureExtractor.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
if torch.cuda.is_available():
model = model.cuda()
defdecode_tokens(token_ids, skip_special_tokens=True, time_precision=0.02):
timestamp_begin = tokenizer.vocab_size
outputs = [[]]
for token in token_ids:
if token >= timestamp_begin:
timestamp = f" |{(token - timestamp_begin) * time_precision:.2f}| "
outputs.append(timestamp)
outputs.append([])
else:
outputs[-1].append(token)
outputs = [
s ifisinstance(s, str) else tokenizer.decode(s, skip_special_tokens=skip_special_tokens) for s in outputs
]
return"".join(outputs).replace("< |", "<|").replace("| >", "|>")
defdecode_wav(audio_wavs, asr_model, prefix=""):
device = next(asr_model.parameters()).device
input_values = feature_extractor.pad(
[{"input_values": feature} for feature in audio_wavs],
padding=True,
max_length=None,
pad_to_multiple_of=None,
return_tensors="pt",
)
output_beam_ids = asr_model.generate(
input_values['input_values'].to(device),
attention_mask=input_values['attention_mask'].to(device),
decoder_input_ids=tokenizer.batch_encode_plus([prefix] * len(audio_wavs), return_tensors="pt")['input_ids'][..., :-1].to(device),
generation_config=GenerationConfig(decoder_start_token_id=tokenizer.bos_token_id),
max_length=250,
num_beams=25,
no_repeat_ngram_size=4,
num_return_sequences=1,
early_stopping=True,
return_dict_in_generate=True,
output_scores=True,
)
output_text = [decode_tokens(sequence) for sequence in output_beam_ids.sequences]
return output_text
# https://huggingface.co/nguyenvulebinh/wav2vec2-bartpho/resolve/main/sample_news.wavprint(decode_wav([torchaudio.load('sample_news.wav')[0].squeeze()], model))
# <|0.00| Gia đình cho biết, nhiều lần đã từng gọi điện báo chính quyền và lực lượng an ninh địa phương nhưng đều không có tác dụng |7.00|># <|8.14| Không ai giúp đỡ được mình một chút nào cả, nên là lúc đó là lúc tuyệt vọng nhất, nó tra tấn mình cực kỳ khổ, gây cái tâm lý ức chế rất là nhiều, rất là lớn |19.02|>
Citation
This repository uses the idea from the following paper. Please cite the paper if this model is used to help produce published results or is incorporated into other software.
@INPROCEEDINGS{10446589,
author={Nguyen, Thai-Binh and Waibel, Alexander},
booktitle={ICASSP 2024 - 2024 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
title={Synthetic Conversations Improve Multi-Talker ASR},
year={2024},
volume={},
number={},
pages={10461-10465},
keywords={Systematics;Error analysis;Knowledge based systems;Oral communication;Signal processing;Data models;Acoustics;multi-talker;asr;synthetic conversation},
doi={10.1109/ICASSP48485.2024.10446589}
}
wav2vec2-bartpho huggingface.co is an AI model on huggingface.co that provides wav2vec2-bartpho's model effect (), which can be used instantly with this nguyenvulebinh wav2vec2-bartpho model. huggingface.co supports a free trial of the wav2vec2-bartpho model, and also provides paid use of the wav2vec2-bartpho. Support call wav2vec2-bartpho model through api, including Node.js, Python, http.
wav2vec2-bartpho huggingface.co is an online trial and call api platform, which integrates wav2vec2-bartpho's modeling effects, including api services, and provides a free online trial of wav2vec2-bartpho, you can try wav2vec2-bartpho online for free by clicking the link below.
nguyenvulebinh wav2vec2-bartpho online free url in huggingface.co:
wav2vec2-bartpho is an open source model from GitHub that offers a free installation service, and any user can find wav2vec2-bartpho on GitHub to install. At the same time, huggingface.co provides the effect of wav2vec2-bartpho install, users can directly use wav2vec2-bartpho installed effect in huggingface.co for debugging and trial. It also supports api for free installation.