Support for FLAC and other audio formats
It would be desirable to make Ketos compatible with FLAC audio format. This should be super easy, assuming that soundfile/librosa already can handle FLAC.
Oliver Kirsebom:
Looks like soundfile's read function works just as well for FLAC as it does for WAV.
So, we will need to
update the documentation to mention FLAC in addition to WAV (in fact, we should point the users to this section of the soundfile documentation which explains which formats are supported by soundfile) consider renaming functions that make explicit mention of wav as the source. For example, the BaseAudio class and its derived classes which include the Waveform and Spectrogram classes, all have a method called from_wav. This could be simply renamed to load? generalizing the implementation of a few functions to search not only for WAV files, but also for FLAC files. Specifically, here and [here] (other formats, besides WAV and FLAC, that we should search for by default?)(https://gitlab.meridian.cs.dal.ca/public_projects/ketos/-/blob/master/ketos/audio/audio_loader.py#L220). @bpadovese , your thoughts?
Bruno Padovese
I like just renaming from_wav to just load. Do we also want to rename the from_waveform method? To maybe load_waveform?
Regarding your last point, are we going to start accepting just FLAC and WAV, or all formats supported by soundfile? Either way, I think we should create a list of supported file types and just check if the file corresponds to one.
Oliver Kirsebom
I think from_waveform is good as it is. The name load_waveform would imply (at least to me) that we are loading something into memory from a file or something, which is not the case as the from_waveform method takes an instance of the Waveform class as input, i.e., the audio data have already been loaded.
As for the supported file types, I like the idea of creating a list of supported file extensions. I would say this list should include WAV, FLAC, and perhaps also MAT. So, something like this,
supported_audio_formats = ['wav','WAV','flac','FLAC','mat','MAT']
Where within ketos would we want to place this list?
By default the find_wave_files function would search for these formats only, although we could add an argument allowing the user to explicitly specify which formats to search for. We would also want to rename this method find_audio_files.
Sounds good?
Bruno Padovese
We can define it in the same module i think. Right at the beginning. and we should use the python constant definition (all capital letters):
SUPPORTED_AUDIO_FORMAT = ['wav','WAV','flac','FLAC','mat','MAT']
IF we need to use it anywhere else, we can just import the module:
import module_name
print(module_name.SUPPORTED_AUDIO_FORMAT)
Another good option is to create a new internal module called 'constants.py' where we place all the constants. Whenever another module needs to use them we can just import this constants.py. It is also easier for us to track all of them.
Oliver Kirsebom
Sounds like a good plan. Specifically which constants do you want to place int he constants.py module?
Would you place SUPPORTED_AUDIO_FORMAT in the constants.py module? Or somewhere else. I don't fully follow
Bruno Padovese
Yes I would put SUPPORTED_AUDIO_FORMAT in constants.py and import from there.
But I think it only makes sense if we have other constants. I think if we only have SUPPORTED_AUDIO_FORMAT, we can just define it on top of data_handling` and it is fine.
So to answer your second question, i dont know. I am not sure how many others we have, would have to search. For now, we can just define it at the beginning of data_handling.py
Oliver Kirsebom
We also have the audio_repres_dict: