From 527403dfeb6273526c5035cfe3a11cb223e7e32e Mon Sep 17 00:00:00 2001 From: not-lain Date: Tue, 17 Feb 2026 12:17:12 +0100 Subject: [PATCH 1/3] fix for windows --- README.md | 7 +++++++ bindings/python/.gitignore | 2 ++ bindings/python/setup.py | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 118def31..161c9ed8 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,13 @@ [![pypi](https://img.shields.io/pypi/v/ggwave.svg)](https://pypi.org/project/ggwave/) [![npm](https://img.shields.io/npm/v/ggwave.svg)](https://www.npmjs.com/package/ggwave/) +## Installation + +You can install the package directly from GitHub: + +```bash +pip install git+https://github.com/not-lain/ggwave.git@python#subdirectory=bindings/python +``` Tiny data-over-sound library. Click on the images below to hear what it sounds like: diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore index 9044a017..f55db96d 100644 --- a/bindings/python/.gitignore +++ b/bindings/python/.gitignore @@ -1,6 +1,8 @@ ggwave.so README.rst ggwave.bycython.cpp +ggwave.cpp +*.pyd ggwave.cpython-*-x86_64-linux-gnu.so ggwave/ ggwave.egg-info/ diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 01016032..56d003ac 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -1,6 +1,8 @@ from setuptools import setup, Extension from codecs import open import os +import sys +import shutil cmdclass = {} long_description = "" @@ -10,6 +12,9 @@ # User has to set environment variable GGWAVE_USE_CYTHON. # e.g.: GGWAVE_USE_CYTHON=1 python setup.py install USE_CYTHON = os.getenv('GGWAVE_USE_CYTHON', False) +if not os.path.exists("ggwave.bycython.cpp"): + USE_CYTHON = True + if USE_CYTHON: from Cython.Build import build_ext ggwave_module_src = "ggwave.pyx" @@ -22,8 +27,33 @@ OMIT_README_RST = os.getenv('GGWAVE_OMIT_README_RST', False) if not OMIT_README_RST: here = os.path.abspath(os.path.dirname(__file__)) - with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: - long_description = f.read() + readme_rst_path = os.path.join(here, 'README.rst') + if os.path.exists(readme_rst_path): + with open(readme_rst_path, encoding='utf-8') as f: + long_description = f.read() + else: + print("WARNING: README.rst undefined") + +# Prepare sources +if not os.path.exists("ggwave"): + os.makedirs("ggwave") + +if not os.path.exists("ggwave/src"): + if os.path.exists("../../src"): + shutil.copytree("../../src", "ggwave/src") + else: + print("WARNING: ../../src undefined") + +if not os.path.exists("ggwave/include"): + if os.path.exists("../../include"): + shutil.copytree("../../include", "ggwave/include") + else: + print("WARNING: ../../include undefined") + +# Compile args +compile_args = ["-O3", "-std=c++11"] +if sys.platform == 'win32': + compile_args = ["/O2"] setup( # Information @@ -42,6 +72,6 @@ include_dirs=["ggwave/include", "ggwave/include/ggwave"], depends=["ggwave/include/ggwave/ggwave.h"], language="c++", - extra_compile_args=["-O3", "-std=c++11"])], + extra_compile_args=compile_args)], cmdclass = cmdclass ) From 9b53157a21bd84c0c59be30c34fd4d523048b6c3 Mon Sep 17 00:00:00 2001 From: not-lain Date: Tue, 17 Feb 2026 12:23:43 +0100 Subject: [PATCH 2/3] add toml file --- README.md | 8 ++++++++ bindings/python/pyproject.toml | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 bindings/python/pyproject.toml diff --git a/README.md b/README.md index 161c9ed8..edc63f46 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,14 @@ You can install the package directly from GitHub: ```bash pip install git+https://github.com/not-lain/ggwave.git@python#subdirectory=bindings/python ``` +or you can run it using uv +``` +uv add "ggwave @ git+https://github.com/not-lain/ggwave.git@python#subdirectory=bindings/python" +``` +to use this package with python you can run the following +```python + + Tiny data-over-sound library. Click on the images below to hear what it sounds like: diff --git a/bindings/python/pyproject.toml b/bindings/python/pyproject.toml new file mode 100644 index 00000000..c07b1d35 --- /dev/null +++ b/bindings/python/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "Cython"] +build-backend = "setuptools.build_meta" From 71c464db55a1b02c3c68a4e4b82a309563886ae7 Mon Sep 17 00:00:00 2001 From: not-lain Date: Tue, 17 Feb 2026 12:29:08 +0100 Subject: [PATCH 3/3] better docs --- README-tmpl.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/README-tmpl.md b/README-tmpl.md index 973e89a8..e67605f0 100644 --- a/README-tmpl.md +++ b/README-tmpl.md @@ -193,6 +193,61 @@ pip install ggwave More info: https://pypi.org/project/ggwave/ +#### Usage + +* Encode and transmit data with sound: + +```python +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: + +```python +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() +``` + ### Node.js ```bash diff --git a/README.md b/README.md index edc63f46..102f3d4c 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,7 @@ or you can run it using uv ``` uv add "ggwave @ git+https://github.com/not-lain/ggwave.git@python#subdirectory=bindings/python" ``` -to use this package with python you can run the following -```python +to use this package with python, check out the [Usage](#usage-1) section. Tiny data-over-sound library. @@ -210,6 +209,61 @@ pip install ggwave More info: https://pypi.org/project/ggwave/ +#### Usage + +* Encode and transmit data with sound: + +```python +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: + +```python +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() +``` + ### Node.js ```bash