Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
hehl2
Torchaudio
Commits
9bdaefc8
"llama/sgemm.cpp" did not exist on "7013e5e2d779d68d2a9cdafa96f8fdb2645618a5"
Unverified
Commit
9bdaefc8
authored
Apr 13, 2020
by
Tomás Osório
Committed by
GitHub
Apr 13, 2020
Browse files
add inline Typing (#530)
parent
60a5b273
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
+21
-17
torchaudio/kaldi_io.py
torchaudio/kaldi_io.py
+21
-17
No files found.
torchaudio/kaldi_io.py
View file @
9bdaefc8
# To use this file, the dependency (https://github.com/vesis84/kaldi-io-for-python)
# To use this file, the dependency (https://github.com/vesis84/kaldi-io-for-python)
# needs to be installed. This is a light wrapper around kaldi_io that returns
# needs to be installed. This is a light wrapper around kaldi_io that returns
# torch.Tensors.
# torch.Tensors.
from
typing
import
Any
,
Callable
,
Iterable
,
Tuple
,
Union
import
torch
import
torch
from
torch
import
Tensor
from
torchaudio.common_utils
import
IMPORT_KALDI_IO
,
IMPORT_NUMPY
from
torchaudio.common_utils
import
IMPORT_KALDI_IO
,
IMPORT_NUMPY
if
IMPORT_NUMPY
:
if
IMPORT_NUMPY
:
...
@@ -20,19 +23,20 @@ __all__ = [
...
@@ -20,19 +23,20 @@ __all__ = [
]
]
def
_convert_method_output_to_tensor
(
file_or_fd
,
fn
,
convert_contiguous
=
False
):
def
_convert_method_output_to_tensor
(
file_or_fd
:
Any
,
fn
:
Callable
,
convert_contiguous
:
bool
=
False
)
->
Iterable
[
Tuple
[
str
,
Tensor
]]:
r
"""Takes a method invokes it. The output is converted to a tensor.
r
"""Takes a method invokes it. The output is converted to a tensor.
Args:
Args:
file_or_fd (str/FileDescriptor): File name or file descriptor
file_or_fd (str/FileDescriptor): File name or file descriptor
fn (Callable[[...], Generator[str, numpy.ndarray]]): Function that has the signature (
fn (Callable): Function that has the signature (file name/descriptor) and converts it to
file name/descriptor) -> Generator(str, numpy.ndarray) and converts it to (
Iterable[Tuple[str, Tensor]].
file name/descriptor) -> Generator(str, torch.Tensor).
convert_contiguous (bool, optional): Determines whether the array should be converted into a
convert_contiguous (bool): Determines whether the array should be converted into a
contiguous layout. (Default: ``False``)
contiguous layout. (Default: ``None``)
Returns:
Returns:
Generator[str, torch.
Tensor]: The string is the key and the tensor is vec/mat
Iterable[Tuple[str,
Tensor]
]
: The string is the key and the tensor is vec/mat
"""
"""
if
not
IMPORT_KALDI_IO
:
if
not
IMPORT_KALDI_IO
:
raise
ImportError
(
'Could not import kaldi_io. Did you install it?'
)
raise
ImportError
(
'Could not import kaldi_io. Did you install it?'
)
...
@@ -43,14 +47,14 @@ def _convert_method_output_to_tensor(file_or_fd, fn, convert_contiguous=False):
...
@@ -43,14 +47,14 @@ def _convert_method_output_to_tensor(file_or_fd, fn, convert_contiguous=False):
yield
key
,
torch
.
from_numpy
(
np_arr
)
yield
key
,
torch
.
from_numpy
(
np_arr
)
def
read_vec_int_ark
(
file_or_fd
)
:
def
read_vec_int_ark
(
file_or_fd
:
Any
)
->
Iterable
[
Tuple
[
str
,
Tensor
]]
:
r
"""Create generator of (key,vector<int>) tuples, which reads from the ark file/stream.
r
"""Create generator of (key,vector<int>) tuples, which reads from the ark file/stream.
Args:
Args:
file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor
file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor
Returns:
Returns:
Generator[str, torch.
Tensor]: The string is the key and the tensor is the vector read from file
Iterable[Tuple[str,
Tensor]
]
: The string is the key and the tensor is the vector read from file
Example
Example
>>> # read ark to a 'dictionary'
>>> # read ark to a 'dictionary'
...
@@ -62,14 +66,14 @@ def read_vec_int_ark(file_or_fd):
...
@@ -62,14 +66,14 @@ def read_vec_int_ark(file_or_fd):
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_vec_int_ark
,
convert_contiguous
=
True
)
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_vec_int_ark
,
convert_contiguous
=
True
)
def
read_vec_flt_scp
(
file_or_fd
)
:
def
read_vec_flt_scp
(
file_or_fd
:
Any
)
->
Iterable
[
Tuple
[
str
,
Tensor
]]
:
r
"""Create generator of (key,vector<float32/float64>) tuples, read according to Kaldi scp.
r
"""Create generator of (key,vector<float32/float64>) tuples, read according to Kaldi scp.
Args:
Args:
file_or_fd (str/FileDescriptor): scp, gzipped scp, pipe or opened file descriptor
file_or_fd (str/FileDescriptor): scp, gzipped scp, pipe or opened file descriptor
Returns:
Returns:
Generator[str, torch.
Tensor]: The string is the key and the tensor is the vector read from file
Iterable[Tuple[str,
Tensor]
]
: The string is the key and the tensor is the vector read from file
Example
Example
>>> # read scp to a 'dictionary'
>>> # read scp to a 'dictionary'
...
@@ -78,14 +82,14 @@ def read_vec_flt_scp(file_or_fd):
...
@@ -78,14 +82,14 @@ def read_vec_flt_scp(file_or_fd):
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_vec_flt_scp
)
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_vec_flt_scp
)
def
read_vec_flt_ark
(
file_or_fd
)
:
def
read_vec_flt_ark
(
file_or_fd
:
Any
)
->
Iterable
[
Tuple
[
str
,
Tensor
]]
:
r
"""Create generator of (key,vector<float32/float64>) tuples, which reads from the ark file/stream.
r
"""Create generator of (key,vector<float32/float64>) tuples, which reads from the ark file/stream.
Args:
Args:
file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor
file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor
Returns:
Returns:
Generator[str, torch.
Tensor]: The string is the key and the tensor is the vector read from file
Iterable[Tuple[str,
Tensor]
]
: The string is the key and the tensor is the vector read from file
Example
Example
>>> # read ark to a 'dictionary'
>>> # read ark to a 'dictionary'
...
@@ -94,14 +98,14 @@ def read_vec_flt_ark(file_or_fd):
...
@@ -94,14 +98,14 @@ def read_vec_flt_ark(file_or_fd):
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_vec_flt_ark
)
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_vec_flt_ark
)
def
read_mat_scp
(
file_or_fd
)
:
def
read_mat_scp
(
file_or_fd
:
Any
)
->
Iterable
[
Tuple
[
str
,
Tensor
]]
:
r
"""Create generator of (key,matrix<float32/float64>) tuples, read according to Kaldi scp.
r
"""Create generator of (key,matrix<float32/float64>) tuples, read according to Kaldi scp.
Args:
Args:
file_or_fd (str/FileDescriptor): scp, gzipped scp, pipe or opened file descriptor
file_or_fd (str/FileDescriptor): scp, gzipped scp, pipe or opened file descriptor
Returns:
Returns:
Generator[str, torch.
Tensor]: The string is the key and the tensor is the matrix read from file
Iterable[Tuple[str,
Tensor]
]
: The string is the key and the tensor is the matrix read from file
Example
Example
>>> # read scp to a 'dictionary'
>>> # read scp to a 'dictionary'
...
@@ -110,14 +114,14 @@ def read_mat_scp(file_or_fd):
...
@@ -110,14 +114,14 @@ def read_mat_scp(file_or_fd):
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_mat_scp
)
return
_convert_method_output_to_tensor
(
file_or_fd
,
kaldi_io
.
read_mat_scp
)
def
read_mat_ark
(
file_or_fd
)
:
def
read_mat_ark
(
file_or_fd
:
Any
)
->
Iterable
[
Tuple
[
str
,
Tensor
]]
:
r
"""Create generator of (key,matrix<float32/float64>) tuples, which reads from the ark file/stream.
r
"""Create generator of (key,matrix<float32/float64>) tuples, which reads from the ark file/stream.
Args:
Args:
file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor
file_or_fd (str/FileDescriptor): ark, gzipped ark, pipe or opened file descriptor
Returns:
Returns:
Generator[str, torch.
Tensor]: The string is the key and the tensor is the matrix read from file
Iterable[Tuple[str,
Tensor]
]
: The string is the key and the tensor is the matrix read from file
Example
Example
>>> # read ark to a 'dictionary'
>>> # read ark to a 'dictionary'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment