-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
52 lines (43 loc) · 1.11 KB
/
util.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
from time import time
from pydub import AudioSegment
import os
DEBUG = True
LANGUAGES = [
('en-US', 'English (US)'),
('en-UK', 'English (UK)'),
('ru-RU', 'Русский (RU)')
]
LANGUAGE_EN = 'en-US'
LANGUAGE_RU = 'ru-RU'
SAMPLE_RATE = 8000
READ_FRAMES = 2000
RECOGNITION_TIMEOUT = 120
MAX_AUDIO_SIZE_MB = 32
APP_NAME = 'hackatom2021'
UPLOAD_FOLDER = 'audio'
ALLOWED_AUDIO_EXTENSIONS = {'wav', 'mp3'}
DOT_DELTA_TIME = 0.7
PARAGRAPH_DELTA_TIME = 1.1
PARAGRAPH_EVERY_N_SENTENCES = 3
DENSITY = {
'ru': {
'dot': 0.05,
'comma': 0.08,
'paragraph': 0.02
},
'en': {
'dot': 0.05,
'comma': 0.04,
'paragraph': 0.025
}
}
def time_left(from_time):
if DEBUG:
print(int(time() - from_time), 'seconds left')
def convert_to_wav(file_path):
sound = AudioSegment.from_file(file_path)
dst = '.'.join(file_path.split('/')[-1].split('.')[:-1]) + '.wav'
print(f'Converting {file_path} to {dst}...')
sound.export(dst, format='wav', parameters=f'-ac 1 -ar {SAMPLE_RATE}'.split())
print(f'File {file_path} was converted to {dst}')
return dst