Learn how to create a SSTV audio file with different formats using Python in Ubuntu 18.04.

How to create Slow-Scan Television transmissions (SSTV) audio files with Python in Ubuntu 18.04

The earlier modes of SSTV transmission were displayed on long persistent monitors with radar CRT. The duration of transmission for each image frame took 7.2 to 8 seconds, and when the last line was received the first line was still visible. It was possible to see the whole picture in a darkened room.

The most known format of this kind of transmission is the Martin system. The Martin system allows us to work with four different modes/speeds. The most popular version is the Martin M1 with 256 lines per frame in two minutes. Other modes of the Martin system have either half the line or half the horizontal resolution of the best quality M1. The mode M4 has the lowest quality and 128 lines. Modes Martin M1 and M2 are often used between European stations:

Mode name Transfer time Resolution Color sequence Scan line (ms) Speed (1pm)
Sync G B R
Martin M1 114 s 320 X 256 G—B—R. 4.862 146.432 146.432 146.432 134.394753
Martin M2 58 s 160 X 256 G—B—R 4.862 73.216 73.216 73.216 264.552598
Martin M3 57 s 320 X 128 G—B—R. 4.862 146.432 146.432 146.432 134.394753
Martin M4 29 s 160 X 128 G—B—R. 4.862 73.216 73.216 73.216 264.552598

In this article, we'll explain you briefly how you can convert an image into a SSTV audio file using the pySSTV library in Python on your Ubuntu 18.04 desktop.

Install requirements

In order to work with the pySSTV library, you will need to install the python-pil library on your system. The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities.

You can install it on your system with the following command in the terminal:

sudo apt-get install python-pil

You will need as well the six module of python installed. Six provides simple utilities for wrapping over differences between Python 2 and Python 3. It is intended to support codebases that work on both Python 2 and 3 without modification. six consists of only one Python file, so it is painless to copy into a project. You can install it with PIP, however if you don't have pip installed, install it first with:

sudo apt-get install python-pip

And after having pip available, install it with:

pip install six

Now that you have the libraries required by pySSTV you will be able to download it and use it from your terminal.

1. Download pySSTV

Download the pySSTV project with Git using the following command (if you don't have git installed, install it with sudo apt-get install git):

git clone https://github.com/dnet/pySSTV.git

PySSTV generates SSTV modulated WAV files from any image that PIL can open (PNG, JPEG, GIF, and many others). These WAV files then can be played by any audio player connected to a shortwave radio for example. The main motivation of the developer was to understand how the internals of SSTV work in practice, so performance is far from optimal in this library, but the results are pretty functional. The code is easily readable, and only performed such optimizations that wouldn't have complicated the codebase.

For more information about this library, please visit the official repository at Github here.

2. Creating the SSTV audio file from an image

In the cloned repository, you will find the pysstv.py file that is basically the code of the tool. You can execute this tool to generate a SSTV audio file from an image that you can decode with special tools that support this kind of data. The script supports the following formats:

  • MartinM1
  • MartinM2
  • ScottieS1
  • ScottieS2
  • Robot36
  • PasokonP3
  • PasokonP5
  • PasokonP7
  • PD90
  • PD120
  • PD160
  • PD180
  • PD240
  • Robot8BW
  • Robot24BW

The mode can be specified with the --mode flag. The command expects 2 positional arguments (input path of the image to convert) in the respective order. Besides it supports the following options:

  • --help: show this help message and exit
  • --mode: {MartinM1,MartinM2,ScottieS1,ScottieS2,Robot36,PasokonP3,PasokonP5,PasokonP7,PD90,PD120D160,PD180,PD240,Robot8BW,Robot24BW}, the default image mode is the Martin M1
  • --rate: RATE sampling rate (default: 48000)
  • --bits: BITS bits per sample (default: 16)
  • --vox: add VOX tones at the beginning
  • --fskid: FSKID add FSKID at the end
  • --chan: CHAN number of channels (default: mono)

The easiest way to generate the audio file from an image is with the following command, where pysstv corresponds to the path of the script. We'll use the MartinM1 mode, but you are free to use the format that you want:

python -m pysstv --mode MartinM1 ./path-to/input-picture.jpg ./output-audio.wav

After running the command, it will generate the output-audio.wav file that contains the audio with frequencies of the specified format. The SSTV class in the sstv module implements basic SSTV-related functionality, and the classes of other modules such as grayscale and color extend this. Most instances implement the following methods:

  • __init__ takes a PIL image, the samples per second, and the bits per sample as a parameter, but doesn't perform any hard calculations
  • gen_freq_bits generates tuples that describe a sine wave segment with frequency in Hz and duration in ms
  • gen_values generates samples between -1 and +1, performing sampling according to the samples per second value given during construction
  • gen_samples generates discrete samples, performing quantization according to the bits per sample value given during construction
  • write_wav writes the whole image to a Microsoft WAV file

The above methods all build upon those above them, for example write_wav calls gen_samples, while latter calls gen_values, so typically, only the first and the last, maybe the last two should be called directly, the others are just listed here for the sake of completeness and to make the flow easier to understand.

You can learn how to decode this audio file into an image again in Ubuntu 18.04 as well if you read this tutorial.

Happy coding !

Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Become a more social person