Commit 7d325c524c453e1ce43a971f2ab44a30a5e330b9
1 parent
2bd908fc
Exists in
master
and in
2 other branches
Indice de confiança do Julius implementado.
Showing
2 changed files
with
62 additions
and
4 deletions
Show diff stats
recognize/src/include/recognize.h
... | ... | @@ -43,6 +43,9 @@ private: |
43 | 43 | |
44 | 44 | char* pathVideo; |
45 | 45 | bool finished; |
46 | + | |
47 | + float sizeScores; | |
48 | + float avgScores; | |
46 | 49 | |
47 | 50 | /** inputType: 1 = RawFile, 2 = Mic */ |
48 | 51 | int inputType, frequency, sizeBlocs; |
... | ... | @@ -57,6 +60,7 @@ private: |
57 | 60 | |
58 | 61 | void executeJuliusEngine(); |
59 | 62 | std::list<char*>* filterOutputJulius(); |
63 | + void confidenceJulius(); | |
60 | 64 | void notifyListeners(char* text); |
61 | 65 | void cleanFiles(); |
62 | 66 | ... | ... |
recognize/src/recognize.cpp
1 | 1 | #include <fstream> |
2 | 2 | #include <stdio.h> |
3 | -#include <string.h> | |
4 | 3 | #include <sstream> |
5 | 4 | #include <stdlib.h> |
5 | +#include <algorithm> | |
6 | +#include <vector> | |
7 | +#include <iterator> | |
8 | + | |
9 | +#include <iostream> | |
10 | +#include <string> | |
6 | 11 | |
7 | 12 | #include <lavidlib/io/FileIO.h> |
8 | 13 | |
... | ... | @@ -12,16 +17,21 @@ |
12 | 17 | #define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */ |
13 | 18 | #define BLOCS_PATTERN 10 |
14 | 19 | #define SIZE_BUFFER 256 |
20 | +#define CONFIDENCE_RATE 0.80 | |
15 | 21 | |
16 | 22 | |
17 | 23 | #define PATH_AUDIO_ORIGIN "gtaaas_user/gtaaas/recognize/src/audio/origin/audio_origin.wav" |
18 | 24 | #define PATH_AUDIO_PARTS "gtaaas_user/gtaaas/recognize/src/audio/parts/" |
19 | -#define FILENAME_RECOGNIZED_OUT "gtaaas_user/gtaaas/recognize/src/audio/recognized.out" | |
20 | 25 | #define FILENAME_AUDIOPART "audio00" |
21 | 26 | #define FILENAME_AUDIOLIST "gtaaas_user/gtaaas/recognize/src/audio/audiolist" |
22 | 27 | #define FILENAME_FILTEROUT "gtaaas_user/gtaaas/recognize/src/audio/filter" |
23 | -#define PROGRAM "ffmpeg" // ffmpeg | |
28 | +#define FILENAME_CONFIDENCEOUT "gtaaas_user/gtaaas/recognize/src/audio/confidence" | |
29 | +#define FILENAME_RECOGNIZED_OUT "gtaaas_user/gtaaas/recognize/src/audio/recognized.out" | |
30 | + | |
31 | +#define FIND_CONFIDENCE "\"cmscore1:\"" | |
24 | 32 | #define FIND_SENTENCE "\"pass1_best:\"" |
33 | + | |
34 | +#define PROGRAM "ffmpeg" // ffmpeg | |
25 | 35 | #define PTS_PATTERN 1000 |
26 | 36 | |
27 | 37 | using namespace std; |
... | ... | @@ -75,6 +85,8 @@ void Recognize::initialize() { |
75 | 85 | |
76 | 86 | executeJuliusEngine(); |
77 | 87 | |
88 | + confidenceJulius(); | |
89 | + | |
78 | 90 | std::list<char*> *list_sentences; |
79 | 91 | list_sentences = filterOutputJulius(); |
80 | 92 | |
... | ... | @@ -220,7 +232,7 @@ void Recognize::executeJuliusEngine() { |
220 | 232 | sprintf(cfreq, "%i", frequency); |
221 | 233 | command.append(" -smpFreq "). |
222 | 234 | append(cfreq). |
223 | - append(" -1pass -nolog -quiet >> "). | |
235 | + append(" -nolog >> "). | |
224 | 236 | append(FILENAME_RECOGNIZED_OUT); |
225 | 237 | |
226 | 238 | printf("\n\nCommand for executeJuliusEngine: %s\n", command.c_str()); |
... | ... | @@ -228,6 +240,47 @@ void Recognize::executeJuliusEngine() { |
228 | 240 | |
229 | 241 | } |
230 | 242 | |
243 | +void Recognize::confidenceJulius() { | |
244 | + | |
245 | + string command = "cat "; | |
246 | + command.append(FILENAME_RECOGNIZED_OUT).append(" | grep "). | |
247 | + append(FIND_CONFIDENCE).append(" >> ").append(FILENAME_CONFIDENCEOUT); | |
248 | + | |
249 | + system(command.c_str()); | |
250 | + printf("\n\n---> command: %s\n\n", command.c_str()); | |
251 | + | |
252 | + ifstream in(FILENAME_CONFIDENCEOUT); | |
253 | + | |
254 | + if (!in) { | |
255 | + perror("Error: "); | |
256 | + } else { | |
257 | + string line; | |
258 | + float tmp; | |
259 | + avgScores = 0; | |
260 | + do { | |
261 | + getline(in, line); | |
262 | + std::istringstream buf(line); | |
263 | + if (line.length() > 0) { | |
264 | + istream_iterator<std::string> beg(buf), end; | |
265 | + vector<string> tokens(beg, end); | |
266 | + int i; | |
267 | + for(i=2; i < tokens.size()-1; i++){ | |
268 | + istringstream(tokens[i]) >> tmp; | |
269 | + avgScores += tmp; | |
270 | + sizeScores++; | |
271 | + } | |
272 | + } | |
273 | + } while (!in.eof()); | |
274 | + in.close(); | |
275 | + avgScores /= sizeScores; | |
276 | + } | |
277 | + | |
278 | + | |
279 | + if (avgScores < CONFIDENCE_RATE) | |
280 | + finished = true; | |
281 | + throw RecognizeException("Desculpe, não podemos concluir pois o vídeo tem baixa qualidade. Tente novamente com outro vídeo."); | |
282 | +} | |
283 | + | |
231 | 284 | |
232 | 285 | std::list<char*>* Recognize::filterOutputJulius() { |
233 | 286 | |
... | ... | @@ -300,6 +353,7 @@ void Recognize::cleanFiles() { |
300 | 353 | command.append(PATH_AUDIO_ORIGIN).append(" "). |
301 | 354 | append(FILENAME_AUDIOLIST).append(" "). |
302 | 355 | append(FILENAME_FILTEROUT).append(" "). |
356 | + append(FILENAME_CONFIDENCEOUT).append(" "). | |
303 | 357 | append(PATH_AUDIO_PARTS).append("* "). |
304 | 358 | append(FILENAME_RECOGNIZED_OUT); |
305 | 359 | system(command.c_str()); | ... | ... |