I'm trying to decode some audio which is basically two frequencies (200hz for a 0 and 800hz for 1) that directly translates directly to binary. A sample of the audio
This sample translates to "1001011". There is a third frequency that is 1600hz as a dividor between the bits.
I can't find anything that works i did find a few things but it either was outdated or just straight up not working i'm really despaired.
I made a sample code that can generate audio for this encoding (to test the decoder):
import math
import wave
import struct
audio = []
sample_rate = 44100.0
def split(word):
return [char for char in word]
def append_sinewave(
freq=440.0,
duration_milliseconds=10,
volume=1.0):
global audio
num_samples = duration_milliseconds * (sample_rate / 1000.0)
for x in range(int(num_samples)):
audio.append(volume * math.sin(2 * math.pi * freq * ( x / sample_rate )))
return
def save_wav(file_name):
wav_file=wave.open(file_name,"w")
nchannels = 1
sampwidth = 2
nframes = len(audio)
comptype = "NONE"
compname = "not compressed"
wav_file.setparams((nchannels, sampwidth, sample_rate, nframes, comptype, compname))
for sample in audio:
wav_file.writeframes(struct.pack('h', int( sample * 32767.0 )))
wav_file.close()
return
print("Input data!\n(binary)")
data=input(">> ")
dataL = []
dataL = split(data)
for x in dataL:
if x == "0":
append_sinewave(freq=200)
elif x == "1":
append_sinewave(freq=800)
append_sinewave(freq=1600,duration_milliseconds=5)
print("Making "+str(x)+" beep")
print("\nWriting to file this may take a while!")
save_wav("output.wav")
Thanks for helping in advance!