├── test ├── __init__.py └── test_util.py ├── Utilities ├── __init__.py ├── util.py ├── tts.py ├── convertsounds.py ├── phonemes.py └── convertphonemes.py ├── requirements.txt ├── data ├── pronunciation.csv └── voices │ ├── 00.wav │ ├── 01.wav │ ├── 02.wav │ ├── 03.wav │ ├── 04.wav │ ├── 05.wav │ ├── 06.wav │ ├── 07.wav │ ├── 08.wav │ ├── 09.wav │ ├── 10.wav │ ├── 11.wav │ ├── 12.wav │ ├── 13.wav │ ├── 14.wav │ ├── 15.wav │ ├── 16.wav │ ├── 17.wav │ ├── 18.wav │ ├── 19.wav │ ├── 20.wav │ ├── 21.wav │ ├── 22.wav │ ├── 23.wav │ ├── 24.wav │ ├── 25.wav │ ├── 26.wav │ ├── 27.wav │ ├── 28.wav │ ├── 29.wav │ ├── 30.wav │ ├── 31.wav │ ├── 32.wav │ ├── 33.wav │ ├── 34.wav │ ├── 35.wav │ ├── 36.wav │ ├── 37.wav │ ├── 38.wav │ ├── 39.wav │ ├── 40.wav │ ├── 41.wav │ ├── 42.wav │ ├── 43.wav │ ├── 44.wav │ ├── 45.wav │ ├── 46.wav │ ├── 47.wav │ └── 48.wav ├── .gitignore ├── SpeechSynthesis.py └── README.md /test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Utilities/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | future 2 | -------------------------------------------------------------------------------- /data/pronunciation.csv: -------------------------------------------------------------------------------- 1 | राज, 32 1 43 44 2 | सार्थक, 33 1 32 37 26 44 -------------------------------------------------------------------------------- /data/voices/00.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/00.wav -------------------------------------------------------------------------------- /data/voices/01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/01.wav -------------------------------------------------------------------------------- /data/voices/02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/02.wav -------------------------------------------------------------------------------- /data/voices/03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/03.wav -------------------------------------------------------------------------------- /data/voices/04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/04.wav -------------------------------------------------------------------------------- /data/voices/05.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/05.wav -------------------------------------------------------------------------------- /data/voices/06.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/06.wav -------------------------------------------------------------------------------- /data/voices/07.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/07.wav -------------------------------------------------------------------------------- /data/voices/08.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/08.wav -------------------------------------------------------------------------------- /data/voices/09.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/09.wav -------------------------------------------------------------------------------- /data/voices/10.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/10.wav -------------------------------------------------------------------------------- /data/voices/11.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/11.wav -------------------------------------------------------------------------------- /data/voices/12.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/12.wav -------------------------------------------------------------------------------- /data/voices/13.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/13.wav -------------------------------------------------------------------------------- /data/voices/14.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/14.wav -------------------------------------------------------------------------------- /data/voices/15.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/15.wav -------------------------------------------------------------------------------- /data/voices/16.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/16.wav -------------------------------------------------------------------------------- /data/voices/17.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/17.wav -------------------------------------------------------------------------------- /data/voices/18.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/18.wav -------------------------------------------------------------------------------- /data/voices/19.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/19.wav -------------------------------------------------------------------------------- /data/voices/20.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/20.wav -------------------------------------------------------------------------------- /data/voices/21.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/21.wav -------------------------------------------------------------------------------- /data/voices/22.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/22.wav -------------------------------------------------------------------------------- /data/voices/23.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/23.wav -------------------------------------------------------------------------------- /data/voices/24.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/24.wav -------------------------------------------------------------------------------- /data/voices/25.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/25.wav -------------------------------------------------------------------------------- /data/voices/26.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/26.wav -------------------------------------------------------------------------------- /data/voices/27.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/27.wav -------------------------------------------------------------------------------- /data/voices/28.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/28.wav -------------------------------------------------------------------------------- /data/voices/29.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/29.wav -------------------------------------------------------------------------------- /data/voices/30.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/30.wav -------------------------------------------------------------------------------- /data/voices/31.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/31.wav -------------------------------------------------------------------------------- /data/voices/32.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/32.wav -------------------------------------------------------------------------------- /data/voices/33.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/33.wav -------------------------------------------------------------------------------- /data/voices/34.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/34.wav -------------------------------------------------------------------------------- /data/voices/35.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/35.wav -------------------------------------------------------------------------------- /data/voices/36.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/36.wav -------------------------------------------------------------------------------- /data/voices/37.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/37.wav -------------------------------------------------------------------------------- /data/voices/38.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/38.wav -------------------------------------------------------------------------------- /data/voices/39.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/39.wav -------------------------------------------------------------------------------- /data/voices/40.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/40.wav -------------------------------------------------------------------------------- /data/voices/41.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/41.wav -------------------------------------------------------------------------------- /data/voices/42.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/42.wav -------------------------------------------------------------------------------- /data/voices/43.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/43.wav -------------------------------------------------------------------------------- /data/voices/44.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/44.wav -------------------------------------------------------------------------------- /data/voices/45.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/45.wav -------------------------------------------------------------------------------- /data/voices/46.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/46.wav -------------------------------------------------------------------------------- /data/voices/47.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/47.wav -------------------------------------------------------------------------------- /data/voices/48.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raj2503/Python-Text-To-Speech-Hindi/HEAD/data/voices/48.wav -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | output.wav 5 | test/ 6 | -------------------------------------------------------------------------------- /SpeechSynthesis.py: -------------------------------------------------------------------------------- 1 | from Utilities import tts 2 | 3 | if __name__ == "__main__": 4 | # message = input("Message: ") 5 | message = "मैं राज हूं" 6 | 7 | # for i in message: 8 | # print(i) 9 | 10 | tts.text_to_speech(message, debug=True, use_pronunciation_dict=True) -------------------------------------------------------------------------------- /test/test_util.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from synthme import util 4 | 5 | class TestUtil(unittest.TestCase): 6 | def test_get_pronunciation(self): 7 | self.assertEqual(util.get_pronunciation("me"), [28, 7]) 8 | def test_tokenize(self): 9 | self.assertEqual(util.tokenize("test message"), ["test", "message"]) 10 | self.assertEqual(util.tokenize("test"), ["test"]) 11 | self.assertEqual(util.tokenize(""), []) -------------------------------------------------------------------------------- /Utilities/util.py: -------------------------------------------------------------------------------- 1 | PRONUNCIATION_CSV_PATH = "data/pronunciation.csv" 2 | 3 | import csv, re 4 | 5 | # Convert raw user input to a list of words 6 | def tokenize(data): 7 | word = [] 8 | word = data.split(" ") 9 | word = re.split('; |, |\*|\n| ',data) 10 | return word 11 | 12 | 13 | def get_pronunciation(word): 14 | with open(PRONUNCIATION_CSV_PATH, 'rt',encoding="utf8") as f: 15 | reader = csv.reader(f, delimiter=',') 16 | for row in reader: 17 | if word == row[0]: 18 | numbers = row[1].strip().split(' ') 19 | # map string to integers 20 | return list(map(int, numbers)) 21 | -------------------------------------------------------------------------------- /Utilities/tts.py: -------------------------------------------------------------------------------- 1 | # Pulls all three pieces together: convertwords, convertphonemes, convertsounds 2 | 3 | OUTPUT_FILE = "output.wav" 4 | 5 | from Utilities import convertphonemes, convertsounds, util 6 | 7 | def text_to_speech(message, output_file=OUTPUT_FILE, debug=False, use_pronunciation_dict=True): 8 | if debug: print("Text to Speech Generation started.") 9 | print(message) 10 | words = util.tokenize(message) 11 | print(words) 12 | if debug: print("Words list: " + str(words)) 13 | phonemes = convertphonemes.words_to_phonemes(words, use_pronunciation_dict) 14 | if debug: print("Phonemes list: " + str(phonemes)) 15 | convertsounds.phonemes_to_sounds(phonemes, output_file) 16 | if debug: print("File created.") 17 | -------------------------------------------------------------------------------- /Utilities/convertsounds.py: -------------------------------------------------------------------------------- 1 | # Matches each phoneme from list with appropriate wav file 2 | 3 | from Utilities import phonemes 4 | import wave, os 5 | 6 | VOICE_PATH = os.path.dirname(__file__) + "/../data/voices/" 7 | 8 | def phonemes_to_sounds(phoneme_list, outfile): 9 | infiles = [] 10 | for phoneme in phoneme_list: 11 | infiles.append(get_sound_file(phoneme)) 12 | data = [] 13 | for infile in infiles: 14 | w = wave.open(infile, 'rb') 15 | data.append( [w.getparams(), w.readframes(w.getnframes())] ) 16 | w.close() 17 | 18 | output = wave.open(outfile, 'wb') 19 | output.setparams(data[0][0]) 20 | for idx, val in enumerate(data): 21 | output.writeframes(data[idx][1]) 22 | output.close() 23 | 24 | def get_sound_file(phoneme): 25 | fname = "%02d" % phoneme 26 | return VOICE_PATH + fname + ".wav" -------------------------------------------------------------------------------- /Utilities/phonemes.py: -------------------------------------------------------------------------------- 1 | # List of all sounds used 2 | 3 | VOWEL_U = 0 # अ 4 | VOWEL_A = 1 # आ 5 | VOWEL_AE = 2 # ए 6 | VOWEL_E = 3 # ऐ 7 | VOWEL_EE = 4 # away 8 | VOWEL_UU = 5 # turn 9 | VOWEL_I = 6 # इ 10 | VOWEL_II = 7 # ई 11 | VOWEL_O = 8 # hot 12 | VOWEL_CA = 9 # औ 13 | VOWEL_PU = 10 # उ 14 | VOWEL_OO = 11 # ऊ 15 | VOWEL_AI = 12 # five 16 | VOWEL_AU = 13 # out 17 | VOWEL_EI = 14 # eight 18 | VOWEL_OH = 15 # ओ 19 | VOWEL_OI = 16 # join 20 | VOWEL_ER = 17 # where 21 | VOWEL_IE = 18 # near 22 | VOWEL_UE = 19 # य 23 | 24 | CONS_B = 20 # ब 25 | CONS_D = 21 # ड ढ 26 | CONS_F = 22 # फ 27 | CONS_G = 23 # ग घ 28 | CONS_H = 24 # ह 29 | CONS_Y = 25 # य 30 | CONS_K = 26 # ख क 31 | CONS_L = 27 # ल 32 | 33 | CONS_M = 28 # म 34 | CONS_N = 29 # न ञ ण 35 | CONS_NG = 30 # ं 36 | CONS_P = 31 # प भ 37 | CONS_R = 32 # र 38 | CONS_S = 33 # स 39 | CONS_SH = 34 # श ष 40 | CONS_T = 35 # ट 41 | CONS_CH = 36 # च 42 | CONS_TH = 37 # थ ठ ध 43 | CONS_TH2 = 38 # द 44 | CONS_V = 39 # व 45 | CONS_W = 40 # wet 46 | CONS_Z = 41 # ज़ 47 | CONS_JJ = 42 # छ झ 48 | CONS_J = 43 # ज 49 | 50 | PUNC_PERIOD = 44 # period (long pause) 0.5 51 | PUNC_COMMA = 44 # comma (short pause) 0.3 52 | PUNC_QUESTION = 44 # question 0.5 53 | PUNC_EXCLAIM = 44 # exclamation 0.5 54 | # to do 55 | PAUSE_WORD = 44 # very short pause 0.2 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## **Python Hindi TTS** 2 | It is a Concatenative Text-to-Speech system implemented in Python. 3 | 4 | We started this project in October 2021 as **Natural Language Processing** Course-Work project. 5 | 6 | A concatenative text-to-speech system creates an audio representation of text by pasting together a bunch of small audio files to form the whole of the output. 7 | 8 | There are three steps, including: 9 | 10 | * **Text-to-words**, where raw input text is tokenized into an list of words. This also generally includes converting numerical digits into their word equivalents (ex: turn "5" into "five"). 11 | * **Words-to-phonemes**, where the array of words is converted into phonemes. Phonemes are the individual sounds in a language. As Hindi has a very vast phonetic genre, the hindi alphabetic pronunciation can vary change the pronunciation of the whole word. System has already mapped the hindi phonetic sounds to their alphabets, so whenever the alphabet is detected, the system just maps to its audio file and return its number. The output is an list of numbers that each correspond to one of the 44 hindi phonemes. 12 | * **Phonemes-to-sounds**, where each phoneme is paired with an audio file. This is the point where the actual audio is stitched together. It would also be in this step that the correct voice for the audio is selected, assuming multiple voices are supported. 13 | 14 | Do refer to [Synthme][2] if want the English implementation of the same. It was a really inspiring and helpful resource to us. 15 | 16 | ## Future Work 17 | Right now the system has only one voice, that is mine and my project buddy's [@SarthakSavasil][1]. We would love to add a few more voices to it. 18 | Also the Phoneme database is limited to only 44 audio files (at the time I am writing this) covering all the major and frequently used Hindi Alphabets. 19 | So we need to build a bigger Phonetic voice database. 20 | 21 | **Do contribute to it if you can. It will really help us and make this project grow.** 22 | 23 | ## Dependencies 24 | This project relies on 25 | * Python 3x. 26 | * re (for tokenization) 27 | * wave and os (for stiching together the audio files) 28 | 29 | ## Installation 30 | Follow the steps below to try the speech synthesizer out. 31 | 32 | 1. Make sure that all dependencies are installed. 33 | 2. Open a terminal and navigate to the cloned directory. 34 | 3. Run: `pip install -r requirements.txt` 35 | 4. Run the command `**python3 SpeechSynthesis.py**` 36 | 5. You will be prompted to input a message. Enter what you want the system to say for you! 37 | 6. The program will generate the output as a .wav file and end. Open output.wav to hear the result. 38 | 39 | [1]:https://github.com/SarthakSavasil 40 | [2]:https://github.com/stephengrice/synth-me 41 | -------------------------------------------------------------------------------- /Utilities/convertphonemes.py: -------------------------------------------------------------------------------- 1 | # Takes list of words and finds appropriate phonemes 2 | # If phoneme not found, an (un)educated guess is made 3 | 4 | from Utilities import phonemes, util 5 | import ast, re 6 | 7 | def words_to_phonemes(words, use_pronunciation_dict=True): 8 | # Takes list of words and punctuation 9 | result = [] 10 | for word in words: 11 | # Check if the word has been learned 12 | row = False 13 | if use_pronunciation_dict: 14 | row = util.get_pronunciation(word) 15 | if row: 16 | # Append the syllables in this word 17 | result.extend(row) 18 | else: 19 | # If not recognized, take an (un)educated guess 20 | blocked = phoneme_scan(word) 21 | result.extend(phoneme_blocks_to_list(blocked)) 22 | result.append(phonemes.PAUSE_WORD) 23 | return result 24 | 25 | def phoneme_blocks_to_list(blocks): 26 | blocks_list = re.findall("\[\d+\]", blocks) 27 | result = [] 28 | for b in blocks_list: 29 | result.append(int(re.sub(r'\[(\d+)\]', r'\1', b))) 30 | return result 31 | 32 | 33 | def phoneme_scan(word): 34 | # Takes a word and returns a string of phonemes 35 | while re.search("[अ-ॐ.,;!?]", word): 36 | 37 | word = replace_with_phoneme(word, "अ", (phonemes.VOWEL_U,)) 38 | word = replace_with_phoneme(word, "आ", (phonemes.VOWEL_A,)) 39 | word = replace_with_phoneme(word, "ा", (phonemes.VOWEL_A,)) 40 | 41 | word = replace_with_phoneme(word, "इ", (phonemes.VOWEL_I,)) 42 | word = replace_with_phoneme(word, "ि", (phonemes.VOWEL_I,)) 43 | word = replace_with_phoneme(word, "ई", (phonemes.VOWEL_II,)) 44 | word = replace_with_phoneme(word, "ी", (phonemes.VOWEL_II,)) 45 | 46 | word = replace_with_phoneme(word, "उ", (phonemes.VOWEL_PU,)) 47 | word = replace_with_phoneme(word, "ु", (phonemes.VOWEL_PU,)) 48 | word = replace_with_phoneme(word, "ऊ", (phonemes.VOWEL_OO,)) 49 | word = replace_with_phoneme(word, "ू", (phonemes.VOWEL_OO,)) 50 | word = replace_with_phoneme(word, "ृ", (phonemes.CONS_R,)) 51 | 52 | word = replace_with_phoneme(word, "ए", (phonemes.VOWEL_AE,)) 53 | word = replace_with_phoneme(word, "े", (phonemes.VOWEL_AE,)) 54 | word = replace_with_phoneme(word, "ॆ", (phonemes.VOWEL_AE,)) 55 | word = replace_with_phoneme(word, "ऐ", (phonemes.VOWEL_E,)) 56 | word = replace_with_phoneme(word, "ै", (phonemes.VOWEL_E,)) 57 | 58 | word = replace_with_phoneme(word, "ओ", (phonemes.VOWEL_OH,)) 59 | word = replace_with_phoneme(word, "ऒ", (phonemes.VOWEL_OH,)) 60 | word = replace_with_phoneme(word, "ो", (phonemes.VOWEL_OH,)) 61 | word = replace_with_phoneme(word, "औ", (phonemes.VOWEL_CA,)) 62 | word = replace_with_phoneme(word, "ौ", (phonemes.VOWEL_CA,)) 63 | word = replace_with_phoneme(word, "ऑ", (phonemes.VOWEL_CA,)) 64 | 65 | word = replace_with_phoneme(word, "क", (phonemes.CONS_K,)) 66 | word = replace_with_phoneme(word, "ख", (phonemes.CONS_K,)) 67 | word = replace_with_phoneme(word, "ग", (phonemes.CONS_G,)) 68 | word = replace_with_phoneme(word, "घ", (phonemes.CONS_G,)) 69 | word = replace_with_phoneme(word, "ङ", (phonemes.CONS_D,)) 70 | 71 | word = replace_with_phoneme(word, "च", (phonemes.CONS_CH,)) 72 | word = replace_with_phoneme(word, "छ", (phonemes.CONS_JJ,)) 73 | word = replace_with_phoneme(word, "ज", (phonemes.CONS_J,)) 74 | word = replace_with_phoneme(word, "झ", (phonemes.CONS_JJ,)) 75 | word = replace_with_phoneme(word, "ञ", (phonemes.CONS_N,)) 76 | 77 | 78 | word = replace_with_phoneme(word, "ट", (phonemes.CONS_T,)) 79 | word = replace_with_phoneme(word, "ठ", (phonemes.CONS_TH,)) 80 | word = replace_with_phoneme(word, "ड", (phonemes.CONS_D,)) 81 | word = replace_with_phoneme(word, "ढ", (phonemes.CONS_D,)) 82 | word = replace_with_phoneme(word, "ण", (phonemes.CONS_N,)) 83 | 84 | word = replace_with_phoneme(word, "त", (phonemes.CONS_TH,)) 85 | word = replace_with_phoneme(word, "थ", (phonemes.CONS_TH,)) 86 | word = replace_with_phoneme(word, "ध", (phonemes.CONS_TH,)) 87 | word = replace_with_phoneme(word, "द", (phonemes.CONS_TH2,)) 88 | word = replace_with_phoneme(word, "न", (phonemes.CONS_N,)) 89 | 90 | word = replace_with_phoneme(word, "प", (phonemes.CONS_P,)) 91 | word = replace_with_phoneme(word, "फ", (phonemes.CONS_F,)) 92 | word = replace_with_phoneme(word, "ब", (phonemes.CONS_B,)) 93 | word = replace_with_phoneme(word, "भ", (phonemes.CONS_P,)) 94 | word = replace_with_phoneme(word, "म", (phonemes.CONS_M,)) 95 | word = replace_with_phoneme(word, "य", (phonemes.CONS_Y,)) 96 | 97 | word = replace_with_phoneme(word, "र", (phonemes.CONS_R,)) 98 | word = replace_with_phoneme(word, "ल", (phonemes.CONS_L,)) 99 | word = replace_with_phoneme(word, "व", (phonemes.CONS_V,)) 100 | word = replace_with_phoneme(word, "श", (phonemes.CONS_SH,)) 101 | word = replace_with_phoneme(word, "ष", (phonemes.CONS_SH,)) 102 | word = replace_with_phoneme(word, "स", (phonemes.CONS_S,)) 103 | word = replace_with_phoneme(word, "ह", (phonemes.CONS_H,)) 104 | 105 | word = replace_with_phoneme(word, "ज़", (phonemes.CONS_Z,)) 106 | 107 | word = replace_with_phoneme(word, ".", (phonemes.PUNC_PERIOD,)) 108 | word = replace_with_phoneme(word, ",", (phonemes.PUNC_COMMA,)) 109 | word = replace_with_phoneme(word, ";", (phonemes.PUNC_COMMA,)) 110 | word = replace_with_phoneme(word, "!", (phonemes.PUNC_EXCLAIM,)) 111 | return word 112 | 113 | def replace_with_phoneme(word, letters, phoneme_ids): 114 | result = "" 115 | for phoneme_id in phoneme_ids: 116 | result += "["+str(phoneme_id)+"]" 117 | return word.replace(letters, result) --------------------------------------------------------------------------------