Skip to content

Commit 8b16202

Browse files
committed
Final Code
1 parent 20a1efa commit 8b16202

File tree

7 files changed

+51
-143
lines changed

7 files changed

+51
-143
lines changed

synthme.py renamed to SpeechSynthesis.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
if __name__ == "__main__":
44
# message = input("Message: ")
5-
# message = "को"
6-
message = "मैं सार्थक हूँ"
5+
message = "मैं राज हूं"
76

87
# for i in message:
98
# print(i)
109

11-
12-
13-
tts.text_to_speech(message, debug=True, use_pronunciation_dict=True)
10+
tts.text_to_speech(message, debug=True, use_pronunciation_dict=True)

Utilities/convertphonemes.py

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# convertphones.py
21
# Takes list of words and finds appropriate phonemes
3-
# If phoneme not found, an educated guess is made
2+
# If phoneme not found, an (un)educated guess is made
43

54
from Utilities import phonemes, util
65
import ast, re
@@ -32,68 +31,9 @@ def phoneme_blocks_to_list(blocks):
3231

3332

3433
def phoneme_scan(word):
35-
# while re.search("[ट]", word): # Keep replacing letters with phonemes in brackets [] until there are no more letters
36-
# Special patterns
37-
# while re.search("[a-zA-Z.,;!?]", word):
34+
# Takes a word and returns a string of phonemes
3835
while re.search("[अ-ॐ.,;!?]", word):
3936

40-
# word = replace_with_phoneme(word, r'iew', (phonemes.CONS_Y, phonemes.VOWEL_OO,phonemes.CONS_W))
41-
42-
# word = replace_with_phoneme(word, r'oo', (phonemes.VOWEL_OO,))
43-
# word = replace_with_phoneme(word, r'ou', (phonemes.VOWEL_OO,))
44-
# word = replace_with_phoneme(word, r'ea', (phonemes.VOWEL_II,))
45-
# word = replace_with_phoneme(word, r'ee', (phonemes.VOWEL_II,))
46-
47-
# word = replace_with_phoneme(word, r'gg', (phonemes.CONS_J,))
48-
# word = replace_with_phoneme(word, r'dd', (phonemes.CONS_D,))
49-
# word = replace_with_phoneme(word, r'ph', (phonemes.CONS_F,))
50-
# word = replace_with_phoneme(word, r'll', (phonemes.CONS_L,))
51-
# word = replace_with_phoneme(word, r'ss', (phonemes.CONS_S,))
52-
# word = replace_with_phoneme(word, r'nn', (phonemes.CONS_N,))
53-
# word = replace_with_phoneme(word, r'ch', (phonemes.CONS_CH,))
54-
# word = replace_with_phoneme(word, r'sh', (phonemes.CONS_SH,))
55-
# word = replace_with_phoneme(word, r'th', (phonemes.CONS_TH,))
56-
# word = replace_with_phoneme(word, r'ck', (phonemes.CONS_K,))
57-
58-
# # Default letters
59-
# क
60-
# ख
61-
# ग
62-
# घ
63-
# ङ
64-
# च
65-
# छ
66-
# ज
67-
# झ
68-
# ञ
69-
# ट
70-
# ठ
71-
# ड
72-
# ढ
73-
# ण
74-
# त
75-
# थ
76-
# द
77-
# ध
78-
# न
79-
# ऩ
80-
# प
81-
# फ
82-
# ब
83-
# भ
84-
# म
85-
# य
86-
# र
87-
# ऱ
88-
# ल
89-
# ळ
90-
# ऴ
91-
# व
92-
# श
93-
# ष
94-
# स
95-
# ह
96-
9737
word = replace_with_phoneme(word, "अ", (phonemes.VOWEL_U,))
9838
word = replace_with_phoneme(word, "आ", (phonemes.VOWEL_A,))
9939
word = replace_with_phoneme(word, "ा", (phonemes.VOWEL_A,))
@@ -164,11 +104,6 @@ def phoneme_scan(word):
164104

165105
word = replace_with_phoneme(word, "ज़", (phonemes.CONS_Z,))
166106

167-
168-
# word = replace_with_phoneme(word, "q", (phonemes.CONS_K,))
169-
170-
# word = replace_with_phoneme(word, "w", (phonemes.CONS_W,))
171-
# word = replace_with_phoneme(word, "x", (phonemes.CONS_K, phonemes.CONS_S))
172107
word = replace_with_phoneme(word, ".", (phonemes.PUNC_PERIOD,))
173108
word = replace_with_phoneme(word, ",", (phonemes.PUNC_COMMA,))
174109
word = replace_with_phoneme(word, ";", (phonemes.PUNC_COMMA,))

