Skip to content

Instantly share code, notes, and snippets.

@mcvittal
Created March 22, 2024 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcvittal/2f55fe2902fc18e7f0ac6ffc48558efc to your computer and use it in GitHub Desktop.
Save mcvittal/2f55fe2902fc18e7f0ac6ffc48558efc to your computer and use it in GitHub Desktop.
def convert_to_dict(text):
text_lines = text.split("\n")
return_dict = {"Room EQ L":{}, "Room EQ R":{}}
isLeft = False
for line in text_lines:
if "L channel calibration:" in line:
isLeft = True
elif "R channel calibration" in line:
isLeft = False
curKey = "Room EQ L" if isLeft else "Room EQ R"
if "Delay" in line:
return_dict[curKey]["REQ Delay"] = line.split(" ")[1]
if "Gain:" in line and "dB" in line:
return_dict[curKey]["Chan Gain"] = line.split(" ")[1]
if "|Type" in line or "|:-------" in line or not line.startswith("|"):
continue
cols = line.split("|")
eqNumber = cols[1].split(" ")[2]
frequency = cols[2].split(" ")[0]
gain = cols[3].split(" ")[0]
q = cols[4].split(" ")[0]
return_dict[curKey][f"REQ Band{eqNumber} Freq"] = f"{frequency},"
return_dict[curKey][f"REQ Band{eqNumber} Q"] = f"{q},"
return_dict[curKey][f"REQ Band{eqNumber} Gain"] = f"{gain},"
return return_dict
def convert_to_xml(in_dict):
xml_output = "<Preset>"
for k in in_dict.keys():
start = f"\n\t<{k}>\n\t\t<Params>"
contents = ""
for kk in in_dict[k].keys():
contents += (f"\n\t\t\t<val e=\"{kk}\" v=\"{in_dict[k][kk]}\"/>")
end = f"\n\t\t</Params>\n\t</{k}>"
xml_output += (start + contents + end)
xml_output += "\n</Preset>\n"
return xml_output
text_input = """
Preset name: 2.0 (Stereo) studio - 2022-08-26
Profile name: 2.0 (Stereo) studio - 2022-08-26
Target mode: Flat
Audio setup: 2.0 (Stereo)
Time exported: 12:05:15 22/03/2024
How to configure your interface: https://www.sonarworks.com/support/soundid-reference/360003040080-Using%20SoundID%20Reference/360005379680-Using%20SoundID%20Reference/4407057579922-Exporting-a-calibration-profile-for-supported-integration-devices
L channel calibration:
Delay: 0 ms
Gain: 0 dB
|Type |Freq |Gain |Q |
|:-------------------|:---------|:---------|:---------|
|Parametric Eq 1 |124 Hz|6.174 dB|1.822 |
|Parametric Eq 2 |143 Hz|-12 dB|2.337 |
|Parametric Eq 3 |235 Hz|-5.348 dB|2.917 |
|Parametric Eq 4 |509 Hz|-4.092 dB|7.527 |
|Parametric Eq 5 |592 Hz|-4.213 dB|6.784 |
|Parametric Eq 6 |881 Hz|2.407 dB|9.769 |
|Parametric Eq 7 |4890 Hz|3.4 dB|7.198 |
|Parametric Eq 8 |17695 Hz|1.682 dB|0.865 |
R channel calibration:
Delay: 0.145833 ms
Gain: -3.36353 dB
|Type |Freq |Gain |Q |
|:-------------------|:---------|:---------|:---------|
|Parametric Eq 1 |96 Hz|-2.481 dB|4.587 |
|Parametric Eq 2 |119 Hz|5.18 dB|7.116 |
|Parametric Eq 3 |139 Hz|-4.042 dB|3.104 |
|Parametric Eq 4 |212 Hz|-4.708 dB|1.458 |
|Parametric Eq 5 |363 Hz|10.456 dB|2.163 |
|Parametric Eq 6 |537 Hz|-9.001 dB|0.709 |
|Parametric Eq 7 |777 Hz|8.507 dB|2.125 |
|Parametric Eq 8 |4957 Hz|4.236 dB|4.113 |
"""
dict_output = convert_to_dict(text_input)
print(convert_to_xml(dict_output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment