espnet2.train.dataset.AdapterForSingingScoreScpReader
espnet2.train.dataset.AdapterForSingingScoreScpReader
class espnet2.train.dataset.AdapterForSingingScoreScpReader(loader)
Bases: Mapping
Adapter for reading singing scores from a specified loader.
This adapter implements the collections.abc.Mapping interface and provides a way to access singing score data from the underlying loader. It extracts the tempo and notes associated with each key, ensuring that the data conforms to the expected structure.
loader
The underlying loader that provides access to singing score data.
Type: Mapping
Parameters:loader (Mapping) – A loader that returns data in the form of a dictionary containing ‘tempo’ and ‘note’ keys.
keys()
Returns the keys from the loader.
__len__()
Returns the number of items in the loader.
__iter__()
Returns an iterator over the keys of the loader.
__getitem__(key
str) -> Tuple[int, List]: Retrieves the singing score data associated with the given key. It returns a tuple containing the tempo and a list of notes.
- Raises:AssertionError – If the data retrieved from the loader does not contain the expected structure.
####### Examples
>>> adapter = AdapterForSingingScoreScpReader(loader)
>>> adapter.keys()
['utt1', 'utt2', ...]
>>> tempo, notes = adapter['utt1']
>>> print(tempo)
120
>>> print(notes)
['C4', 'E4', 'G4']
NOTE
The expected structure of the data retrieved from the loader is a dictionary with keys ‘tempo’ (an integer) and ‘note’ (a list of note strings).
keys()
Adapter for SingingScoreReader to provide a mapping interface.
This class acts as an adapter for the SingingScoreReader loader, allowing the retrieval of singing scores in a format suitable for further processing. It conforms to the collections.abc.Mapping interface.
loader
The loader instance which provides the singing scores.
- Parameters:loader – An instance of SingingScoreReader that reads singing scores.
- Returns: A tuple containing the tempo and a list of notes.
####### Examples
>>> loader = SingingScoreReader(fname='path/to/scores.scp')
>>> adapter = AdapterForSingingScoreScpReader(loader)
>>> tempo, notes = adapter['utterance_id']
>>> print(tempo)
120
>>> print(notes)
[{'start': 0.0, 'end': 1.0, 'syllable': 'ah', 'midi': 60, 'phones': 'a'},
{'start': 1.0, 'end': 2.0, 'syllable': 'ee', 'midi': 62, 'phones': 'i'}]
- Raises:
- AssertionError – If the returned value from the loader does not
- contain exactly three elements or if the types of those elements –
- do not match the expected types. –