Skip to content

Instantly share code, notes, and snippets.

@YuheiNakasaka
Created January 13, 2020 11:11
Show Gist options
  • Save YuheiNakasaka/7824a0385ee735eb3c46aff732ce5b2c to your computer and use it in GitHub Desktop.
Save YuheiNakasaka/7824a0385ee735eb3c46aff732ce5b2c to your computer and use it in GitHub Desktop.
適当な音声ファイルをffmpegでwavにしてsoxでspectrogramを作るやつ
start = 0
sec = 2
if ARGV.length == 3
file = ARGV[0]
start = ARGV[1]
sec = ARGV[2]
else
file = ARGV[0]
end
filename = File.basename(file, '.*')
if !File.exist?(file)
raise "File not exists"
end
wav_file = "#{filename}.wav"
system("ffmpeg -loglevel fatal -y -i #{file} -ac 1 #{wav_file}")
system("sox #{wav_file} -n trim #{start} #{sec} rate 12k spectrogram -y 300 -z 65 -o #{filename}.png")
puts "#{filename}.png successfully created"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment