Views
No views yet
1git clone https://github.com/nguyenvulebinh/AV-HuBERT-S2S.git
2cd AV-HuBERT-S2S
3conda create -n avhuberts2s python=3.9
4conda activate avhuberts2s
5pip install -r requirements.txt
6python run_example.py1from src.model.avhubert2text import AV2TextForConditionalGeneration
2from src.dataset.load_data import load_feature
3from transformers import Speech2TextTokenizer
4import torch
5
6if __name__ == "__main__":
7 # Choose language to run example
8 AVAILABEL_LANGUAGES = ["ar", "de", "el", "en", "es", "fr", "it", "pt", "ru", "multilingual"]
9 language = "ru"
10 assert language in AVAILABEL_LANGUAGES, f"Language {language} is not available, please choose one of {AVAILABEL_LANGUAGES}"
11
12
13 # Load model and tokenizer
14 model_name_or_path = f"nguyenvulebinh/AV-HuBERT-MuAViC-{language}"
15 model = AV2TextForConditionalGeneration.from_pretrained(model_name_or_path, cache_dir='./model-bin')
16 tokenizer = Speech2TextTokenizer.from_pretrained(model_name_or_path, cache_dir='./model-bin')
17
18 model = model.cuda().eval()
19
20 # Load example video and audio
21 video_example = f"./example/video_processed/{language}_lip_movement.mp4"
22 audio_example = f"./example/video_processed/{language}_audio.wav"
23 if not os.path.exists(video_example) or not os.path.exists(audio_example):
24 print(f"WARNING: Example video and audio for {language} is not available english will be used instead")
25 video_example = f"./example/video_processed/en_lip_movement.mp4"
26 audio_example = f"./example/video_processed/en_audio.wav"
27
28 # Load and process example
29 sample = load_feature(
30 video_example,
31 audio_example
32 )
33
34 audio_feats = sample['audio_source'].cuda()
35 video_feats = sample['video_source'].cuda()
36 attention_mask = torch.BoolTensor(audio_feats.size(0), audio_feats.size(-1)).fill_(False).cuda()
37
38 # Generate text
39 output = model.generate(
40 audio_feats,
41 attention_mask=attention_mask,
42 video=video_feats,
43 max_length=1024,
44 )
45
46 print(tokenizer.batch_decode(output, skip_special_tokens=True))1mkdir model-bin
2cd model-bin
3wget https://huggingface.co/nguyenvulebinh/AV-HuBERT/resolve/main/20words_mean_face.npy .
4wget https://huggingface.co/nguyenvulebinh/AV-HuBERT/resolve/main/shape_predictor_68_face_landmarks.dat .
5
6# raw video only support 4:3 ratio now
7cp raw_video.mp4 ./example/
8
9python src/dataset/video_to_audio_lips.py| Languages | Huggingface |
|---|---|
| Arabic | Checkpoint-AR |
| German | Checkpoint-DE |
| Greek | Checkpoint-EL |
| English | Checkpoint-EN |
| Spanish | Checkpoint-ES |
| French | Checkpoint-FR |
| Italian | Checkpoint-IT |
| Portuguese | Checkpoint-PT |
| Russian | Checkpoint-RU |
| Multilingual | Checkpoint-ar_de_el_es_fr_it_pt_ru |
1@article{anwar2023muavic,
2 title={MuAViC: A Multilingual Audio-Visual Corpus for Robust Speech Recognition and Robust Speech-to-Text Translation},
3 author={Anwar, Mohamed and Shi, Bowen and Goswami, Vedanuj and Hsu, Wei-Ning and Pino, Juan and Wang, Changhan},
4 journal={arXiv preprint arXiv:2303.00628},
5 year={2023}
6}