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).

  • $\begingroup$ Do you mean that you want the "common audio player" to convert the data to a waveform? $\endgroup$
    – Jim Clay
    Commented Dec 5, 2012 at 14:15
  • $\begingroup$ 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? $\endgroup$ Commented Dec 5, 2012 at 15:01
  • $\begingroup$ You could do it in Octave, which is a freeware program that is similar to Matlab. $\endgroup$
    – Jim Clay
    Commented Dec 5, 2012 at 15:05
  • $\begingroup$ 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)? $\endgroup$
    – penelope
    Commented Dec 6, 2012 at 10:02
  • 1
    $\begingroup$ 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 dsp.stackexchange.com/questions/4708/…). If you want to do data visualization, there are better tools (octave, python+numpy+matplotlib, R). $\endgroup$ Commented Dec 6, 2012 at 20:32

2 Answers 2


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 = wave.open(filename, 'wb')
sound.setparams((1, 2, samplerate, 1, 'NONE', 'noncompressed'))

# plotting spectrogram

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.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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