Last active
March 19, 2019 10:25
-
-
Save YuheiNakasaka/227ddf5da0104d45b7845fff0b8a28ca to your computer and use it in GitHub Desktop.
サンプルボイスとかのmp3 urlから声紋画像を得る
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
# Usage: | |
# ruby spectrogram.rb <FILE URL> | |
# Example: | |
# ruby spectrogram.rb http://www.imenterprise.jp/voice/voice/v86.mp3 | |
unless ARGV[0].nil? | |
filename = File.basename(ARGV[0]).sub(/\..*/, '') | |
start = ARGV[1] || 0 | |
duration = ARGV[2] || 1.5 | |
system("wget #{ARGV[0]} -O #{filename}.mp3") | |
system("ffmpeg -y -i #{filename}.mp3 -vn -ac 2 -ar 44100 -acodec pcm_s16le -f wav #{filename}.wav") | |
system("sox #{filename}.wav -n trim #{start} #{duration} rate 40k spectrogram -z 60 -o #{filename}.png") | |
system("rm #{filename}.mp3 #{filename}.wav") | |
else | |
puts "set mp3 URL" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment