espnet2.fileio.score_scp.SingingScoreWriter
espnet2.fileio.score_scp.SingingScoreWriter
class espnet2.fileio.score_scp.SingingScoreWriter(outdir: Path | str, scpfile: Path | str)
Bases: object
Writer class for ‘score.scp’.
This class allows for writing musical scores to a specified output directory and maintaining a corresponding SCP file that maps keys to score file paths. The scores are saved in JSON format.
dir
The directory where score files will be written.
- Type: Path
fscp
The file handle for the SCP file.
- Type: TextIOWrapper
data
A dictionary to store the mapping of keys to score file paths.
Type: dict
Parameters:
- outdir (Union *[*Path , str ]) – The output directory for the score files.
- scpfile (Union *[*Path , str ]) – The path to the SCP file to be created.
####### Examples
key1 /some/path/score.json key2 /some/path/score.json key3 /some/path/score.json key4 /some/path/score.json …
>>> writer = SingingScoreWriter('./data/', './data/score.scp')
>>> writer['aa'] = score_obj
>>> writer['bb'] = score_obj
__setitem__(key
str, value: dict): Saves a score under the specified key.
get_path(key)
Returns the file path associated with the given key.
__enter__()
Supports the use of the context manager.
__exit__(exc_type, exc_val, exc_tb)
Cleans up by closing the SCP file.
close()
Closes the SCP file.
NOTE
The score should be a dictionary with the following structure:
{ : “tempo”: bpm, “item_list”: a subset of [“st”, “et”, “lyric”, “midi”, “phn”], “note”: [ <br/>
[start_time1, end_time1, lyric1, midi1, phn1], [start_time2, end_time2, lyric2, midi2, phn2], … <br/> ]
}
The items in each note correspond to the “item_list”.
close()
Writer class for ‘score.scp’.
This class allows writing singing score data to a specified directory and maintaining a corresponding ‘scp’ file for easy access to the written scores.
Attributes: : dir (Path): The directory where score files will be saved. fscp (TextIOWrapper): The file object for the ‘scp’ file. data (dict): A dictionary to store paths of written scores.
Args: : outdir (Union[Path, str]): The output directory for score files. scpfile (Union[Path, str]): The path to the ‘scp’ file.
Examples: : key1 /some/path/score.json key2 /some/path/score.json key3 /some/path/score.json key4 /some/path/score.json … <br/>
>>> writer = SingingScoreWriter('./data/', './data/score.scp') >>> writer['aa'] = score_obj >>> writer['bb'] = score_obj
Methods: : __setitem__(key: str, value: dict): : Writes the score data to a JSON file and updates the ‘scp’ file. <br/> get_path(key): : Returns the path of the score file associated with the given key. <br/> __enter__(): : Allows the use of the context manager. <br/> __exit__(exc_type, exc_val, exc_tb): : Closes the file when exiting the context manager. <br/> close(): : Closes the ‘scp’ file.
Note: : The score should be a dictionary structured as follows: { <br/>
“tempo”: bpm, “item_list”: a subset of [“st”, “et”, “lyric”, “midi”, “phn”], “note”: [ <br/>
[start_time1, end_time1, lyric1, midi1, phn1], [start_time2, end_time2, lyric2, midi2, phn2], … <br/> ] <br/> } <br/> The items in each note correspond to the “item_list”.
get_path(key)
Writer class for ‘score.scp’.
This class is responsible for writing score data to a specified directory and maintaining a mapping between keys and their corresponding file paths.
dir
The output directory for the score files.
- Type: Path
fscp
The file handle for the SCP file.
- Type: TextIOWrapper
data
A dictionary mapping keys to their respective file paths.
Type: dict
Parameters:
- outdir (Union *[*Path , str ]) – The output directory where score files will be stored.
- scpfile (Union *[*Path , str ]) – The path to the SCP file that will be created or written to.
####### Examples
key1 /some/path/score.json key2 /some/path/score.json key3 /some/path/score.json key4 /some/path/score.json …
>>> writer = SingingScoreWriter('./data/', './data/score.scp')
>>> writer['aa'] = score_obj
>>> writer['bb'] = score_obj
__setitem__(key
str, value: dict): Writes the score data as a JSON file and updates the SCP mapping.
get_path(key)
Returns the file path associated with the given key.
__enter__()
Enables the use of the class in a context manager.
__exit__(exc_type, exc_val, exc_tb)
Closes the file handle upon exiting the context manager.
close()
Closes the SCP file handle.
NOTE
The score data should be structured as follows: {
“tempo”: bpm, “item_list”: a subset of [“st”, “et”, “lyric”, “midi”, “phn”], “note”: [
[start_time1, end_time1, lyric1, midi1, phn1], [start_time2, end_time2, lyric2, midi2, phn2], …
]
} The items in each note correspond to the “item_list”.
- Raises:OSError – If the output directory cannot be created or accessed.