Skip to content

Instantly share code, notes, and snippets.

@davidhoness
Last active February 25, 2022 20:09
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 davidhoness/870ed393059cbc11c93e3632f5ba5208 to your computer and use it in GitHub Desktop.
Save davidhoness/870ed393059cbc11c93e3632f5ba5208 to your computer and use it in GitHub Desktop.
Used to process a satnogs ogg audio file for loading in WxToImg GUI
#!/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")))
print("Done")
@davidhoness
Copy link
Author

Usage

chmod +x satnogs_wx.py
./satnogs_wx.py satnogs_1692904_2020-02-14T10-24-03.ogg

Then File / Open Audio File in WXtoImg
Browse to satnogs_1692904_2020-02-14T10-24-03.wav

@danalvarez
Copy link

Thanks for this David! So useful! Here's a modification of the program for Windows in case it's useful to anybody: https://gist.github.com/danalvarez/6e409a6705b9425c25f180d7f53a72b2

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