RecognizerLoggerpublic class RecognizerLogger extends Object This class logs the inputs and results of a recognition session to
the files listed below, which reside in
/data/data/com.android.voicedialer/app_logdir.
The files have the date encoded in the name so that they will sort in
time order. The newest RecognizerLogger.MAX_FILES are kept,
and the rest deleted to limit space used in the file system.
- datename.wav - what the microphone heard.
- datename.log - contact list, results, errors, etc.
|
Fields Summary |
---|
private static final String | TAG | private static final String | LOGDIR | private static final String | ENABLED | private static final int | MAX_FILES | private final String | mDatedPath | private final BufferedWriter | mWriter |
Constructors Summary |
---|
public RecognizerLogger(android.content.Context context)Constructor
if (Config.LOGD) Log.d(TAG, "RecognizerLogger");
// generate new root filename
File dir = context.getDir(LOGDIR, 0);
mDatedPath = dir.toString() + File.separator + "log_" +
DateFormat.format("yyyy_MM_dd_kk_mm_ss",
System.currentTimeMillis());
// delete oldest files
deleteOldest(".wav");
deleteOldest(".log");
// generate new text output log file
mWriter = new BufferedWriter(new FileWriter(mDatedPath + ".log"), 8192);
mWriter.write(Build.FINGERPRINT);
mWriter.newLine();
|
Methods Summary |
---|
public void | close()Close the text log file.
mWriter.close();
| private void | deleteOldest(java.lang.String suffix)Delete oldest files with a given suffix, if more than MAX_FILES.
FileFilter ff = new FileFilter() {
public boolean accept(File f) {
String name = f.getName();
return name.startsWith("log_") && name.endsWith(suffix);
}
};
File[] files = (new File(mDatedPath)).getParentFile().listFiles(ff);
Arrays.sort(files);
for (int i = 0; i < files.length - MAX_FILES; i++) {
files[i].delete();
}
| public static void | disable(android.content.Context context)Disable logging.
try {
File dir = context.getDir(LOGDIR, 0);
File enabled = new File(dir, ENABLED);
enabled.delete();
}
catch (SecurityException e) {
Log.e(TAG, "disableLogging " + e);
}
| public static void | enable(android.content.Context context)Enable logging.
try {
File dir = context.getDir(LOGDIR, 0);
File enabled = new File(dir, ENABLED);
enabled.createNewFile();
}
catch (IOException e) {
Log.e(TAG, "enableLogging " + e);
}
| public static boolean | isEnabled(android.content.Context context)Determine if logging is enabled. If the
File dir = context.getDir(LOGDIR, 0);
File enabled = new File(dir, ENABLED);
return enabled.exists();
| public void | logContacts(java.util.List contacts)Write the list of contacts into the text log file.
logLine("Contacts *****************");
for (VoiceContact vc : contacts) logLine(vc.toString());
try {
mWriter.flush();
}
catch (IOException e) {
Log.e(TAG, "logContacts exception: " + e);
}
| public java.io.InputStream | logInputStream(java.io.InputStream inputStream, int sampleRate)InputStream wrapper which will log the contents to a WAV file.
final ByteArrayOutputStream baos = new ByteArrayOutputStream(sampleRate * 2 * 20);
return new InputStream() {
public int available() throws IOException {
return inputStream.available();
}
public int read(byte[] b, int offset, int length) throws IOException {
int rtn = inputStream.read(b, offset, length);
if (rtn > 0) baos.write(b, offset, rtn);
return rtn;
}
public int read(byte[] b) throws IOException {
int rtn = inputStream.read(b);
if (rtn > 0) baos.write(b, 0, rtn);
return rtn;
}
public int read() throws IOException {
int rtn = inputStream.read();
if (rtn > 0) baos.write(rtn);
return rtn;
}
public long skip(long n) throws IOException {
throw new UnsupportedOperationException();
}
public void close() throws IOException {
try {
OutputStream out = new FileOutputStream(mDatedPath + ".wav");
try {
byte[] pcm = baos.toByteArray();
WaveHeader hdr = new WaveHeader(WaveHeader.FORMAT_PCM,
(short)1, sampleRate, (short)16, pcm.length);
hdr.write(out);
out.write(pcm);
}
finally {
out.close();
}
}
finally {
inputStream.close();
baos.close();
}
}
};
| public void | logIntents(java.util.ArrayList intents)Write a list of Intents into the text log file.
logLine("Intents *********************");
StringBuffer sb = new StringBuffer();
for (Intent intent : intents) {
logLine(intent.toString() + " " + RecognizerEngine.SENTENCE_EXTRA + "=" +
intent.getStringExtra(RecognizerEngine.SENTENCE_EXTRA));
}
try {
mWriter.flush();
}
catch (IOException e) {
Log.e(TAG, "logIntents exception: " + e);
}
| public void | logLine(java.lang.String msg)Write a line into the text log file.
try {
mWriter.write(msg);
mWriter.newLine();
}
catch (IOException e) {
Log.e(TAG, "logLine exception: " + e);
}
| public void | logNbestHeader()Write a header for the NBest lines into the text log file.
logLine("Nbest *****************");
|
|