-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
106 lines (78 loc) · 2.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
97
98
99
100
101
102
103
104
105
106
import os
import pandas as pd
from pydub import AudioSegment
from gtts import gTTS
# pip install pyaudio
# pip install pydub
# pip install pandas
# pip install gTTS
def textToSpeech(text, filename):
mytext = str(text)
language = 'hi'
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save(filename)
# This function returns pydubs audio segment
def mergeAudios(audios):
combined = AudioSegment.empty()
for audio in audios:
combined += AudioSegment.from_mp3(audio)
return combined
def generateSkeleton():
audio = AudioSegment.from_mp3('railway.mp3')
# 1 - Generate kripya dheyan dijiye
start = 88000
finish = 90200
audioProcessed = audio[start:finish]
audioProcessed.export("1_hindi.mp3", format="mp3")
# 2 is from-city
# 3 - Generate se chalkar
start = 91000
finish = 92200
audioProcessed = audio[start:finish]
audioProcessed.export("3_hindi.mp3", format="mp3")
# 4 is via-city
# 5 - Generate ke raaste
start = 94000
finish = 95000
audioProcessed = audio[start:finish]
audioProcessed.export("5_hindi.mp3", format="mp3")
# 6 is to-city
# 7 - Generate ko jaane wali gaadi sakhya
start = 96000
finish = 98900
audioProcessed = audio[start:finish]
audioProcessed.export("7_hindi.mp3", format="mp3")
# 8 is train no and name
# 9 - Generate kuch hi samay mei platform sankhya
start = 105500
finish = 108200
audioProcessed = audio[start:finish]
audioProcessed.export("9_hindi.mp3", format="mp3")
# 10 is platform number
# 11 - Generate par aa rahi hai
start = 109000
finish = 112250
audioProcessed = audio[start:finish]
audioProcessed.export("11_hindi.mp3", format="mp3")
def generateAnnouncement(filename):
df = pd.read_excel(filename)
print(df)
for index, item in df.iterrows():
# 2 - Generate from-city
textToSpeech(item['from'], '2_hindi.mp3')
# 4 - Generate via-city
textToSpeech(item['via'], '4_hindi.mp3')
# 6 - Generate to-city
textToSpeech(item['to'], '6_hindi.mp3')
# 8 - Generate train no and name
textToSpeech(item['train_no'] + " " + item['train_name'], '8_hindi.mp3')
# 10 - Generate platform number
textToSpeech(item['platform'], '10_hindi.mp3')
audios = [f"{i}_hindi.mp3" for i in range(1,12)]
announcement = mergeAudios(audios)
announcement.export(f"announcement_{item['train_no']}_{index+1}.mp3", format="mp3")
if __name__ == "__main__":
print("Generating Skeleton...")
generateSkeleton()
print("Now Generating Announcement...")
generateAnnouncement("announce_hindi.xlsx")