Last active
March 19, 2021 13:47
-
-
Save htakeuchi/aa8bca798ae0ff07af57a9c87a34a52c to your computer and use it in GitHub Desktop.
mp3とwavを相互変換する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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