#audio #cli #wav #encode #decode

bin+lib data2sound

A library to convert data to sound, and vice versa, supports WASI (dependency-free)

5 releases

0.2.2 Mar 1, 2023
0.2.1 Feb 28, 2023
0.1.6 Feb 26, 2023

#149 in Audio

Download history 88/week @ 2023-02-19 122/week @ 2023-02-26 1/week @ 2023-03-19 10/week @ 2023-03-26 21/week @ 2023-04-02 28/week @ 2023-04-09 16/week @ 2023-04-16 5/week @ 2023-04-30 29/week @ 2023-05-07 4/week @ 2023-05-14 4/week @ 2023-05-21 15/week @ 2023-05-28

53 downloads per month

MIT license

175 lines

Data to sound

A simple crate to convert data to sound, and sound to data. The sound file format is wave (.wav). You can use it as a library or as a command line tool, also supports WASI. (dependency-free)

Minimum supported Rust version

The minimum supported Rust version is 1.59.0.


The sound frequency is 202860Hz (202.86kHz), and the sound is mono. The sound is encoded in 16 bits.


  • The wave file size limit is 4GB, so you can't store more than 4GB of data in a single file.


  • The sound file is a standard .wav file, so you can play it with any audio player.
  • The sound file will be the same size as the data file.


There are two ways to use this crate. As a library, or as a command line tool. The library is the core of the tool, so you can use the library to create your own tool. Also we support WASI, so you can use the cli in a WASI environment.


Add this to your Cargo.toml:

data2sound = "0.2.0"

See the documentation for more information about the library.

Command line Interface

Install the tool with cargo:

cargo install data2sound

Run the tool with:

data2sound --help

And to convert a file to sound:

data2sound encode input_file output_file.wav

And to convert a sound file to data:

data2sound decode input_file.wav output_file


You can use the CLI in a WASI environment. All you need to do is to install the wasm file from the releases page, and to run it with wasmtime or wasmer.

Install with GitHub CLI

gh release download -R TheAwiteb/data2sound -p "*wasm32-wasi.zip"
unzip *wasm32-wasi.zip # The zip file contains the wasm


You need to get access to the directory where the input file is located, and to the directory where the output file will be created. You can do that with the --dir flag. Help message:

wasmtime data2sound.wasm -- --help

Encoding and decoding:

wasmtime data2sound.wasm --dir . --  encode input_file output_file.wav
wasmtime data2sound.wasm --dir . --  decode input_file.wav output_file


The same as with wasmtime Help message:

wasmer data2sound.wasm -- --help

Encoding and decoding:

wasmer data2sound.wasm --dir . --  encode input_file output_file.wav
wasmer data2sound.wasm --dir . --  decode input_file.wav output_file

Use cases

This crate can be used to store data in a sound file, and to retrieve the data from the sound file. This can be useful for storing data in a sound file.


The following benchmarks were made on a 4.600GHz 12th Gen Intel i7-12700H CPU with 16GB of RAM.


File size Audio file size Audio length Speed Link
2687.94MB 2687.94MB 01:28:13 1.47s Soundcloud-link
35.3MB 35.3MB 00:01::27 39.07ms Soundcloud-link


File size Audio file size Audio length Speed Link
2687.94MB 2687.94MB 01:28:13 1.44s Soundcloud-link
35.3MB 35.3MB 00:01::27 38.97ms Soundcloud-link


This tool was designed for educational purposes as it explains how to save data in an audio file. It is not recommended to exploit this thing to use cloud audio storage services to store your data, as your account may be banned.


This project is licensed under the MIT license. See the LICENSE file for more information.

No runtime deps