-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_a_warning.py
executable file
·43 lines (36 loc) · 1.04 KB
/
make_a_warning.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
#! /usr/bin/env python
import os
import sys
from gtts import gTTS
# different microphones can return different level of signal
rms_multiplyer = 1
mp3_name = 'warning.mp3'
language = 'ru'
def get_message(rms):
rms = int(rms)
if rms < 800:
return 'Потише!'
elif rms < 1100:
return 'Тише!!'
elif rms < 1500:
return 'Тише! Слишком громко!'
elif rms < 2000:
return 'Слишком громко! на 30 децибел потише!'
else: # Very LOUD
return 'Да Вы совсем мох у ели!'
def main():
try:
rms = sys.argv[1] * rms_multiplyer
except IndexError:
print('no rms')
rms = "4000"
mytext = get_message(rms)
tts = gTTS(text=mytext, lang=language, slow=False)
tts.save(mp3_name)
platform = sys.platform
if platform == "linux" or platform == "linux2":
os.system("mpg123 " + mp3_name)
elif platform == "darwin":
os.system("afplay " + mp3_name)
if __name__ == "__main__":
main()