Skip to content

Instantly share code, notes, and snippets.

@pimeys
Created January 25, 2012 14:14
Show Gist options
  • Save pimeys/1676435 to your computer and use it in GitHub Desktop.
Save pimeys/1676435 to your computer and use it in GitHub Desktop.
Sound log
require 'rubygems'
require 'bundler/setup'
require 'wavefile'
require 'json'
include WaveFile
format = Format.new(:mono, 16, 1000)
writer = Writer.new("sound.wav", format)
sound_data = JSON.
parse(File.open('log.json', 'r').readlines.first).
detect{|item| item["target"] == "log303"}["datapoints"].
map{|value| value.first ? value.first : 0}
buffer = Buffer.new(sound_data, format)
writer.write(buffer)
writer.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment