Skip to main content

Tiny data-over-sound library.

Project description

Tiny data-over-sound library.

# generate audio waveform for string "hello python"
waveform = ggwave.encode("hello python")

# decode audio waveform
text = ggwave.decode(instance, waveform)

Features

  • Audible and ultrasound transmissions available

  • Bandwidth of 8-16 bytes/s (depending on the transmission protocol)

  • Robust FSK modulation

  • Reed-Solomon based error correction

Installation

pip install ggwave

API

encode()

encode(payload, [protocolId], [volume], [instance])

Encodes payload into an audio waveform.

Output of help(ggwave.encode):

built-in function encode in module ggwave

encode(...)
    Encode payload into an audio waveform.
    @param {string} payload, the data to be encoded
    @return Generated audio waveform bytes representing 16-bit signed integer samples.

decode()

decode(instance, waveform)

Analyzes and decodes waveform into to try and obtain the original payload. A preallocated ggwave instance is required.

Output of help(ggwave.decode):

built-in function decode in module ggwave

decode(...)
    Analyze and decode audio waveform to obtain original payload
    @param {bytes} waveform, the audio waveform to decode
    @return The decoded payload if successful.

Usage

  • Encode and transmit data with sound:

import ggwave
import pyaudio

p = pyaudio.PyAudio()

# generate audio waveform for string "hello python"
waveform = ggwave.encode("hello python", protocolId = 1, volume = 20)

print("Transmitting text 'hello python' ...")
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=48000, output=True, frames_per_buffer=4096)
stream.write(waveform, len(waveform)//4)
stream.stop_stream()
stream.close()

p.terminate()
  • Capture and decode audio data:

import ggwave
import pyaudio

p = pyaudio.PyAudio()

stream = p.open(format=pyaudio.paFloat32, channels=1, rate=48000, input=True, frames_per_buffer=1024)

print('Listening ... Press Ctrl+C to stop')
instance = ggwave.init()

try:
    while True:
        data = stream.read(1024, exception_on_overflow=False)
        res = ggwave.decode(instance, data)
        if (not res is None):
            try:
                print('Received text: ' + res.decode("utf-8"))
            except:
                pass
except KeyboardInterrupt:
    pass

ggwave.free(instance)

stream.stop_stream()
stream.close()

p.terminate()

More

Check out http://github.com/ggerganov/ggwave for more information about ggwave!

Development

Check out ggwave python package on Github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ggwave_fork-0.4.2.tar.gz (76.7 kB view details)

Uploaded Source

Built Distribution

ggwave_fork-0.4.2-cp311-cp311-macosx_14_0_arm64.whl (56.4 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

File details

Details for the file ggwave_fork-0.4.2.tar.gz.

File metadata

  • Download URL: ggwave_fork-0.4.2.tar.gz
  • Upload date:
  • Size: 76.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for ggwave_fork-0.4.2.tar.gz
Algorithm Hash digest
SHA256 58e127da2f373f68752530b0f589e6c7b3da6e1d750f44b9bbe4f9d14057eabd
MD5 c5cc87a14db590fef5ca01c67ddaaa8b
BLAKE2b-256 5f8682ab032f51740b3309b85f328f1ac89248f1e76010d9efc06c6debe579a3

See more details on using hashes here.

File details

Details for the file ggwave_fork-0.4.2-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for ggwave_fork-0.4.2-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a37d5cd2d1fdc54bb2cf72dc57cb8ba4b6cbef292f87e2d26c727e92b5a78222
MD5 750c4720312bf5743f9d3082a263230e
BLAKE2b-256 fb4fff26b4a8151d0fba53508f179af5a4522a667889d90221a160cdbbb97b97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page