-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (29 loc) · 1.05 KB
/
main.py
File metadata and controls
41 lines (29 loc) · 1.05 KB
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
import speech_recognition as sr
import subprocess
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
FOLDER_AUDIO = "audios"
FOLDER_TEXT = "texts"
LANGUAGE = "pt_BR"
print "starting..."
if not os.path.isdir(FOLDER_AUDIO):
os.mkdir(FOLDER_AUDIO)
if not os.path.isdir(FOLDER_TEXT):
os.mkdir(FOLDER_TEXT)
paths = [os.path.join(FOLDER_AUDIO, nome) for nome in os.listdir(FOLDER_AUDIO)]
files = [arq for arq in paths if os.path.isfile(arq)]
wav_files = [arq for arq in files if arq.lower().endswith(".wav")]
for filename in wav_files:
r = sr.Recognizer()
with sr.AudioFile(filename) as source:
audio = r.record(source)
command = r.recognize_google(audio, language=LANGUAGE)
print "running file {}".format(filename)
filefinal = filename.split("audios\\")[1].split(".wav")[0]
filefinal = '{}\{}.txt'.format(FOLDER_TEXT, filefinal)
with open(filefinal, 'w') as arq:
arq.write(unicode(command))
print "create a new file {}".format(filefinal)
print "finish"