Skip to content

Instantly share code, notes, and snippets.

@htakeuchi
Last active March 19, 2021 13:47
Show Gist options
  • Save htakeuchi/aa8bca798ae0ff07af57a9c87a34a52c to your computer and use it in GitHub Desktop.
Save htakeuchi/aa8bca798ae0ff07af57a9c87a34a52c to your computer and use it in GitHub Desktop.
mp3とwavを相互変換する
#!/usr/bin/env ruby
def usage
$stderr.puts "usage: wavmp3 file [file ...]"
exit 1
end
usage if ARGV.size < 1
ARGV.each do |f|
/(\..+?)$/ =~ f
next if $1.nil?
case $1.downcase
when ".mp3"
d =f.sub(/\..+?$/, ".wav")
system %!ffmpeg -i "#{f}" -vn -ac 2 -ar 44100 -acodec pcm_s16le -f wav "#{d}"!
when ".wav"
d =f.sub(/\..+?$/, ".mp3")
system %!ffmpeg -i "#{f}" -vn -ac 2 -ar 44100 -ab 192k -acodec libmp3lame -f mp3 "#{d}"!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment