Skip to content

Instantly share code, notes, and snippets.

@danalvarez
Last active February 25, 2022 20:11
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 danalvarez/6e409a6705b9425c25f180d7f53a72b2 to your computer and use it in GitHub Desktop.
Save danalvarez/6e409a6705b9425c25f180d7f53a72b2 to your computer and use it in GitHub Desktop.
Used to process a satnogs ogg audio file for loading in WxToImg GUI (in windows)
#!/usr/bin/python3
import os
import sys
import wave
from datetime import datetime, timedelta
from dateutil import tz
# example satnogs_1692904_2020-02-14T10-24-03.ogg
if len(sys.argv) == 2:
fn = sys.argv[1]
fn_split = fn.split("_") # gives ["satnogs", "1692904", "2020-02-14T10-24-03.ogg"]
if len(fn_split) == 3:
date_string = fn_split[2][:-4] # chop off .ogg
dt_utc = datetime.strptime(date_string, "%Y-%m-%dT%H-%M-%S")
dt_utc = dt_utc.replace(tzinfo=tz.tzutc()) # set UTC as the time zone
dt_local = dt_utc.astimezone(tz.tzlocal()) # convert to local time stamp
fn_wav = fn.replace("ogg", "wav")
print("Converting ogg to wav...")
os.system("sox %s -r 11025 %s" % (fn, fn_wav))
with wave.open(fn_wav, 'r') as f:
wav_frames = f.getnframes()
wav_rate = f.getframerate()
wav_duration = wav_frames / float(wav_rate)
dt_final = dt_local + timedelta(seconds=wav_duration)
print("Updating time stamp...")
# os.system("touch %s --date=\"%s\"" % (fn_wav, dt_final.strftime("%Y-%m-%d %H:%M:%S")))
os.system("nircmd.exe setfiletime \"./%s\" \"%s\" \"%s\"" % (fn_wav, dt_local.strftime("%d-%m-%Y %H:%M:%S"), dt_final.strftime("%d-%m-%Y %H:%M:%S")))
print("Done")
@danalvarez
Copy link
Author

danalvarez commented Feb 25, 2022

A modification of: https://gist.github.com/davidhoness/870ed393059cbc11c93e3632f5ba5208 by @davidhoness to be used in Windows. Since Windows does not have the touch command, this program uses nircmd. Ensure nircmd.exe is in the same directory as the file to be converted and this script.

To run: python satnogs_wx_windows.py satnogs_1692904_2020-02-14T10-24-03.ogg

You must install sox for windows and add it to your PATH: http://sox.sourceforge.net/
And nircmd replaces touch: http://www.nirsoft.net/utils/nircmd.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment