-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcription.py
45 lines (38 loc) · 1.39 KB
/
transcription.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
# Standard Packages
import os
# PyPi packages
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
modeldir = "./data/model"
passiveconfig = Decoder.default_config()
passiveconfig.set_string('-hmm', os.path.join(modeldir, 'en-us'))
passiveconfig.set_string('-lm', os.path.join(modeldir, 'en-us/en-us.lm.bin'))
passiveconfig.set_string('-logfn', "/dev/null")
passiveconfig.set_string('-dict', os.path.join(modeldir, 'homebrain.dict'))
passivedecoder = Decoder(passiveconfig)
activeconfig = Decoder.default_config()
activeconfig.set_string('-hmm', os.path.join(modeldir, 'en-us'))
activeconfig.set_string('-lm', os.path.join(modeldir, 'en-us/en-us.lm.bin'))
passiveconfig.set_string('-logfn', "/dev/null")
activeconfig.set_string('-dict', os.path.join(modeldir, 'commandterms.dict'))
activedecoder = Decoder(activeconfig)
def passive_transcribe(filename):
return transcribe(filename, passivedecoder)
def active_transcribe(filename):
return transcribe(filename, activedecoder)
def transcribe(filename, decoder):
fp = open(filename, 'rb')
data = fp.read()
decoder.start_utt()
decoder.process_raw(data, False, True)
decoder.end_utt()
fp.close()
result = decoder.hyp()
if result:
print(result)
print(result.best_score)
print(result.prob)
print('Transcribed: '+result.hypstr)
return result
else:
return None