0

I am trying to convert words of english dictionary into simple phoneme using python. I am using python 3.5 while all the examples are for python 2 +.

For example in the text below of file test.txt:

what a joke 
is your name 
this fall summer singer
well what do I call this thing mister

Here firstly I want to extract each word then convert them to phoneme. This is the result I want

what    WH AT
a       AE
joke    JOH K
is      ES

....and so on

This is my code for python but its too early and too less . Could you please suggest me more as to convert what to WH AT i need to first find if there are letters wh then replace it with WH

 with open ('test.txt',mode='r',encoding='utf8')as f:
      for line in f:
        for word in line.split():
            phenome = word.replace('what', word + ' WH AT')
            print (phenome)
choman
  • 787
  • 1
  • 5
  • 24

1 Answers1

-2

1st, build a dictionary for the phenome mapping. Then replace the word by look up the dictionary

# added full phenome mapping to dict below
dict1 = {'what':'WH AT', 'a':'AE', 'joke':'JOH K', 'is':'ES'}

with open ('test.txt', encoding='utf8') as f:
    for line in f:
        phenome = ' '.join([dict1.get(word, word) for word in line.split()])
        print (phenome)
Skycc
  • 3,496
  • 1
  • 12
  • 18
  • I am working for the whole dictionary . there are 100 thousand words. What you have suggest works but not practical for huge amount of words. – choman Nov 25 '16 at 12:00
  • What i can think of is to save the dict using pickle then load from the pickle file but it still require unpickle and load to memory, not sure if it helps in term of memory and efficiency – Skycc Nov 25 '16 at 12:24