Skip to content

Commit

Permalink
remove dear code and unnecessary dependance on mutagen
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupak committed Aug 15, 2024
1 parent 69e2690 commit 7932764
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
45 changes: 0 additions & 45 deletions IMOSPATools/wav.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import wave
import numpy
import logging
from mutagen.wave import WAVE
from mutagen import MutagenError
from datetime import datetime, timezone
from dataclasses import dataclass, asdict
import json

from IMOSPATools import rawdat

Expand Down Expand Up @@ -118,45 +115,3 @@ def writeMono16bit(wavFileName: str,
# logMsg = f"Error writing metadata at the end of audio file {wavFileName}"
# log.error(logMsg + f"\nException {e}")
# raise IMOSAcousticWavException(logMsg)



# the following is an experimental code that actually does not work
# with the standard python wav library.
# Eventually decided to use soundfile library instead (see apudiofile.py)
def addIMOSMetadata(wavFileName: str, metadataStruct: WavMetadataEssential):
"""
Generate the wav filename from raw DAT file
Micro$oft wave format does not support custom metadata.
the workaround is: Format metadata into a json string
and write that into wav as a text comment
:param rawFileName: filename of the raw (DAT) file from which the vav filename shall be derived
:return: filename of the wav file name
"""
try:
audio = WAVE(wavFileName)
# Convert the dataclass instance to a dictionary
metadataDict = asdict(metadataStruct)

for key, value in metadataDict.items():
# Convert the value to a string
metadataDict[key] = str(value)

# #Serialize the metadata dictionary to a JSON
# metadataJson = json.dumps(metadataDict)
# #Add the JSON string as a single custom tag
# metadataJsonString = json.dumps(metadataJson)

# Serialize the metadata dictionary to a JSON string
metadataJsonString = json.dumps(metadataDict)

# wav.setcomment(metadata_json.encode('utf-8'))
audio.add_tags()
audio.tags['IMOS_metadata'] = metadataJsonString
audio.save()
except (FileNotFoundError, IOError, MutagenError) as e:
logMsg = f"An error occurred while adding metadata to the WAV file {wavFileName}"
log.error(logMsg + f"\nException {e}")
raise IMOSAcousticWavException(logMsg)
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def get_version():
# add all libraries
requirements = ["numpy",
"wave",
"mutagen",
"soundfile",
# "matplotlib",
"scipy"]

package_name = 'IMOSPATools'
Expand Down

0 comments on commit 7932764

Please sign in to comment.