Esempio n. 1
0
def read_audio_file_meta(
        absolute_path: str) -> Optional[CompressedAudioFileMeta]:
    if file_exists(absolute_path):
        audio_file = None
        audio_file_size = file_size_bytes(absolute_path)
        try:
            if extract_extension(absolute_path) == Extension.MP3.value:
                return _read_mp3_file_meta(absolute_path, audio_file_size)
            elif extract_extension(absolute_path) == Extension.FLAC.value:
                return _read_flac_file_meta(absolute_path, audio_file_size)
        except Exception as e:
            logger.exception(
                "Could not read audio file meta from {}. Details: {}".format(
                    absolute_path, e))
            if audio_file:
                audio_file.close()
    return None
Esempio n. 2
0
def read_raw_audio_from_file(input_audio_file_path: str) -> numpy.ndarray:
    mono_audio_segment = AudioSegment.from_file(
        input_audio_file_path,
        extract_extension(input_audio_file_path)).set_channels(1)
    normalized_mono_audio_segment = _normalize_to_maximum_dBFS(
        mono_audio_segment)
    return numpy.true_divide(
        normalized_mono_audio_segment.get_array_of_samples(), 32767.0)
Esempio n. 3
0
def read_audio_tag(input_audio_file_absolute_path: str) -> Optional[Id3Tag]:
    if file_exists(input_audio_file_absolute_path):
        file_ext = extract_extension(input_audio_file_absolute_path)
        if file_ext == Extension.MP3.value:
            return read_audio_tag_using(input_audio_file_absolute_path, EasyID3)
        elif file_ext == Extension.FLAC.value:
            return read_audio_tag_using(input_audio_file_absolute_path, FLAC)
        else:
            raise ValueError("Unsupported file for reading tags: {}".format(input_audio_file_absolute_path))
    else:
        logger.error("File {} does not exists, could not read tags".format(input_audio_file_absolute_path))
        return None
Esempio n. 4
0
 def test_getting_extension(self):
     assert_that(extract_extension('song.ogg')).is_equal_to('ogg')
     assert_that(extract_extension('song.ogg.wav')).is_equal_to('wav')
     assert_that(extract_extension('config')).is_equal_to('')
     assert_that(extract_extension('.vimrc')).is_equal_to('')
Esempio n. 5
0
 def extension(self) -> str:
     return extract_extension(self.file_name)