-
Notifications
You must be signed in to change notification settings - Fork 632
/
Copy pathaudio.py
74 lines (65 loc) · 1.96 KB
/
audio.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from typing import Tuple
from hub.schema.features import Tensor
class Audio(Tensor):
def __init__(
self,
shape: Tuple[int, ...] = (None,),
dtype="int64",
file_format=None,
sample_rate: int = None,
max_shape: Tuple[int, ...] = None,
chunks=None,
compressor="lz4",
):
"""Constructs the connector.
Parameters
----------
file_format: `str`
the audio file format. Can be any format ffmpeg
understands. If `None`, will attempt to infer from the file extension.
shape: `tuple`
shape of the data.
dtype: str
The dtype of the data.
sample_rate: `int`
additional metadata exposed to the user through
`info.schema['audio'].sample_rate`. This value isn't used neither in
encoding nor decoding.
Raises
----------
ValueError: If the shape is invalid
"""
self.file_format = file_format
if len(shape) != 1:
raise TypeError(
"Audio schema currently only supports 1-D values, got %s." % shape
)
# self._shape = shape
self.sample_rate = sample_rate
super().__init__(
shape=shape,
dtype=dtype,
max_shape=max_shape,
chunks=chunks,
compressor=compressor,
)
def get_attr_dict(self):
"""Return class attributes."""
return self.__dict__
def __str__(self):
out = super().__str__()
out = "Audio" + out[6:-1]
out = (
out + ", file_format=" + self.file_format
if self.file_format is not None
else out
)
out = (
out + ", sample_rate=" + self.sample_rate
if self.sample_rate is not None
else out
)
out += ")"
return out
def __repr__(self):
return self.__str__()