Skip to content

Commit 5d5df8d

Browse files
committed
Added benchmarks in a different folder. Added a yes or no benchmark
1 parent 3a0221b commit 5d5df8d

File tree

4 files changed

+132
-4
lines changed

4 files changed

+132
-4
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
#MIT License (MIT)
5+
6+
#Copyright (c) <2014> <Rapp Project EU>
7+
8+
#Permission is hereby granted, free of charge, to any person obtaining a copy
9+
#of this software and associated documentation files (the "Software"), to deal
10+
#in the Software without restriction, including without limitation the rights
11+
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
#copies of the Software, and to permit persons to whom the Software is
13+
#furnished to do so, subject to the following conditions:
14+
15+
#The above copyright notice and this permission notice shall be included in
16+
#all copies or substantial portions of the Software.
17+
18+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
#THE SOFTWARE.
25+
26+
# Authors: Athanassios Kintsakis, Manos Tsardoulias
27+
28+
29+
import rospy
30+
import sys
31+
from os import listdir
32+
from os.path import isfile, join
33+
34+
from rapp_platform_ros_communications.srv import (
35+
SpeechRecognitionSphinx4Srv,
36+
SpeechRecognitionSphinx4SrvResponse,
37+
SpeechRecognitionSphinx4SrvRequest,
38+
SpeechRecognitionSphinx4ConfigureSrv,
39+
SpeechRecognitionSphinx4ConfigureSrvResponse,
40+
SpeechRecognitionSphinx4ConfigureSrvRequest,
41+
SpeechRecognitionSphinx4TotalSrv,
42+
SpeechRecognitionSphinx4TotalSrvResponse,
43+
SpeechRecognitionSphinx4TotalSrvRequest
44+
)
45+
46+
class SpeechRecognitionTester:
47+
48+
def setup_two_words_voc(self):
49+
spreq = SpeechRecognitionSphinx4ConfigureSrvRequest()
50+
spreq.language = 'gr'
51+
spreq.words = []
52+
spreq.words.append(u'όχι')
53+
spreq.words.append(u'ναι')
54+
spreq.sentences = []
55+
spreq.sentences.append(u'όχι')
56+
spreq.sentences.append(u'ναι')
57+
spreq.grammar = []
58+
spreq.grammar.append(u'(όχι)')
59+
spreq.grammar.append(u'(ναι)')
60+
return spreq
61+
62+
def __init__(self):
63+
self.conf_sp_ser = rospy.ServiceProxy(\
64+
'/ric/speech_detection_sphinx4_batch',\
65+
SpeechRecognitionSphinx4TotalSrv)
66+
67+
spreq = ""
68+
spreq = self.setup_two_words_voc()
69+
spreq.grammar = []
70+
spee_req = SpeechRecognitionSphinx4TotalSrvRequest()
71+
72+
if len(sys.argv) != 2:
73+
print "Invalid number of arguments"
74+
return
75+
76+
folder = sys.argv[1]
77+
78+
files = [ f for f in listdir(folder) if isfile(join(folder, f)) ]
79+
80+
success = 0
81+
total = 0
82+
83+
for f in files:
84+
response = ""
85+
if not (("nai_" in f) or ("oxi_" in f)):
86+
continue;
87+
if "nai_" in f:
88+
response = u'ναι'
89+
else:
90+
response = u'όχι'
91+
92+
spee_req.language = spreq.language
93+
spee_req.words = spreq.words
94+
spee_req.grammar = spreq.grammar
95+
spee_req.user = 'etsardou'
96+
spee_req.sentences = spreq.sentences
97+
spee_req.path = folder + f
98+
spee_req.audio_source = 'headset' # The samples are already denoised
99+
res = self.conf_sp_ser(spee_req)
100+
print spee_req.path + " : ",
101+
for word in res.words:
102+
print word,
103+
104+
ok = False
105+
while not ok:
106+
ok = True
107+
for i in range(0, len(res.words) - 1):
108+
if res.words[i] == res.words[i + 1]:
109+
del res.words[i + 1]
110+
ok = False
111+
break;
112+
113+
total += 1
114+
if len(res.words) == 1:
115+
if res.words[0] == response.encode('utf-8'):
116+
success += 1
117+
118+
print str(success*1.0/total*100.0) + "%"
119+
120+
121+
# Main function
122+
if __name__ == "__main__":
123+
rospy.init_node('SpeechRecognitionTester')
124+
SpeechRecognitionTesterNode = SpeechRecognitionTester()
125+
#rospy.spin()
126+

rapp_speech_detection_sphinx4/src/sphinx4_wrapper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,13 @@ def performSpeechRecognition(self, audio_file, audio_source, user):
192192
directory = "/tmp/rapp_platform_files/rapp_speech_recognition_sphinx4/" + user
193193
if not os.path.isdir(directory):
194194
os.makedirs(directory)
195-
clean_file = audio_to_be_erased[-1].split("/")[-1]
196-
clean_file_or = audio_to_be_erased[0].split("/")[-1]
197195

198-
os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/" + clean_file)
199-
os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/original_" + clean_file)
196+
if len(audio_to_be_erased) != 0:
197+
clean_file = audio_to_be_erased[-1].split("/")[-1]
198+
clean_file_or = audio_to_be_erased[0].split("/")[-1]
199+
200+
os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/" + clean_file)
201+
os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/original_" + clean_file)
200202

201203
for f in audio_to_be_erased:
202204
command = "rm " + f

0 commit comments

Comments
 (0)