From cf54d805759416ae09f012657125284dfb12ec0f Mon Sep 17 00:00:00 2001 From: MartinCupak <30996725+MartinCupak@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:31:01 +0800 Subject: [PATCH] extract json is now cmdline parameter --- IMOSPATools/audiofile.py | 7 ++++--- scripts/inspect_audio_record.py | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/IMOSPATools/audiofile.py b/IMOSPATools/audiofile.py index 92fee2a..118bfbe 100644 --- a/IMOSPATools/audiofile.py +++ b/IMOSPATools/audiofile.py @@ -125,18 +125,19 @@ def extractMetadataJson(fileName: str): raise IMOSAcousticAudioFileException(logMsg) -def loadInspect(fileName: str): +def loadInspectIMOSFile(fileName: str) -> soundfile.SoundFile: try: with soundfile.SoundFile(fileName, mode='r') as sf: signal = sf.read() sampleRate = sf.samplerate extraInfo = sf.extra_info print(extraInfo) - # IMOSMetaData = extraInfo.get('comment') - # print(IMOSMetaData) + print("----------------------------------------------------") recordDuration = signal.size / sampleRate print(f"Audio record duration {recordDuration:.2f}s") print(f"Sampling rate {sampleRate}Hz") + print(f"Maximum abs amplitude of the signal: {numpy.max(numpy.abs(signal))}") + return sf except (IOError, OSError, soundfile.LibsndfileError) as e: logMsg = f"Error inspecting audio file {fileName}" log.error(logMsg + f"\nException {e}") diff --git a/scripts/inspect_audio_record.py b/scripts/inspect_audio_record.py index ca1e6b7..18e12df 100644 --- a/scripts/inspect_audio_record.py +++ b/scripts/inspect_audio_record.py @@ -21,6 +21,8 @@ def parseArgs(): help='Enable debug mode') parser.add_argument('--filename', '-f', required=True, help='The name of the audio file to inspect.') + parser.add_argument('--json', '-j', action='store_true', + help='extract and print IMOS specifci metadata as JSON.') args = parser.parse_args() return args @@ -46,5 +48,6 @@ def parseArgs(): audiofile.loadInspect(fileName) - mataJson = audiofile.extractMetadataJson(fileName) - print(f"Metadata extracted from file {fileName} as JSON:\n{mataJson}") + if args.json: + mataJson = audiofile.extractMetadataJson(fileName) + print(f"Metadata extracted from file {fileName} as JSON:\n{mataJson}")