forked from Open-Speech-EkStep/speech-recognition-open-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
35 lines (25 loc) · 856 Bytes
/
utilities.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
import requests
import wave
import os
import time
def download_from_url_to_file(file_name, url):
response = requests.get(url, allow_redirects=True)
response.raise_for_status()
with open(file_name, 'wb') as f:
f.write(response.content)
return os.path.join(os.getcwd(), file_name)
def create_wav_file_using_bytes(file_name, audio):
with wave.open(file_name, 'wb') as file:
file.setnchannels(1)
file.setsampwidth(2)
file.setframerate(16000.0)
file.writeframes(audio)
return os.path.join(os.getcwd(), file_name)
def write_to_file(file_name, audio):
with open(file_name, 'wb') as f:
f.write(audio)
return os.path.join(os.getcwd(), file_name)
def convert_audio_to_required_format(file_name):
pass
def get_current_time_in_millis():
return round(time.time() * 1000)