Serialize all audio file info#438
Conversation
|
@ElodieENSTA This could also speed things up on the APLOSE side! 👏 |
|
I tested this but i get a missing dict key error when trying to deserialize the file = Path(path\to\json)
ads = AudioDataset.from_json(file)The issue seem to stem from instrument = (
None
if dictionary["instrument"] is None
else Instrument.from_dict(dictionary["instrument"])
)changing from The logic in the next bits of the method seem broken as well: butter = (
None
if "butter" not in dictionary or dictionary["audio_data"]["butter"] is None
else Butterworth.from_dict(dictionary["butter"])
)The first condition is always True because return cls.from_files(
files=files,
begin=begin,
end=end,
instrument=instrument,
sample_rate=dictionary["audio_data"]["sample_rate"],
normalization=Normalization(dictionary["audio_data"]["normalization"]),
normalization_values=dictionary["audio_data"]["normalization_values"],
butter=butter,
)Same here none of the returned key here exist in Is there something wrong with the way I process the json or is it something to fix @Gautzilla ? EDIT |
I can't reproduce. Can you share a minimal reproducible example or at least a glimpse of the JSON file?
The ads = AudioDataset(...)
ads.write_json(ads.folder)
ads_deserialized = AudioDataset.from_folder(ads.folder / f"{ads.name}.json")This doesn't raise on my end.
I really don't know how you process the JSON, send me a Minimal Reproducible Example and I'll be able to take a deeper look! 😉 |
My bad I was trying to use the function from a
|

🐌 wassup?
AudioFileserialization only included the filepathplus thebeginandendtimestamps.Thus, deserializing an
AudioFile(e.g. when usingAudioDataset.from_json()still required the audio file manager to read the file metadata to access the sample rate (or deduce it from the number of samples) and the number of chanels.This led to significant loss of time when trying to deserialize large datasets on slow disks or servers.
💡what's new?
This PR adds the
sample_rateandchanelskvps to the serializedAudioFiledictionaries, so that theAudioFilecan be fully instantiated from the dictionary without reading anything from the file.🤷 Is that it??
Not really: since the previously written JSON file didn't include these kvps, we still need to read the metadata for deserializing those old files.
However, it is quite easy to update the JSON once the dataset has been deserialized:
🎵 nota bene
I've just tested this with ~15k files locally stored on my computer, so the speed gain is not that obvious (it mostly seems more consistent while repeatedly deserializing the dataset), so I'm all in if anyone wants to test this on remote servers or whatever!
resolves #437