Last active
October 3, 2019 14:05
-
-
Save igorgue/96dea6585f7d6c3b9d2d to your computer and use it in GitHub Desktop.
This script formats audio files to the Bastl Instrument's GrandPA's format, to use just install ffmpeg (brew install ffmpeg), copy it to a directory with files that end in ('.mp3', '.wav', '.aiff', '.ogg') and run it. It overwrites everything too so be careful (try first, it works for me).
This file contains hidden or 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 | |
# What's this? | |
# ============ | |
# | |
# A script that converts all kinds of files to the file format Bastl Instruments GrandPA requires. | |
# | |
# Install | |
# ======= | |
# | |
# 1. Put all your files inside of the root dir of the SD card | |
# 2. Copy this file to it | |
# 3. Open terminal and run it | |
cwd = File.expand_path(File.dirname(__FILE__)) | |
supported_extentions = ['.mp3', '.wav', '.aiff', '.ogg'] | |
# According to the manual: | |
# | |
# The files on the SD card need to be in the root directory and have specific | |
# names e.g.: P0.wav -P9.wav, PA.wav -PZ.wav etc. The first letter of the name | |
# has to be a capital P and second # letter 0-9 or A-Z (also capital). | |
# | |
# Samples have to be 22050hz, 16bit, mono wav files. (they can also be 44.1khz, but the sample rate will not | |
# allow pitch up then). | |
numbers_files = (0..9).map { |number| "P#{number}.wav" } | |
letters_files = ('A'..'Z').map { |letter| "P#{letter}.wav" } | |
grandpa_language_file_names = numbers_files + letters_files | |
failed_files = [] # due to the limited amount of file names we can have | |
('A'..'Z').each do |letters| | |
grandpa_language_file_names | |
end | |
Dir.glob("#{cwd}/*").each do |file| | |
next unless File::file?(file) | |
next unless supported_extentions.any? { |extension| file.end_with? extension } | |
if grandpa_language_file_names.any? | |
grandpa_name = grandpa_language_file_names.shift | |
command_to_run = "ffmpeg -y -i #{file} -acodec pcm_s16le -ac 1 -ar 22050 #{grandpa_name}" | |
puts "ORIGINAL FILE: #{file} ... GRANDPA NAME: #{grandpa_name}" | |
# Run command, oh ruby joy | |
puts command_to_run | |
`#{command_to_run}` | |
else | |
failed_files << file | |
end | |
end | |
if failed_files.any? | |
puts "The following files did not convert due to the limited amount of files names we can have: \n" | |
failed_files.each do |failed_file| | |
puts failed_file | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cd /Volumes/GRANDPA
to go to grandpa's dir.