espnet2.fileio.score_scp.XMLReader
espnet2.fileio.score_scp.XMLReader
class espnet2.fileio.score_scp.XMLReader(fname: ~pathlib.Path | str, dtype: type = <class 'numpy.int16'>)
Bases: Mapping
Reader class for ‘xml.scp’.
This class allows reading XML files corresponding to musical scores. Each key in the ‘xml.scp’ file maps to a specific XML file, which can be parsed to extract musical information such as tempo and notes.
fname
The file name or path to the ‘xml.scp’ file.
- Type: Union[Path, str]
dtype
The data type for note representation, default is np.int16.
- Type: type
data
A dictionary containing the mapping of keys to XML file paths.
Type: dict
Parameters:
- fname (Union *[*Path , str ]) – Path to the ‘xml.scp’ file.
- dtype (type) – Data type for note representation (default: np.int16).
Returns: None
######### Examples
Given the following entries in ‘xml.scp’: : key1 /some/path/a.xml key2 /some/path/b.xml key3 /some/path/c.xml key4 /some/path/d.xml
You can access the tempo and note list as follows:
>>> reader = XMLReader('xml.scp')
>>> tempo, note_list = reader['key1']
- Raises:AssertionError – If the music21 package is not available.
NOTE
Ensure that the music21 library is installed to use this class. If it’s not installed, follow the instructions to install the Muskit modules via (cd tools && make muskit.done).
get_path(key)
Retrieve the file path associated with a given key.
This method accesses the internal data dictionary to return the path of the XML or MIDI file associated with the provided key.
- Parameters:key (str) – The key for which the file path is to be retrieved.
- Returns: The file path corresponding to the provided key.
- Return type: str
- Raises:KeyError – If the key is not found in the data dictionary.
######### Examples
>>> reader = XMLReader('xml.scp')
>>> path = reader.get_path('key1')
>>> print(path)
/some/path/a.xml
NOTE
Ensure that the key exists in the data before calling this method to avoid a KeyError.
keys()
Reader class for ‘xml.scp’.
This class reads XML files specified in a key-value format from an input file (xml.scp). Each key corresponds to a path of an XML file, and the class provides methods to access the tempo and a list of notes for each key.
fname
The path to the input file containing keys and their corresponding XML file paths.
- Type: Union[Path, str]
dtype
The data type for notes, default is numpy.int16.
- Type: type
data
A dictionary containing the mapping of keys to XML file paths.
Type: dict
Parameters:
- fname (Union *[*Path , str ]) – The path to the ‘xml.scp’ file.
- dtype (type , optional) – The data type for notes. Defaults to np.int16.
Returns: The tempo as an integer and a list of NOTE objects.
Return type: Tuple[int, List[NOTE]]
Raises:AssertionError – If the music21 package cannot be imported.
######### Examples
key1 /some/path/a.xml key2 /some/path/b.xml key3 /some/path/c.xml key4 /some/path/d.xml …
>>> reader = XMLReader('xml.scp')
>>> tempo, note_list = reader['key1']