#!/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