I lookup a little bit into this. Typically m4a use AAC audio format so we could use this.
from mutagen import File
file_path = 'path/to/your/file.m4a'
# Load the audio file using mutagen
audio = File(file_path)
audio.info.codec
Out[13]: 'mp4a.40.2'
audio.info.codec_description
Out[14]: 'AAC LC'
I think ISO/IEC 14496-3:2009 give the last m4a codec formats spec but I dont want to pay 200 dollars for this to get a list of codecs codes. So we could parse the codec_description. If there is a supported audio format inside we use this audio format quality table, if not we raise an error.
for format in $list_of_supported_audio_format :
if format in audio.info.codec_description:
return format
else :
raise "Format not support {audio.info.codec_description}"