Capturing from sound file #38
-
Hi! I've been trying to capture ggwave data from a recorded sound file and I was hoping someone else has tried before and might be able to help. I'm using Python, although code examples in any language would be appreciated. I'm basing my code on the Does this make sense so far, or have I missed any parameters? The one thing I'm not sure is whether it should be little- or big-endian (is it platform-specific, or does PortAudio have a preference?), but I've tested both and never got any reads. Here's my code so far, if anyone can spot something obviously wrong (`ggwave_from_file` is the entrypoint)import ggwave
import pyaudio
import ffmpeg
# FRAME_SIZE=4 # 32-bit samples @ 1 channel
FRAME_SIZE = 4
BUFFER_SIZE = 1024*FRAME_SIZE
parameters = ggwave.getDefaultParameters()
parameters["payloadLength"] = 16
instance = ggwave.init(parameters)
def read_audio(filename):
process = (ffmpeg
.input(filename)
.output('-', format='f32le', acodec='pcm_f32le', ar=4800, ac=1)
.global_args('-map_metadata', '-1', '-vn')
.overwrite_output()
.run_async(pipe_stdout=True)
)
while process.poll() is None:
packet = process.stdout.read(BUFFER_SIZE)
yield packet
process.wait()
def ggwave_decode(audio):
for chunk in audio:
res = ggwave.decode(instance, chunk)
if res:
text = res.decode("utf-8")
yield text
def ggwave_from_file(filename):
audio = read_audio(filename)
decoder = ggwave_decode(audio)
for msg in decoder:
print(msg)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Nevermind, I'm a complete idiot 🤦 I had the sample rate set to Anyways, I guess I'll leave this here as a code example since after fixing the stupid mistake, the code works very well. |
Beta Was this translation helpful? Give feedback.
Nevermind, I'm a complete idiot 🤦 I had the sample rate set to
4800
instead of48000
! How this single zero managed to evade me for many hours of debugging is absolutely beyond me.....Anyways, I guess I'll leave this here as a code example since after fixing the stupid mistake, the code works very well.