Commit f2ab2fc8 authored by Elodie Gauthier's avatar Elodie Gauthier

Fix minor issues before delivery to partners.

Precise message log in RecordElicitation.java.
Add "_elicit" to the recording filename of an elicitation.

We still cannot do a respeaking/translation of an elicitation.
parent bc5ad9e4
......@@ -1147,7 +1147,7 @@ public class Recording extends FileModel {
/**
* Name mutator.
*/
private void setName(String name) {
public void setName(String name) {
this.name = name;
}
......
......@@ -148,7 +148,13 @@ public class RecordingLig extends Recording {
throws IOException {
File wavFile = new File(getNoSyncRecordingsPath(), wavUUIDExt);
Log.i(TAG, "importwav: " + wavFile.length());
File destFile = new File(getIndividualRecordingPath(), this.name + ext);
Log.i(TAG, "Elicitation mode? " + isElicit());
File destFile;
if (isElicit()) {
destFile = new File(getIndividualRecordingPath(), this.respeakingId + ext);
} else {
destFile = new File(getIndividualRecordingPath(), this.name + ext);
}
FileUtils.moveFile(wavFile, destFile);
// FileUtils.moveFile(wavFile, this.getFile(idExt));
Log.i(TAG, "src file " + wavFile.getAbsolutePath() + " moves to " + destFile.getAbsolutePath());
......@@ -185,14 +191,12 @@ public class RecordingLig extends Recording {
// if the recording is original
if (isOriginal()) {
if (isOriginal() || isElicit()) {
// Import the sample wave file into the new recording directory
File wavFile = new File(getNoSyncRecordingsPath(), recordingUUID + SAMPLE_SUFFIX);
FileIO.delete(wavFile);
Log.d("file deleted", wavFile.getName());
}else {
} else {
// Try and import the mapping file
importMapping(recordingUUID, getId());
......@@ -204,8 +208,12 @@ public class RecordingLig extends Recording {
// Write the json metadata.
File metadataFile = new File(getIndividualRecordingPath(),
this.name + METADATA_SUFFIX);
File metadataFile;
if (isElicit()) {
metadataFile = new File(getIndividualRecordingPath(), this.respeakingId + METADATA_SUFFIX);
} else {
metadataFile = new File(getIndividualRecordingPath(), this.name + METADATA_SUFFIX);
}
FileIO.writeJSONObject(metadataFile,encodedRecording);
Log.i(TAG, "Saved metadata file to " + metadataFile.getAbsolutePath());
}
......@@ -266,9 +274,30 @@ public class RecordingLig extends Recording {
public File getFile() {
String extension = (this.isMovie())? ".mp4" : ".wav";
return new File(getIndividualRecordingPath(), this.name + extension);
// return getFile(id + extension);
// return getFile(id + extension);
}
public File getElicitFile() {
String extension = (this.isMovie())? ".mp4" : ".wav";
if (isElicit()) {
return new File(getIndividualRecordingPath(), this.getRespeakingId() + extension);
} else {
return new File(getIndividualRecordingPath(), this.name + extension);
// return getFile(id + extension);
}
}
/**
* Returns true if the Recording is an elicitation;
*
* @return True if the recording is an elicitation.
*/
public boolean isElicit() {
return this.name.contains("elicit") && !this.name.contains("_rspk") || !this.name.contains("_trsl");
}
public File getRecordingsPath() {
File path = new File(
FileIO.getOwnerPath(), RECORDINGS);
......@@ -283,14 +312,21 @@ public class RecordingLig extends Recording {
*/
public File getIndividualRecordingPath() {
File path;
String[] dir = this.getRespeakingId().split("_");
if (this.name.contains("rspk") || this.name.contains("trsl")) {
String[] dir = this.getRespeakingId().split("_");
Log.d("path -> ", "path -> "+this.getRespeakingId());
path = new File(getRecordingsPath(),
dir[0] + "_" + dir[1] + "_" + dir[2] + "/");
} else { path = new File(getRecordingsPath(), this.name + "/"); }
} else if (isElicit()) {
Log.d("elicitation path -> ", "elicitation path -> "+this.getRespeakingId());
path = new File(getRecordingsPath(),
dir[0] + "_" + dir[1] + "_" + dir[2] + "_" + dir[3] + "/");
} else {
path = new File(getRecordingsPath(), this.name + "/");
}
path.mkdirs();
Log.d("destPath", path.toString());
return path;
}
}
......@@ -18,6 +18,7 @@ import java.util.Date;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.lp20.aikuma.Aikuma;
import org.lp20.aikuma.MainActivity;
import org.lp20.aikuma.audio.SimplePlayer;
......@@ -69,6 +70,9 @@ public class RecordElicitation extends AikumaActivity {
private SharedPreferences prefsUserSession;
private String strFolderDate;
private RecordingLig recordingLig;
private String dirName;
private String recordingName;
private String mode = "_elicit";
/**
* the "linker" file
......@@ -94,7 +98,7 @@ public class RecordElicitation extends AikumaActivity {
initSession();
switch (choiceMode) {
case ElicitationMode.TEXT_MODE:
setContentView(R.layout.elicitation);
setContentView(R.layout.elicitation_text);
break;
case ElicitationMode.IMAGE_MODE:
setContentView(R.layout.elicitation_image);
......@@ -105,7 +109,7 @@ public class RecordElicitation extends AikumaActivity {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
default:
setContentView(R.layout.elicitation);
setContentView(R.layout.elicitation_text);
break;
}
......@@ -129,6 +133,7 @@ public class RecordElicitation extends AikumaActivity {
break;
}
updateProgressBar();
Log.d(TAG, "Progress bar (onCreate state) = "+entityId+"/"+numberOfEntities);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
......@@ -275,6 +280,10 @@ public class RecordElicitation extends AikumaActivity {
ptrSelectedReference = prefsUserSession.getString(getString(R.string.sessionInputFile), "");
entityId = prefsUserSession.getInt(getString(R.string.currentLine), 0);
choiceMode = prefsUserSession.getInt(getString(R.string.selectedFileType), ElicitationMode.TEXT_MODE);
dirName = prefsUserSession.getString(getString(R.string.dirname), "");
recordingName = prefsUserSession.getString(getString(R.string.sessionOutputFile), "");
recordingName = prefsUserSession.getString(getString(R.string.sessionOutputFile), "");
Log.d(TAG, "last saved recorded filename: " + recordingName);
ed.clear();
ed.commit();
......@@ -318,24 +327,14 @@ public class RecordElicitation extends AikumaActivity {
}
//if (choiceMode == ElicitationMode.IMAGE_MODE || choiceMode == ElicitationMode.VIDEO_MODE) {
String idDevice = Aikuma.getDeviceId();
String name = strFolderDate + "_" +
recordLang.getCode() + "_" + idDevice;
textFile = new File(FileIO.getOwnerPath()+"/recordings/"+name + "/" + name + "_linker.txt");
File f = new File(ptrSelectedReference);
images = f.listFiles();
// if (!isNewSession) {
// try {
// initBufferedWriter();
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// Toast.makeText(this, "Problem with text output file linker", Toast.LENGTH_SHORT).show();
// this.finish();
// }
// }
//}
String idDevice = Aikuma.getDeviceId();
// String name = strFolderDate + "_" +
// recordLang.getCode() + "_" + idDevice;
dirName = strFolderDate + "_" + recordLang.getCode() + "_" + idDevice + mode;
textFile = new File(FileIO.getOwnerPath()+"/recordings/"+dirName + "/" + dirName + "_linker.txt");
File f = new File(ptrSelectedReference);
images = f.listFiles();
if (!isNewSession) {
try {
......@@ -413,7 +412,7 @@ public class RecordElicitation extends AikumaActivity {
tvFrPhrase = (TextView) findViewById(R.id.tv_orig_phrase);
tvFrPhrase.setText(phrasePair[1]);
TextView tv = (TextView) findViewById(R.id.phrase_x);
tv.setText("Phrase" + entityId);
tv.setText("Phrase" + (entityId+1));
break;
case ElicitationMode.IMAGE_MODE:
loadImage();
......@@ -429,7 +428,7 @@ public class RecordElicitation extends AikumaActivity {
tv2.setText(entityId + "");
updateProgressBar();
Log.d(TAG, "Progress bar (saveOneRecord state) = "+entityId+"/"+numberOfEntities);
} catch (MicException e) {
this.finish();
......@@ -507,23 +506,34 @@ public class RecordElicitation extends AikumaActivity {
* Function called to restore the recordingLig by a json file.
*/
private void restoreMetaDataFromJson() {
String lastSavedMetadataFile = recordingName + RecordingLig.METADATA_SUFFIX;
Log.d(TAG, "last saved metadata file: " + lastSavedMetadataFile);
if (entityId > 0) {
int i = entityId-1;
File metadataFile;
//do is used to get the last json file. Useful in case we have skip sentences
do {
metadataFile = new File(FileIO.getOwnerPath().getAbsolutePath() + "/"+ "recordings" + "/" +this.strFolderDate + "_"+recordLang.getCode()+"_"+Aikuma.getDeviceId(),
this.strFolderDate + "_" + recordLang.getCode() + "_" + Aikuma.getDeviceId() + "_" + i + RecordingLig.METADATA_SUFFIX);
// metadataFile = new File(FileIO.getOwnerPath().getAbsolutePath() + "/"+ "recordings" + "/" +this.strFolderDate + "_"+recordLang.getCode()+"_"+Aikuma.getDeviceId(),
// this.strFolderDate + "_" + recordLang.getCode() + "_" + Aikuma.getDeviceId() + "_" + i + RecordingLig.METADATA_SUFFIX);
metadataFile = new File(FileIO.getOwnerPath().getAbsolutePath() + "/"+ RecordingLig.RECORDINGS + dirName +"/",
dirName + "_" + i + RecordingLig.METADATA_SUFFIX);
i--;
} while (!metadataFile.exists());
Log.d(TAG, "metadataFile : " + metadataFile.getAbsolutePath());
String[] splitRecordingName = recordingName.split("_");
String newRecordingName = splitRecordingName[0]+"_" +splitRecordingName[1]+"_" +splitRecordingName[2]+"_"+splitRecordingName[3]+"_" + entityId;
try {
recordingLig = RecordingLig.read(metadataFile);
int duration = recorder.getCurrentMsec();
recordingLig.setDurationMsec(duration);
recordingLig.setRecordingUUID(recordUUID);
recordingLig.setDeviceName(Aikuma.getDeviceName());
recordingLig.setName(newRecordingName);
} catch (IOException e) {
e.printStackTrace();
}
......@@ -547,12 +557,16 @@ public class RecordElicitation extends AikumaActivity {
: new File(ptrSelectedReference).getName().replace(".txt", "");
String idDevice = Aikuma.getDeviceId();
String recordingName = strFolderDate + "_" +
MetadataSession.getMetadataSession().getRecordLanguage().getCode()
+ "_" + idDevice;
// String recordingName = strFolderDate + "_" +
// MetadataSession.getMetadataSession().getRecordLanguage().getCode()
// + "_" + idDevice;
// + "_elicit_" + new File(eliciTextFile).getName().substring(0,10);
// + "_" + eliciTextFile.substring(0, 10) + "_" + phraseId
recordingName = strFolderDate + "_" +
MetadataSession.getMetadataSession().getRecordLanguage().getCode()
+ "_" + idDevice + mode + "_" + entityId;
Log.i(TAG, "recording name: " + recordingName);
Log.i(TAG, "record directory name: " + dirName);
String gender = "";
int speakerGender = MetadataSession.getMetadataSession().getSpeakerGender();
if (speakerGender == RecordingMetadataLig.GENDER_MALE) {
......@@ -560,11 +574,23 @@ public class RecordElicitation extends AikumaActivity {
} else if (speakerGender == RecordingMetadataLig.GENDER_FEMALE) {
gender = "Female";
}
String groupId = RandomStringUtils.randomAlphabetic(12);
String sourceVerId = AikumaSettings.getLatestVersion() + "-" + groupId;
// recordingLig = new RecordingLig(recordUUID, recordingName, date,
// AikumaSettings.getLatestVersion(),
// AikumaSettings.getCurrentUserId(), recordLang, MetadataSession.getMetadataSession().getMotherTongue(),
// MetadataSession.getMetadataSession().getExtraLanguages(), speakerIds, deviceName, androidID,
// null, null, sampleRate, duration,
// recorder.getFormat(), recorder.getNumChannels(),
// recorder.getBitsPerSample(), latitude, longitude,
// MetadataSession.getMetadataSession().getRegionOrigin(),
// MetadataSession.getMetadataSession().getSpeakerName(),
// MetadataSession.getMetadataSession().getSpeakerAge(), gender);
recordingLig = new RecordingLig(recordUUID, recordingName, date,
AikumaSettings.getLatestVersion(),
AikumaSettings.getCurrentUserId(), recordLang, MetadataSession.getMetadataSession().getMotherTongue(),
MetadataSession.getMetadataSession().getExtraLanguages(), speakerIds, deviceName, androidID,
null, null, sampleRate, duration,
groupId, sourceVerId, dirName, sampleRate, duration,
recorder.getFormat(), recorder.getNumChannels(),
recorder.getBitsPerSample(), latitude, longitude,
MetadataSession.getMetadataSession().getRegionOrigin(),
......@@ -597,9 +623,12 @@ public class RecordElicitation extends AikumaActivity {
try {
recordingLig.write();
String filenamePath = recordingLig.getFile().getAbsolutePath();
// String filenamePath = recordingLig.getFile().getAbsolutePath();
String filenamePath = recordingLig.getElicitFile().getAbsolutePath();
Log.i(TAG, "filename path = "+filenamePath);
FileUtils.copyFile(recordingLig.getFile(),
// FileUtils.copyFile(recordingLig.getFile(),
// new File(filenamePath.replace(".wav", "_" + entityId + ".wav")));
FileUtils.copyFile(recordingLig.getElicitFile(),
new File(filenamePath.replace(".wav", "_" + entityId + ".wav")));
FileIO.delete(new File(filenamePath));
FileUtils.copyFile(new File(filenamePath.replace(".wav", "-metadata.json")),
......@@ -615,7 +644,7 @@ public class RecordElicitation extends AikumaActivity {
bufferedWriter.newLine();
bufferedWriter.flush();
} else {
bufferedWriter.write(ptrSelectedReference + " ; " + new File(filenamePath).getPath().replace(".wav", "_"+entityId+".wav"));
bufferedWriter.write(ptrSelectedReference + " (line "+ (entityId+1) + ") ; " + new File(filenamePath).getPath().replace(".wav", "_"+entityId+".wav"));
Log.d(TAG, "linker content : " + ptrSelectedReference + " (line "+ (entityId+1) + ") ; " + new File(filenamePath).getPath().replace(".wav", "_"+entityId+".wav"));
bufferedWriter.newLine();
bufferedWriter.flush();
......@@ -724,7 +753,8 @@ public class RecordElicitation extends AikumaActivity {
SharedPreferences.Editor ed = prefsUserSession.edit();
ed.putBoolean(getString(R.string.sessionActive), true);
ed.putString(getString(R.string.sessionMode),TAG);
ed.putString(getString(R.string.dirname), dirName);
ed.putString(getString(R.string.sessionOutputFile), recordingName);
ed.putString(getString(R.string.language_name), recordLang.getName());
ed.putString(getString(R.string.languageCode), recordLang.getCode());
ed.putString(getString(R.string.sessionDate), strFolderDate);
......@@ -805,9 +835,9 @@ public class RecordElicitation extends AikumaActivity {
mapFile.delete();
metadataFile.delete();
wavFile.delete();
Log.i(TAG, "map file deleted: "+mapFile);
Log.i(TAG, "metadata file deleted: "+metadataFile);
Log.i(TAG, "wave file deleted: "+wavFile);
Log.i(TAG, "temp map file deleted: "+mapFile);
Log.i(TAG, "temp metadata file deleted: "+metadataFile);
Log.i(TAG, "temp wave file deleted: "+wavFile);
if (isNewSession) {
RecordElicitation.this.finish();
} else {
......
......@@ -189,7 +189,7 @@ public class ThumbRespeakActivityLig extends AikumaActivity {
*/
private void saveCurrentState() {
Log.d("saveCurrentSession", "true");
Toast.makeText(this, "save current not finished session", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "The session has been saved.", Toast.LENGTH_SHORT).show();
duration = respeaker.getSimplePlayer().getCurrentMsec();
Date date = new Date();
DateFormat dateformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment