Skip to content

Instantly share code, notes, and snippets.



View GitHub Profile
endolith /
Last active March 29, 2023 20:43
Frequency estimation methods in Python
from __future__ import division
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
from scipy.signal import blackmanharris, correlate
from time import time
import sys
import soundfile as sf
except ImportError:
from scikits.audiolab import flacread
endolith /
Created March 27, 2023 02:33
Transcribe a long audio recording using OpenAI Whisper API
Break up a long recording to fit within the Whisper API's limits, with some
overlap, so no words are missed, and then feed to OpenAI Whisper API to
transcribe it to .txt file. Written by endolith and ChatGPT-4.
import openai
import math
import os
import subprocess
endolith /
Last active March 22, 2023 17:44
Training neural network to implement discrete Fourier transform (DFT/FFT)
Train a neural network to implement the discrete Fourier transform
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import numpy as np
import matplotlib.pyplot as plt
N = 32
batch = 10000
endolith /
Last active March 21, 2023 03:58
THD+N calculator

Unfortunately, there are 2 versions of this. The other is here: I intend to either completely combine them or completely separate them, eventually.

Somewhat crude THD+N calculator in Python

Measures the total harmonic distortion plus noise (THD+N) for a given input signal, by guessing the fundamental frequency (finding the peak in the FFT), and notching it out in the frequency domain. This is a THDR

endolith / example.png
Last active March 16, 2023 14:38
Plot poles and zeros in Z plane for a transfer function
endolith / Has weird right-to-left characters.txt
Last active March 15, 2023 03:50
Unicode kaomoji smileys emoticons emoji
View Has weird right-to-left characters.txt
endolith /
Last active March 10, 2023 05:20
How to stream a webcam to a web browser in Ubuntu

Grr this took hours to figure out. I was trying to install MJPG-streamer and running VLC command lines and all this crap but nothing worked.

First install motion:

~> sudo apt-get install motion

Then create a config file:

~> mkdir ~/.motion

~> nano ~/.motion/motion.conf

endolith / AutoCorrect.ahk
Last active March 5, 2023 23:23
AutoCorrect AutoHotkey spelling script
View AutoCorrect.ahk
; c = case sensitive
; c1 = ignore the case that was typed, always use the same case for output
; * = immediate change (no need for space, period, or enter)
; ? = triggered even when the character typed immediately before it is alphanumeric
; r = raw output
; 2011-03-21 and after: See
endolith / peakdet.m
Last active March 4, 2023 09:59
Peak detection in Python [Eli Billauer]
View peakdet.m
function [maxtab, mintab]=peakdet(v, delta, x)
%PEAKDET Detect peaks in a vector
% [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local
% maxima and minima ("peaks") in the vector V.
% MAXTAB and MINTAB consists of two columns. Column 1
% contains indices in V, and column 2 the found values.
% With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices
% in MAXTAB and MINTAB are replaced with the corresponding
% X-values.
endolith /
Last active February 26, 2023 21:18
A-weighting audio files in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Translated from a MATLAB script (which also includes C-weighting, octave
and one-third-octave digital filters).
Author: Christophe Couvreur, Faculte Polytechnique de Mons (Belgium)
Last modification: Aug. 20, 1997, 10:00am.
BSD license