Metadata-Version: 2.4
Name: radiogrampy
Version: 0.2.1
Summary: Direct MFSK32/MFSK64 decoder and native PCM WAV encoder
Author: Sam Elsamman
License-Expression: MIT
Project-URL: Documentation, https://github.com/selsamman/GramPy/tree/master/docs
Project-URL: Source, https://github.com/selsamman/GramPy/tree/master
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: jsonschema>=4.18
Requires-Dist: numpy
Requires-Dist: Pillow
Requires-Dist: scipy
Dynamic: license-file

# GramPy

GramPy is an importable Python library and command-line tooling for decoding
MFSK32 and MFSK64 transmissions from SigMF IQ recordings. It is maintained as
a standalone project after its extraction from Radiogram.
It also creates native MFSK broadcast WAVs from text, PNG pictures, audio and
silence through its public Python API.

The PyPI distribution name is `radiogrampy`; its Python import name is
`grampy`.

Python 3.11 or newer is required.

## Use as a library

The supported Python interface is `grampy.api`. Decode a SigMF metadata/data
pair into compact text and quality products:

```python
from pathlib import Path

from grampy.api import DecodeConfig, decode_iq_products

products = decode_iq_products(
    meta_path=Path("recording.sigmf-meta"),
    data_path=Path("recording.sigmf-data"),
    config=DecodeConfig(mode="MFSK64"),
    artifact_dir=Path("results/text.manifest.artifacts"),
    artifact_path_prefix="text.manifest.artifacts",
)

for segment in products.text_manifest["mode_segments"]:
    for item in segment["items"]:
        if item["kind"] == "text":
            print(item["text"])
```

## Create an MFSK WAV

The supported encoder interface is also in `grampy.api`. It writes one
caller-selected mono PCM WAV and returns exact start timestamps derived from
the completed file. Every `MfskSegment` includes the required RSID prefix;
use `SilencePart` only when you want an explicit editorial pause.

```python
from pathlib import Path

from grampy.api import MfskSegment, TextPart, encode_mfsk_wav

result = encode_mfsk_wav(
    parts=(
        MfskSegment((TextPart.from_text("HELLO FROM GRAMPY"),), "MFSK32", 1500.0),
    ),
    output_path=Path("out.wav"),
)
print(result.duration_seconds, result.segments[0].contents[0].start_seconds)
```

The encoder requires the base package dependencies, including Pillow for PNG
input; there is no encoder extra and no encoder CLI in version one. See the
[encoder API guide](docs/encoder/api.md) for input, output, failure, and
timestamp behavior. **48-kHz mono PCM16** is the required and qualified
broadcast output. Acceptance, maintenance and performance evidence are
indexed in the [encoder documentation](docs/encoder/README.md).

`decode_iq_products` returns validated, JSON-compatible text and quality
manifests; it does not write them to disk. `decode_iq` remains available for
the detailed diagnostic manifest. The optional artifact arguments control where
large decoded-picture artifacts are written. See [the Python API guide](https://github.com/selsamman/GramPy/blob/master/docs/decoder/api.md)
for the supported arguments, configuration, result contract, errors, and
artifact behavior. The [manifest schema](https://github.com/selsamman/GramPy/blob/master/src/grampy/schemas/mfsk-decode-manifest-v1.json)
is the machine-readable format reference.

## Setup

Create a virtual environment and install GramPy with its runtime dependencies:

```sh
python3 -m venv .venv
.venv/bin/python -m pip install --editable . pillow
```

`Pillow` is used by the image-related test suite. The repository uses a `src/`
layout, so run Python work with both the virtual environment and source tree
selected:

```sh
PYTHONPATH="$PWD/src" PATH="$PWD/.venv/bin:$PATH" \
  .venv/bin/python -m unittest discover -s tests
```

For full-suite runs, experiments, corpus jobs, or other potentially long work,
follow the managed-execution contract in [AGENTS.md](https://github.com/selsamman/GramPy/blob/master/AGENTS.md). The normal Mac
entry point is `tools/mac-local.sh`; place a temporary command batch in the
ignored `.local/mac-command.sh` when needed.

## Tests and corpus

The normal regression suite runs without large external artifacts. Tests that
need received IQ or controlled generated fixtures skip cleanly when those
optional inputs are absent.

See [tests/README.md](https://github.com/selsamman/GramPy/blob/master/tests/README.md) to install an optional received-IQ
corpus, point tests at an existing corpus, or package one for controlled
distribution. Large samples are never committed to this repository.

## Decode a SigMF recording

GramPy includes a command-line adapter for reproducible decoder work on a
SigMF metadata/data pair:

```sh
tools/mfsk-iq-decode \
  --in-meta recording.sigmf-meta \
  --in-data recording.sigmf-data \
  --out-text-manifest results/text.manifest.json \
  --out-quality-manifest results/quality.manifest.json
```

The default automatic mode decodes every resolved MFSK32 and MFSK64 segment
and the pictures carried by both modes in one run. The command writes
ordered readable text and one-second reception and decode quality data.
Add `--out-manifest results/decode.json` to request the large diagnostic
manifest as well, or use that option alone for the legacy invocation.
Large decoded pictures are written beside the compact manifests in
`results/text.manifest.artifacts/`; small rasters are embedded. See
[the SigMF decode guide](https://github.com/selsamman/GramPy/blob/master/docs/decoder/cli.md) for the accepted metadata, input
formats, interval options, and complete output layout.

## Development

Use [docs/operations/change-management-v1.md](https://github.com/selsamman/GramPy/blob/master/docs/operations/change-management-v1.md)
for continuous-improvement work. It defines the request, baseline, candidate,
evaluation, acceptance, and closeout cycle. Decoder architecture, contracts,
validation guidance, and the accepted baseline are indexed in
[docs/decoder/README.md](https://github.com/selsamman/GramPy/blob/master/docs/decoder/README.md).

Reusable command-line tools are documented in [tools/README.md](https://github.com/selsamman/GramPy/blob/master/tools/README.md).
