Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to generate a waveform from data (any kind of data: integer, hexadecimal, string, char, binary), in a common audio player, without converting the data to an audio format?

I'm looking for a way to "code" an arbitrary file in to audio (obtain an audio-descriptor of the data).

share|improve this question
Do you mean that you want the "common audio player" to convert the data to a waveform? – Jim Clay Dec 5 '12 at 14:15
when I said common audio player, i mean windows media player or winamp. And yes, i'm trying to see the spectrum or something of the data. But, my doubt is: Can the player understand a set of data that I wrote in an text editor and saved as "audio.wav", for example? – Daniel Bezerra Dec 5 '12 at 15:01
You could do it in Octave, which is a freeware program that is similar to Matlab. – Jim Clay Dec 5 '12 at 15:05
Do you want to write some kind of description of the audio and then play that description, or do you want to somehow convert ("code") an arbitrary file in to audio (like, make an audio-descriptor of the data)? – penelope Dec 6 '12 at 10:02
I don't see any reason why anyone would want to do that. Maybe you could tell us more about your application? If you want to "embed" data into a waveform so that it can be transmitted over an audio channel, this is a digital communications problem... (See…). If you want to do data visualization, there are better tools (octave, python+numpy+matplotlib, R). – pichenettes Dec 6 '12 at 20:32
up vote 2 down vote accepted

If you want a simple way to transform a numeric array in sound, I suggest you to use Python, with the wave module and Numpy numeric package.

Now if you want to analyze the spectrogram of the numbers without listening to anything, then Python's Matplotlib does what you want.

Below is a sample working code that generates a simple tone, saves it to a .wav file, AND displays a spectrogram:

import numpy
import wave
from matplotlib import pyplot as plt

samplerate = 44100

# generate simple sound
sound_data = numpy.sin(numpy.linspace(0,20000,100000))*1000

# converts to a string representation (I suspect there might be a more natural way to do this)
raw = "".join((wave.struct.pack('h', item) for item in sound_data))

# saving to .wav file
filename = 'aaa.wav'
sound =, 'wb')
sound.setparams((1, 2, samplerate, 1, 'NONE', 'noncompressed'))

# plotting spectrogram
share|improve this answer

Many audio players can be tricked into playing an array of raw PCM samples (16-bit signed linear little-endian) simply by pre-pending a 44-byte WAV/RIFF file header copied from another (larger?) .wav file of the same type (sample rate, mono/stereo, etc.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.