-
Notifications
You must be signed in to change notification settings - Fork 84
/
speech_stats.py
executable file
·168 lines (126 loc) · 3.53 KB
/
speech_stats.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2013, 2014, 2016, 2017 Guenter Bartsch
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# print stats about audio, dictionary and models
#
import sys
import re
import os
import StringIO
import ConfigParser
import wave
import codecs
from speech_transcripts import Transcripts
from speech_lexicon import Lexicon
from nltools.phonetics import ipa2xsampa, xsampa2ipa
from nltools.tokenizer import tokenize
from nltools import misc
LANG = 'de'
#
# init terminal
#
misc.init_app ('speech_stats')
#
# config
#
config = misc.load_config('.speechrc')
wav16_dir = config.get("speech", "wav16_dir_%s" % LANG)
#
# load transcripts
#
print "loading transcripts..."
transcripts = Transcripts(lang=LANG)
print "loading transcripts...done."
#
# load lexicon
#
print "loading lexicon..."
lex = Lexicon(lang=LANG)
print "loading lexicon...done."
#
# lexicon stats
#
print
print "%d lexicon entries." % len(lex)
#
# audio stats
#
def format_duration(duration):
m, s = divmod(duration, 60)
h, m = divmod(m, 60)
return "%3d:%02d:%02d" % (h, m, s)
total_duration = 0.0
duration_per_spk = {}
for cfn in transcripts:
quality = transcripts[cfn]['quality']
if quality < 2:
continue
wavfn = '%s/%s.wav' % (wav16_dir, cfn)
wavef = wave.open(wavfn, 'rb')
num_frames = wavef.getnframes()
frame_rate = wavef.getframerate()
duration = float(num_frames) / float(frame_rate)
# print '%s has %d frames at %d samples/s -> %fs' % (wavfn, num_frames, frame_rate, duration)
total_duration += duration
spk = transcripts[cfn]['spk']
if not spk in duration_per_spk:
duration_per_spk[spk] = 0.0
duration_per_spk[spk] += duration
wavef.close()
print
print "total duration of all good submissions: %s" % format_duration(total_duration)
print
print "good submissions per user:"
print
for spk in sorted(duration_per_spk):
print "%-42s %s" % (spk, format_duration(duration_per_spk[spk]))
print
#
# sphinx model stats
#
print
with codecs.open('data/dst/speech/%s/cmusphinx_cont/logs/sphinxtrain_run.log' % LANG, 'r', 'utf8') as logf:
for line in logf:
if 'WORD ERROR RATE' in line:
print "cmusphinx cont model: %s" % line.strip()
print
print
with codecs.open('data/dst/speech/%s/cmusphinx_ptm/logs/sphinxtrain_run.log' % LANG, 'r', 'utf8') as logf:
for line in logf:
if 'WORD ERROR RATE' in line:
print "cmusphinx ptm model: %s" % line.strip()
print
#
# kaldi model stats
#
print "kaldi models: "
with codecs.open('data/dst/speech/%s/kaldi/RESULTS.txt' % LANG, 'r', 'utf8') as logf:
for line in logf:
print line.strip()
print
#
# sequitur model stats
#
print "sequitur g2p model:"
with codecs.open('data/dst/speech/%s/sequitur/model-6.test' % LANG, 'r', 'utf8', 'ignore') as logf:
for line in logf:
if not line.startswith(' '):
continue
print line.rstrip()
print