Utilities/convertsounds.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# convertsounds.py
21
# Matches each phoneme from list with appropriate wav file
32

43
from Utilities import phonemes

Utilities/phonemes.py

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
1-
# phonemes.py
21
# List of all sounds used
32

4-
VOWEL_U = 0 # cup, luck
5-
VOWEL_A = 1 # arm, father
6-
VOWEL_AE = 2 # cat, black
7-
VOWEL_E = 3 # met, bed
8-
VOWEL_EE = 4 # away, cinema
9-
VOWEL_UU = 5 # turn, learn
10-
VOWEL_I = 6 # hit, sitting
11-
VOWEL_II = 7 # see, heat
12-
VOWEL_O = 8 # hot, rock
13-
VOWEL_CA = 9 # call, four
14-
VOWEL_PU = 10 # put, could
15-
VOWEL_OO = 11 # blue, food
16-
VOWEL_AI = 12 # five, eye
17-
VOWEL_AU = 13 # now, out
18-
VOWEL_EI = 14 # say, eight
19-
VOWEL_OH = 15 # go, home
20-
VOWEL_OI = 16 # boy, join
21-
VOWEL_ER = 17 # where, air
22-
VOWEL_IE = 18 # near, here
23-
VOWEL_UE = 19 # pure, tourist
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 # य
2423

25-
CONS_B = 20 # bad, lab
26-
CONS_D = 21 # did, lady ड ढ
27-
CONS_F = 22 # find, if
28-
CONS_G = 23 # give, flag ग घ
29-
CONS_H = 24 # how, hello
30-
CONS_Y = 25 # yes, yellow
31-
CONS_K = 26 # cat, black ख क
32-
CONS_L = 27 # leg, litte
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 # ल
3332

34-
CONS_M = 28 # man, lemon म
35-
# todo
36-
CONS_N = 29 # no, ten न ञ ण
37-
CONS_NG = 30 # sing, finger ं
38-
CONS_P = 31 # pet, map प भ
39-
CONS_R = 32 # red, try र
40-
CONS_S = 33 # sun, miss स
41-
CONS_SH = 34 # she, crash श ष
42-
CONS_T = 35 # tea, getting ट
43-
CONS_CH = 36 # check, church च
44-
CONS_TH = 37 # think, both थ ठ ध
45-
CONS_TH2 = 38 # this, mother द
46-
CONS_V = 39 # voice, five व
47-
CONS_W = 40 # wet, window
48-
CONS_Z = 41 # zoo, lazy ज़
49-
CONS_JJ = 42 # pleasure, vision छ झ
50-
CONS_J = 43 # just, large ज
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 # ज
5149

5250
PUNC_PERIOD = 44 # period (long pause) 0.5
5351
PUNC_COMMA = 44 # comma (short pause) 0.3

Utilities/tts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# tts.py
21
# Pulls all three pieces together: convertwords, convertphonemes, convertsounds
32

4-
DATABASE_NAME = "data/pronunciation.db"
53
OUTPUT_FILE = "output.wav"
64

75
from Utilities import convertphonemes, convertsounds, util

Utilities/util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
import csv, re
44

55
# Convert raw user input to a list of words
6-
# TODO: convert numerical values to words
76
def tokenize(data):
8-
# return re.findall(r"[\w]+|[.,!?;|]",data.lower())
97
word = []
108
word = data.split(" ")
119
word = re.split('; |, |\*|\n| ',data)
1210
return word
1311

1412

1513
def get_pronunciation(word):
16-
with open(PRONUNCIATION_CSV_PATH, 'rt') as f:
14+
with open(PRONUNCIATION_CSV_PATH, 'rt',encoding="utf8") as f:
1715
reader = csv.reader(f, delimiter=',')
1816
for row in reader:
1917
if word == row[0]:

data/pronunciation.csv

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,2 @@
1-
me, 28 7
2-
i, 12
3-
like, 27 12 26
4-
and, 2 29 21
5-
my, 28 12
6-
name, 29 14 28
7-
is, 6 41
8-
dad, 21 2 21
9-
am, 2 28
10-
the, 38 4
11-
used, 25 11 41 21
12-
own, 15 40 29
13-
voice, 39 16 33
14-
to, 35 11
15-
create, 26 32 7 14 35
16-
concatenative, 26 8 29 26 1 35 6 29 3 35 6 39
17-
speech, 33 31 7 36
18-
synthesis, 33 6 29 37 6 33 6 33
19-
demonstration, 21 3 28 8 29 33 35 32 14 34 6 29
1+
राज, 32 1 43 44
2+
सार्थक, 33 1 32 37 26 44

0 commit comments

Comments
 (0)