-
Notifications
You must be signed in to change notification settings - Fork 0
/
_TestAC.py
38 lines (33 loc) · 1.35 KB
/
_TestAC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from wai.annotations.core.component import SourceComponent
from wai.annotations.core.stream import ThenFunction, DoneFunction
from wai.annotations.domain.audio import Audio
from wai.annotations.domain.audio.classification import AudioClassificationInstance
from wai.annotations.domain.classification import Classification
from wai.common.cli.options import TypedOption
class TestAC(SourceComponent[AudioClassificationInstance]):
input_dir: str = TypedOption(
"--dir",
type=str,
default=".",
help="the directory with the wav files"
)
def produce(
self,
then: ThenFunction[AudioClassificationInstance],
done: DoneFunction
):
"""
Produces elements and inserts them into the stream. Should call 'then'
for each element produced, and then call 'done' when finished.
:param then: A function which forwards elements into the stream.
:param done: A function which closes the stream when called.
"""
for f in os.listdir(self.input_dir):
if not f.lower().endswith(".wav"):
continue
label = os.path.splitext(f)[0]
full = os.path.join(self.input_dir, f)
data = Audio.from_file(full)
then(AudioClassificationInstance(data, Classification(label)))
done()