Last active
February 25, 2022 20:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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