Views
No views yet
pip install plixkws1import torch
2from plixkws import model, util
3
4support_examples = ["./test_clips/aandachtig.wav", "./test_clips/stroom.wav",
5 "./test_clips/persbericht.wav", "./test_clips/klinkers.wav",
6 "./test_clips/zinsbouw.wav"]
7classes = ["aandachtig", "stroom", "persbericht", "klinkers", "zinsbouw"]
8int_indices = [0,1,2,3,4]
9
10fws_model = model.load(encoder_name="base", language="en", device="cpu")
11
12support = {
13 "paths": support_examples,
14 "classes": classes,
15 "labels": torch.tensor(int_indices),
16}
17support["audio"] = torch.stack([util.load_clip(path) for path in support["paths"]])
18support = util.batch_device(support, device="cpu")
19
20query = {
21 "paths": ["./test_clips/query_klinkers.wav", "./test_clips/query_stroom.wav"]
22}
23query["audio"] = torch.stack([util.load_clip(path) for path in query["paths"]])
24query = util.batch_device(query, device="cpu")
25
26with torch.no_grad():
27 predictions = fws_model(support, query)1
2# !pip install pyaudio
3import numpy as np
4import pyaudio
5import torch
6from plixkws import model, util
7
8sample_rate = 16000
9frames_per_buffer = 512
10support_examples = ["./test_clips/aandachtig.wav", "./test_clips/stroom.wav",
11 "./test_clips/persbericht.wav", "./test_clips/klinkers.wav",
12 "./test_clips/zinsbouw.wav"]
13classes = ["aandachtig", "stroom", "persbericht", "klinkers", "zinsbouw"]
14int_indices = [0,1,2,3,4]
15
16support = {
17 "paths": support_examples,
18 "classes": classes,
19 "labels": torch.tensor(int_indices)
20}
21support["audio"] = torch.stack([util.load_clip(path) for path in support["paths"]])
22support = util.batch_device(support, device="cpu")
23
24fws_model = model.load(encoder_name="small", language="nl", device="cpu")
25
26p = pyaudio.PyAudio()
27stream = p.open(format = pyaudio.paInt16, channels=1,
28 rate=sample_rate, input=True, frames_per_buffer=frames_per_buffer)
29
30frames = []
31while True:
32 data = stream.read(frames_per_buffer)
33 buffer = np.frombuffer(data, dtype=np.int16)
34 frames.append(buffer)
35 if len(frames) * frames_per_buffer / sample_rate >= 1:
36 audio = np.concatenate(frames)
37 audio = audio.astype(float) / np.iinfo(np.int16).max
38 query = {"audio":torch.tensor(audio[np.newaxis, np.newaxis,:], dtype=torch.float32)}
39 query = util.batch_device(query, device="cpu")
40 with torch.no_grad():
41 predictions = fws_model(support, query)
42 print(classes[predictions.item()])
43 frames = []| Language | Encoder Name |
|---|---|
| Multilingual | base_multi |
| Multilingual | small_multi |
| English | base_en |
| Arabic | small_ar |
| Czech | small_cs |
| German | small_de |
| Greek | small_el |
| English | small_en |
| Estonian | small_et |
| Spanish | small_es |
| Persian | small_fa |
| French | small_fr |
| Indonesian | small_id |
| Italian | small_it |
| Kyrgyz | small_ky |
| Dutch | small_nl |
| Polish | small_pl |
| Portuguese | small_pt |
| Russian | small_ru |
| Kinyarwanda | small_rw |
| Swedish | small_sv-SE |
| Turkish | small_tr |
| Tatar | small_tt |
@article{saeed2023plix,
title={Plug-and-Play Multilingual Few-shot Spoken Words Recognition},
author={Saeed, Aaqib and Tsouvalas, Vasileios},
journal={arXiv preprint arXiv:2305.03058},
year={2023}
}