i2mint / hear

Access audio data simply and consistently
Apache License 2.0
1 stars 0 forks source link

Instance to dynamically figure out the `sr` to assert #1

Open thorwhalen opened 3 years ago

thorwhalen commented 3 years ago

We have sr assertion in Trans object, but it's convenient to let the instance (of the store that has access to wav metadata) to figure this out on its own.

It's not hard to do this in the store that has access to meta data (see below), but how to do this in the trans object itself.

Is this a good case for descriptors?

Example of such a mechanism (found in a "dacc" object (which has access to meta data)):

    @cached_property
    def sr(self):
        t = Counter(self.wav_files_info_df['sr'])
        assert len(t) == 1, f"The sr (sample rates) aren't all the same: {t}"
        common_sr = int(self.wav_files_info_df.iloc[0]['sr'])  # get that unique sr
        return common_sr