Commit 83c45b2d authored by Elodie Gauthier's avatar Elodie Gauthier

It is now possible to respeak/translate

a recording made in Elicitation mode.

TODO: name of the files generated by Respeaking/Translating mode
are wrong (not contains "elicit"). It must be corrected.
parent f2ab2fc8
......@@ -149,14 +149,8 @@ public class RecordingLig extends Recording {
File wavFile = new File(getNoSyncRecordingsPath(), wavUUIDExt);
Log.i(TAG, "importwav: " + wavFile.length());
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);
}
File 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());
}
......@@ -208,12 +202,7 @@ public class RecordingLig extends Recording {
// Write the json metadata.
File metadataFile;
if (isElicit()) {
metadataFile = new File(getIndividualRecordingPath(), this.respeakingId + METADATA_SUFFIX);
} else {
metadataFile = new File(getIndividualRecordingPath(), this.name + METADATA_SUFFIX);
}
File metadataFile = new File(getIndividualRecordingPath(), this.name + METADATA_SUFFIX);
FileIO.writeJSONObject(metadataFile,encodedRecording);
Log.i(TAG, "Saved metadata file to " + metadataFile.getAbsolutePath());
}
......@@ -277,16 +266,6 @@ public class RecordingLig extends Recording {
// 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;
......@@ -294,7 +273,8 @@ public class RecordingLig extends Recording {
* @return True if the recording is an elicitation.
*/
public boolean isElicit() {
return this.name.contains("elicit") && !this.name.contains("_rspk") || !this.name.contains("_trsl");
// return this.name.contains("_elicit_") && !this.name.contains("rspk") || !this.name.contains("trsl");
return this.name.contains("elicit");
}
......@@ -314,18 +294,24 @@ public class RecordingLig extends Recording {
File path;
String[] dir = this.getRespeakingId().split("_");
if (this.name.contains("rspk") || this.name.contains("trsl")) {
Log.d("path -> ", "path -> "+this.getRespeakingId());
path = new File(getRecordingsPath(),
dir[0] + "_" + dir[1] + "_" + dir[2] + "/");
if (dir[3].equals("elicit")) {
Log.d(TAG, "elicitation path -> "+this.getRespeakingId());
path = new File(getRecordingsPath(),
dir[0] + "_" + dir[1] + "_" + dir[2] + "_" + dir[3] + "/");
} else {
Log.d(TAG, "path -> "+this.getRespeakingId());
path = new File(getRecordingsPath(),
dir[0] + "_" + dir[1] + "_" + dir[2] + "/");
}
} else if (isElicit()) {
Log.d("elicitation path -> ", "elicitation path -> "+this.getRespeakingId());
Log.d(TAG, "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());
Log.d(TAG, "destPath: "+path.toString());
return path;
}
......
......@@ -18,7 +18,6 @@ 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;
......@@ -30,6 +29,7 @@ import org.lp20.aikuma.model.Recording;
import org.lp20.aikuma.model.RecordingLig;
import org.lp20.aikuma.util.AikumaSettings;
import org.lp20.aikuma.util.FileIO;
import org.lp20.aikuma.util.IdUtils;
import org.lp20.aikuma2.R;
import android.app.AlertDialog;
......@@ -485,8 +485,8 @@ public class RecordElicitation extends AikumaActivity {
* @param _view the next button
*/
public void onNextClick(View _view) {
if (!saveRecording() && (entityId+1 < numberOfEntities)) {
Log.d(TAG,"onNextClick => entityId = "+entityId+"; numberOfEntities = "+numberOfEntities);
if (!saveRecording() && (entityId < numberOfEntities)) {
Log.d(TAG,"onNextClick => entityId was "+entityId+" next it will be"+(entityId+1));
Toast.makeText(this, "Going next...", Toast.LENGTH_SHORT).show();
}
saveOneRecord();
......@@ -574,7 +574,7 @@ public class RecordElicitation extends AikumaActivity {
} else if (speakerGender == RecordingMetadataLig.GENDER_FEMALE) {
gender = "Female";
}
String groupId = RandomStringUtils.randomAlphabetic(12);
String groupId = IdUtils.sampleFromAlphabet(12, "abcdefghijklmnopqrstuvwxyz");
String sourceVerId = AikumaSettings.getLatestVersion() + "-" + groupId;
// recordingLig = new RecordingLig(recordUUID, recordingName, date,
// AikumaSettings.getLatestVersion(),
......@@ -623,29 +623,47 @@ public class RecordElicitation extends AikumaActivity {
try {
recordingLig.write();
// String filenamePath = recordingLig.getFile().getAbsolutePath();
String filenamePath = recordingLig.getElicitFile().getAbsolutePath();
String filePath = recordingLig.getFile().getAbsolutePath(); //absolute path of the file
String filenamePath = ""; //name of the file with its absolute path;
if (entityId >= 0 && entityId < 10) {
filenamePath = filePath.substring(0, filePath.length()-6)+".wav";
} else if (entityId >= 10 && entityId < 100) {
filenamePath = filePath.substring(0, filePath.length()-7)+".wav";
} else if (entityId >= 100 && entityId < 1000) {
filenamePath = filePath.substring(0, filePath.length()-8)+".wav";
} else if (entityId >= 1000 && entityId < 10000) {
filenamePath = filePath.substring(0, filePath.length()-9)+".wav";
} else if (entityId >= 10000 && entityId < 100000) {
filenamePath = filePath.substring(0, filePath.length()-10)+".wav";
}
Log.i(TAG, "filename path = "+filenamePath);
// FileUtils.copyFile(recordingLig.getFile(),
// new File(filenamePath.replace(".wav", "_" + entityId + ".wav")));
FileUtils.copyFile(recordingLig.getElicitFile(),
new File(filenamePath.replace(".wav", "_" + entityId + ".wav")));
/*audio file*/
FileUtils.copyFile(recordingLig.getFile(), new File(filenamePath));
FileIO.delete(recordingLig.getFile());
FileUtils.copyFile(new File(filenamePath),
new File(filenamePath.replace(".wav", "_" + entityId + ".wav")));
/*metadata file*/
// FileUtils.copyFile(new File(filenamePath.replace(".wav", "-metadata.json")),
// new File(filenamePath.replace(".wav", "_" + entityId + "-metadata.json")));
// FileIO.delete(new File(filenamePath.replace(".wav", "-metadata.json")));
FileIO.delete(new File(filenamePath));
FileUtils.copyFile(new File(filenamePath.replace(".wav", "-metadata.json")),
new File(filenamePath.replace(".wav", "_" + entityId + "-metadata.json")));
FileIO.delete(new File(filenamePath.replace(".wav", "-metadata.json")));
recorder.release();
recorder = null;
//write linker file
initTxtEncodedFile();
if (choiceMode == ElicitationMode.IMAGE_MODE || choiceMode == ElicitationMode.VIDEO_MODE) {
bufferedWriter.write(images[entityId].getPath() + " ; " +new File(filenamePath).getPath().replace(".wav", "_"+entityId+".wav"));
Log.d(TAG, "linker content : " + images[entityId].getPath() + " ; " + new File(filenamePath).getPath().replace(".wav", "_"+entityId+".wav"));
// bufferedWriter.write(images[entityId].getPath() + " ; " +new File(filePath).getPath().replace(".wav", "_"+entityId+".wav"));
bufferedWriter.write(images[entityId].getPath() + " ; " +new File(filePath).getPath());
Log.d(TAG, "linker content : " + images[entityId].getPath() + " ; " + new File(filePath));
bufferedWriter.newLine();
bufferedWriter.flush();
} else {
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.write(ptrSelectedReference + " (line "+ (entityId+1) + ") ; " + new File(filePath).getPath().replace(".wav", "_"+entityId+".wav"));
bufferedWriter.write(ptrSelectedReference + " (line "+ (entityId+1) + ") ; " + new File(filePath).getPath());
Log.d(TAG, "linker content : " + ptrSelectedReference + " (line "+ (entityId+1) + ") ; " + new File(filePath).getPath());
bufferedWriter.newLine();
bufferedWriter.flush();
}
......
......@@ -431,7 +431,11 @@ public class RecordingMetadataLig extends AikumaActivity implements OnClickListe
}
if (recordLang == null || speakerName.isEmpty()) {
msgError = "Some fields remain empty, please fill it.";
if (recordLang == null) {
msgError = "The recording language is empty, please fill it.";
} else if (speakerName.isEmpty()) {
msgError = "The name of the speaker is empty, please fill it.";
}
new AlertDialog.Builder(this)
.setMessage(msgError)
.setPositiveButton("Ok", null)
......
......@@ -285,8 +285,12 @@ public class RespeakingMetadataLig extends AikumaActivity implements OnClickList
message = RecordingMetadataLig.missFieldsMsg;
} else { message = RecordingMetadataLig.validateMsg; }*/
if (respeak_lang.isEmpty() && speakerName .isEmpty()) {
msgError = "Some fields remain empty, please fill it.";
if (respeak_lang.isEmpty() || speakerName.isEmpty()) {
if (respeak_lang.isEmpty()) {
msgError = "Please fill the respeaking language field.";
} else if (speakerName.isEmpty()) {
msgError = "Please fill the name of the speaker.";
}
new AlertDialog.Builder(this)
.setMessage(msgError)
.setPositiveButton("Ok", null)
......
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