espnet2.fileio.read_text.read_2columns_text
Less than 1 minute
espnet2.fileio.read_text.read_2columns_text
espnet2.fileio.read_text.read_2columns_text(path: Path | str) → Dict[str, str]
Read a text file having 2 columns as dict object.
This function reads a text file where each line contains two columns, separated by whitespace. The first column is treated as the key and the second column as the value. It returns a dictionary mapping each key to its corresponding value. If duplicate keys are found, a RuntimeError is raised.
- Parameters:path (Union *[*Path , str ]) – The path to the text file to be read.
- Returns: A dictionary containing key-value pairs from the text file.
- Return type: Dict[str, str]
- Raises:RuntimeError – If a duplicate key is found in the text file.
Examples
Given a file named wav.scp with the following content: : key1 /some/path/a.wav key2 /some/path/b.wav
The function can be called as follows: : ```python
read_2columns_text('wav.scp')
##### NOTE
The function expects the text file to be encoded in UTF-8.