Skip to content

Commit

Permalink
Added benchmarks in a different folder. Added a yes or no benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
etsardou committed May 27, 2015
1 parent 3a0221b commit 5d5df8d
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 4 deletions.
126 changes: 126 additions & 0 deletions rapp_speech_detection_sphinx4/src/benchmarks/yes_no_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#MIT License (MIT)

#Copyright (c) <2014> <Rapp Project EU>

#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:

#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.

#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.

# Authors: Athanassios Kintsakis, Manos Tsardoulias
# contact: [email protected], [email protected]

import rospy
import sys
from os import listdir
from os.path import isfile, join

from rapp_platform_ros_communications.srv import (
SpeechRecognitionSphinx4Srv,
SpeechRecognitionSphinx4SrvResponse,
SpeechRecognitionSphinx4SrvRequest,
SpeechRecognitionSphinx4ConfigureSrv,
SpeechRecognitionSphinx4ConfigureSrvResponse,
SpeechRecognitionSphinx4ConfigureSrvRequest,
SpeechRecognitionSphinx4TotalSrv,
SpeechRecognitionSphinx4TotalSrvResponse,
SpeechRecognitionSphinx4TotalSrvRequest
)

class SpeechRecognitionTester:

def setup_two_words_voc(self):
spreq = SpeechRecognitionSphinx4ConfigureSrvRequest()
spreq.language = 'gr'
spreq.words = []
spreq.words.append(u'όχι')
spreq.words.append(u'ναι')
spreq.sentences = []
spreq.sentences.append(u'όχι')
spreq.sentences.append(u'ναι')
spreq.grammar = []
spreq.grammar.append(u'(όχι)')
spreq.grammar.append(u'(ναι)')
return spreq

def __init__(self):
self.conf_sp_ser = rospy.ServiceProxy(\
'/ric/speech_detection_sphinx4_batch',\
SpeechRecognitionSphinx4TotalSrv)

spreq = ""
spreq = self.setup_two_words_voc()
spreq.grammar = []
spee_req = SpeechRecognitionSphinx4TotalSrvRequest()

if len(sys.argv) != 2:
print "Invalid number of arguments"
return

folder = sys.argv[1]

files = [ f for f in listdir(folder) if isfile(join(folder, f)) ]

success = 0
total = 0

for f in files:
response = ""
if not (("nai_" in f) or ("oxi_" in f)):
continue;
if "nai_" in f:
response = u'ναι'
else:
response = u'όχι'

spee_req.language = spreq.language
spee_req.words = spreq.words
spee_req.grammar = spreq.grammar
spee_req.user = 'etsardou'
spee_req.sentences = spreq.sentences
spee_req.path = folder + f
spee_req.audio_source = 'headset' # The samples are already denoised
res = self.conf_sp_ser(spee_req)
print spee_req.path + " : ",
for word in res.words:
print word,

ok = False
while not ok:
ok = True
for i in range(0, len(res.words) - 1):
if res.words[i] == res.words[i + 1]:
del res.words[i + 1]
ok = False
break;

total += 1
if len(res.words) == 1:
if res.words[0] == response.encode('utf-8'):
success += 1

print str(success*1.0/total*100.0) + "%"


# Main function
if __name__ == "__main__":
rospy.init_node('SpeechRecognitionTester')
SpeechRecognitionTesterNode = SpeechRecognitionTester()
#rospy.spin()

10 changes: 6 additions & 4 deletions rapp_speech_detection_sphinx4/src/sphinx4_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ def performSpeechRecognition(self, audio_file, audio_source, user):
directory = "/tmp/rapp_platform_files/rapp_speech_recognition_sphinx4/" + user
if not os.path.isdir(directory):
os.makedirs(directory)
clean_file = audio_to_be_erased[-1].split("/")[-1]
clean_file_or = audio_to_be_erased[0].split("/")[-1]

os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/" + clean_file)
os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/original_" + clean_file)
if len(audio_to_be_erased) != 0:
clean_file = audio_to_be_erased[-1].split("/")[-1]
clean_file_or = audio_to_be_erased[0].split("/")[-1]

os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/" + clean_file)
os.system("cp " + audio_to_be_erased[-1] + " " + directory + "/original_" + clean_file)

for f in audio_to_be_erased:
command = "rm " + f
Expand Down

0 comments on commit 5d5df8d

Please sign in to comment.