espnet2.fileio.score_scp.SingingScoreReader
espnet2.fileio.score_scp.SingingScoreReader
class espnet2.fileio.score_scp.SingingScoreReader(fname: ~pathlib.Path | str, dtype: type = <class 'numpy.int16'>)
Bases: Mapping
Reader class for ‘score.scp’.
This class provides an interface to read singing scores from a specified file. The file should contain paths to JSON files that represent the musical scores.
fname
The file name or path of the ‘score.scp’ file.
- Type: Union[Path, str]
dtype
The data type for numerical values (default: np.int16).
- Type: type
data
A dictionary mapping keys to file paths read from ‘score.scp’.
Type: dict
Parameters:
- fname (Union *[*Path , str ]) – The path to the ‘score.scp’ file.
- dtype (type , optional) – The data type for numerical values (default: np.int16).
Returns: The content of the JSON file corresponding to the key.
Return type: dict
######### Examples
key1 /some/path/score.json key2 /some/path/score.json key3 /some/path/score.json key4 /some/path/score.json …
>>> reader = SingingScoreReader('score.scp')
>>> score = reader['key1']
- Raises:
- FileNotFoundError – If the specified JSON file does not exist.
- KeyError – If the specified key is not found in the data.
NOTE
Ensure that the ‘score.scp’ file is properly formatted with valid paths to the JSON files.
get_path(key)
Retrieve the file path associated with the given key.
This method returns the path of the file stored in the internal data dictionary for the specified key.
- Parameters:key (str) – The key whose associated file path is to be retrieved.
- Returns: The file path associated with the given key.
- Return type: str
######### Examples
>>> reader = XMLReader('xml.scp')
>>> path = reader.get_path('key1')
>>> print(path)
/some/path/a.xml
- Raises:KeyError – If the key is not found in the data dictionary.
keys()
Reader class for ‘score.scp’.
This class allows for reading singing scores stored in JSON format. Each score contains a tempo and a list of notes, where each note has attributes such as start time, end time, lyric, MIDI pitch, and phoneme.
fname
The path to the score file.
- Type: Union[Path, str]
dtype
The data type for the score values, default is np.int16.
- Type: type
data
A dictionary mapping keys to file paths.
Type: dict
Parameters:
- fname (Union *[*Path , str ]) – The path to the score file.
- dtype (type) – The data type for the score values, default is np.int16.
Returns: A dictionary representation of the singing score.
Return type: dict
######### Examples
key1 /some/path/score.json key2 /some/path/score.json key3 /some/path/score.json key4 /some/path/score.json …
>>> reader = SingingScoreReader('score.scp')
>>> score = reader['key1']
- Raises:
- FileNotFoundError – If the specified file does not exist.
- KeyError – If the key is not found in the score file.
NOTE
Ensure that the score JSON files are structured correctly to avoid loading errors.