espnet2.fileio package

espnet2.fileio.__init__

espnet2.fileio.datadir_writer

class espnet2.fileio.datadir_writer.DatadirWriter(p: Union[pathlib.Path, str])[source]

Bases: object

Writer class to create kaldi like data directory.

Examples

>>> with DatadirWriter("output") as writer:
...     # output/sub.txt is created here
...     subwriter = writer["sub.txt"]
...     # Write "uttidA some/where/a.wav"
...     subwriter["uttidA"] = "some/where/a.wav"
...     subwriter["uttidB"] = "some/where/b.wav"
close()[source]

espnet2.fileio.npy_scp

class espnet2.fileio.npy_scp.NpyScpReader(fname: Union[pathlib.Path, str])[source]

Bases: collections.abc.Mapping

Reader class for a scp file of numpy file.

Examples

key1 /some/path/a.npy key2 /some/path/b.npy key3 /some/path/c.npy key4 /some/path/d.npy …

>>> reader = NpyScpReader('npy.scp')
>>> array = reader['key1']
get_path(key)[source]
keys() → a set-like object providing a view on D's keys[source]
class espnet2.fileio.npy_scp.NpyScpWriter(outdir: Union[pathlib.Path, str], scpfile: Union[pathlib.Path, str])[source]

Bases: object

Writer class for a scp file of numpy file.

Examples

key1 /some/path/a.npy key2 /some/path/b.npy key3 /some/path/c.npy key4 /some/path/d.npy …

>>> writer = NpyScpWriter('./data/', './data/feat.scp')
>>> writer['aa'] = numpy_array
>>> writer['bb'] = numpy_array
close()[source]
get_path(key)[source]

espnet2.fileio.rand_gen_dataset

class espnet2.fileio.rand_gen_dataset.FloatRandomGenerateDataset(shape_file: Union[pathlib.Path, str], dtype: Union[str, numpy.dtype] = 'float32', loader_type: str = 'csv_int')[source]

Bases: collections.abc.Mapping

Generate float array from shape.txt.

Examples

shape.txt uttA 123,83 uttB 34,83 >>> dataset = FloatRandomGenerateDataset(“shape.txt”) >>> array = dataset[“uttA”] >>> assert array.shape == (123, 83) >>> array = dataset[“uttB”] >>> assert array.shape == (34, 83)

class espnet2.fileio.rand_gen_dataset.IntRandomGenerateDataset(shape_file: Union[pathlib.Path, str], low: int, high: int = None, dtype: Union[str, numpy.dtype] = 'int64', loader_type: str = 'csv_int')[source]

Bases: collections.abc.Mapping

Generate float array from shape.txt

Examples

shape.txt uttA 123,83 uttB 34,83 >>> dataset = IntRandomGenerateDataset(“shape.txt”, low=0, high=10) >>> array = dataset[“uttA”] >>> assert array.shape == (123, 83) >>> array = dataset[“uttB”] >>> assert array.shape == (34, 83)

espnet2.fileio.read_text

espnet2.fileio.read_text.load_num_sequence_text(path: Union[pathlib.Path, str], loader_type: str = 'csv_int') → Dict[str, List[Union[float, int]]][source]

Read a text file indicating sequences of number

Examples

key1 1 2 3 key2 34 5 6

>>> d = load_num_sequence_text('text')
>>> np.testing.assert_array_equal(d["key1"], np.array([1, 2, 3]))
espnet2.fileio.read_text.read_2column_text(path: Union[pathlib.Path, str]) → Dict[str, str][source]

Read a text file having 2 column as dict object.

Examples

wav.scp:

key1 /some/path/a.wav key2 /some/path/b.wav

>>> read_2column_text('wav.scp')
{'key1': '/some/path/a.wav', 'key2': '/some/path/b.wav'}

espnet2.fileio.rttm

class espnet2.fileio.rttm.RttmReader(fname: str)[source]

Bases: collections.abc.Mapping

Reader class for ‘rttm.scp’.

Examples

SPEAKER file1 1 0 1023 <NA> <NA> spk1 <NA> SPEAKER file1 2 4000 3023 <NA> <NA> spk2 <NA> SPEAKER file1 3 500 4023 <NA> <NA> spk1 <NA> END file1 <NA> 4023 <NA> <NA> <NA> <NA>

This is an extend version of standard RTTM format for espnet. The difference including: 1. Use sample number instead of absolute time 2. has a END label to represent the duration of a recording 3. replace duration (5th field) with end time (For standard RTTM,

>>> reader = RttmReader('rttm')
>>> spk_label = reader["file1"]
keys() → a set-like object providing a view on D's keys[source]
espnet2.fileio.rttm.load_rttm_text(path: Union[pathlib.Path, str]) → Dict[str, List[Tuple[str, float, float]]][source]

Read a RTTM file

Note: only support speaker information now

espnet2.fileio.sound_scp

class espnet2.fileio.sound_scp.SoundScpReader(fname, dtype=<class 'numpy.int16'>, always_2d: bool = False, normalize: bool = False)[source]

Bases: collections.abc.Mapping

Reader class for ‘wav.scp’.

Examples

key1 /some/path/a.wav key2 /some/path/b.wav key3 /some/path/c.wav key4 /some/path/d.wav …

>>> reader = SoundScpReader('wav.scp')
>>> rate, array = reader['key1']
get_path(key)[source]
keys() → a set-like object providing a view on D's keys[source]
class espnet2.fileio.sound_scp.SoundScpWriter(outdir: Union[pathlib.Path, str], scpfile: Union[pathlib.Path, str], format='wav', dtype=None)[source]

Bases: object

Writer class for ‘wav.scp’

Examples

key1 /some/path/a.wav key2 /some/path/b.wav key3 /some/path/c.wav key4 /some/path/d.wav …

>>> writer = SoundScpWriter('./data/', './data/feat.scp')
>>> writer['aa'] = 16000, numpy_array
>>> writer['bb'] = 16000, numpy_array
close()[source]
get_path(key)[source]