Created
December 22, 2009 15:16
-
-
Save emres/261793 to your computer and use it in GitHub Desktop.
A very small and yet-to-be-completed Python program for some sound file renaming.
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
import os | |
import glob | |
import re | |
file_prefix = "prompt_pronunciation_vl_" | |
file_extension = ".wav" | |
index_range = [1, 1139] | |
index = 1 | |
number_of_zeroes = 4 | |
def k(s): | |
""" Used for human / natural sorting. | |
For detailed technical discussion see resources below | |
http://stackoverflow.com/questions/1940056/python-sorts-u11-phrase-1000-wav-before-u11-phrase-101-wav-how-can-i-overcom | |
http://nedbatchelder.com/blog/200712/human_sorting.html | |
http://www.codinghorror.com/blog/archives/001018.html | |
""" | |
return [w.isdigit() and int(w) or w for w in re.split(r'(\d+)', s)] | |
files = glob.glob('*.wav') | |
for file in sorted(files, key=k): | |
if (index >= index_range[0] and index <= index_range[1]): | |
print "Current file = " + file | |
os.rename(file, file_prefix | |
+ (str(index)).zfill(number_of_zeroes) | |
+ file_extension) | |
index = index + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment