Connect with us

Convert CSV File to WAV

Discussion in 'Electronic Design' started by [email protected], Apr 7, 2013.

Scroll to continue with content
  1. Guest

    My Hantek signal generator only saves in CSV format. I would like to
    covert this to WAV so it may be played back as an audio loop using one
    of the commonly available Windows programs.

    Does anyone know how to do this "in house", eg. without resorting to a
    specialized scripting language?

    There is an assortment of converters online (one selection below), but
    none I can find that compiles the data into WAV format.

    http://www.bluechillies.com/software/file-conversion-csv-to-wav.html

    It can be done, apprently, if you are proficient in Python.
    Unfortunately, I am not.

    https://gist.github.com/Pretz/1773870

    Arthur Brooks
     
  2. Guest

    No. Saying you have a CSV file is about like saying you have an Excel
    file; it allows you to reliably produce the same set of numbers, but it
    doesn't carry any information about what the numbers represent. You
    have to provide this knowledge to whatever program you use to convert
    the CSV file to something else. For widely-used CSV formats (maybe US
    Census data?) there are ready-made programs for it, but for all the
    other millions of CSV formats in the world, you get to roll your own.

    For jobs like this, it usually works out better to implement the program
    in more of a scripting language (awk, Perl, Python, etc) instead of a
    real, official compiled language (FORTRAN, C, C++, etc). The scripting
    language will have built-in features for parsing the CSV file that you
    will take a long time for you to reimplement badly in an official
    compiled language. Also, the requirements are almost guaranteed to be
    poorly specified, which means more revisions of the code, which is
    usually easier with a scripting language.
    A lot of these are probably wrappers around existing open-source
    libraries that they then charge you $17 to $80 for. Which would be OK
    if the perpetrators provided any end-user support in return, or
    supported further development of the underlying code, but they don't.
    That looks like a reasonable approach, actually. It expects a CSV file
    with two columns: time and amplitude. It reads both values, discards
    the time (it seems to assume that the input data is sampled at 100 kHz),
    keeps the amplitudes in an array, normalizes the entire array, resamples
    to 44.1 kHz, and writes a 16-bit mono 44.1 kHz WAV file.

    I am not sure what a couple of the fixed constants do, so this might die
    or do an incomplete job if you try to convert a really huge file
    (several dozen minutes maybe?), but for shorter files it should be fine.

    On Linux you would save the contents of that github file to (say)
    hantek-csv-converter.py . Then you would put the CSV data in (say)
    hantek.csv in the same directory. Then, in that directory, do

    chmod 755 hantek-csv-converter.py

    ../hantek-csv-converter.py hantek.csv

    and after a bit, a new file named hantek.wav should appear in the same
    directory.

    On Windows you need to install Python for Windows first, which exists.
    If the installer asks you about configuring it to run Python scripts
    from the command line, say yes. Save the contents of that github file
    to (say) hantek-csv-converter.py . Then you would put the CSV data in
    (say) hantek.csv in the same directory. Then, in a cmd.exe window,
    navigate to that directory, and do

    python hantek-csv-converter.py hantek.csv

    and after a bit, a new file named hantek.wav should appear in the same
    directory.

    If the only thing that will do is a single .exe with a nice happy clicky
    interface, you'll probably either need to get it from Hantek or pay to
    have one written. It will probably be cheaper to buy a different signal
    generator that saves files in a reasonable format than to buy a custom-
    written program.

    Matt Roberds
     
  3. miso

    miso Guest

    I've done the reverse with sox, i.e. wave to data. The webpage says it
    can take data to wav, but I doubt you will be doing this without minimal
    scripting or a simple program. Sox can't anticipate every data format. The C programs I've thrown together for reformatting data are less than
    a hundred lines. It isn't a major project.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-