Here is a simple script in Ruby that converts FLAC to MP3, sending the decoded FLAC output to the LAME MP3 encoder (avoiding temporary files):
#!/usr/bin/env ruby
require 'open3'
def convert_flac_to_mp3(input_file)
input_file = File.basename(input_file)
output_file = "#{input_file}.mp3"
Open3.popen3("flac.exe", "-d", "-c", input_file) do |stdin, stdout, stderr, wait_thr|
Open3.popen3("lame.exe", "-o", output_file) do |lame_stdin, _, lame_stderr, _|
stdout.each_line do |line|
lame_stdin.write(line)
end
wait_thr.value
lame_stdin.close
end
end
end
# Usage example:
convert_flac_to_mp3('path/to/your/input.flac')
This script uses the open3 library to run the flac and lame command-line tools and pipe the decoded FLAC output to the LAME MP3 encoder. It avoids temporary files by piping the output directly.
Please note that you need to have the flac and lame command-line tools installed on your system for this script to work.
References: