-
Notifications
You must be signed in to change notification settings - Fork 8
/
transcriber.py
39 lines (30 loc) · 1.11 KB
/
transcriber.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
import glob
import speech_recognition as sr
from os import path, rename
def transcribe():
r = sr.Recognizer()
# get a list of audio files from the juice/wavs directory
wav_files = glob.glob('./wavs/*.wav')
metadata = []
# for each wav file
for fpath in wav_files:
with sr.AudioFile(fpath) as source:
print()
audio = r.record(source) # read the entire audio file
transcription = ''
try:
transcription = r.recognize_google(audio)
print(fpath + "|" + transcription)
metadata.append(fpath + "|" + transcription)
except:
print('Skipping ' + fpath)
metadata.append(fpath + "|" + "<ERROR>")
new_fpath = './ignore/' + path.basename(fpath)
# now move the file to the skipped directory
rename(fpath, new_fpath)
continue
metadata_txt = '\n'.join(metadata)
with open("metadata.csv", "w") as text_file:
text_file.write(metadata_txt)
if __name__ == "__main__":
transcribe()