Created
May 2, 2012 01:54
-
-
Save ktibb/2573000 to your computer and use it in GitHub Desktop.
Phoneme Phenom: breaking top-40 songs into phonemes
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
import random | |
songs = ["1.txt", "2.txt", "3.txt", "4.txt", "5.txt", "6.txt", "7.txt", "8.txt", "9.txt", "10.txt", "11.txt", "12.txt", "13.txt", "14.txt", "15.txt", "16.txt", "17.txt", "18.txt", "19.txt", "20.txt", "21.txt"] | |
dictfile = "cmuDict.txt" | |
cmu = open(dictfile, "r") | |
dictlines = cmu.readlines() | |
cmu.close() | |
phoneme = {} | |
for dictlines in open(dictfile): | |
#regex in split=> all the characters in a row after /n until the space OR beginning of a string to space | |
key, value = dictlines.split (' ') | |
phoneme[key] = str (value) | |
#print value | |
#open random txt file | |
randSong = random.choice(songs) | |
text = open (randSong, "r") | |
lines = text.readlines() | |
#print (lines) | |
#print (type(lines)) => is a list | |
for line in lines: | |
words = line.split(" ") | |
#print words | |
#print (type(words)) => each line is a list of seperate words | |
# search for each word(from txt file) in dictionary | |
for word in words: | |
if word.upper() in phoneme.keys(): | |
print phoneme[word.upper()].replace('0', ' ').replace('1',' ').replace('2',' ').replace('3',' ').replace('4',' ').replace(')',' ').replace('(',' '), | |
else: | |
print word, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment