Skip to content

Commit

Permalink
extract json is now cmdline parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupak committed Jul 31, 2024
1 parent c6093ef commit cf54d80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions IMOSPATools/audiofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
7 changes: 5 additions & 2 deletions scripts/inspect_audio_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}")

0 comments on commit cf54d80

Please sign in to comment.