Commit fb51193a authored by CallisteHanriat's avatar CallisteHanriat
Browse files

Video elicitation has been implemented

parent eefc1fa8
......@@ -119,6 +119,7 @@
<string name="session_submode">submode</string>
<string name="sessionCheckImportFile">checkImportFile</string>
<string name="sessionCheckExportFile">checkExportFile</string>
<string name="nbReadLines">nbReadLine</string>
<string name="sessionInputFile">inputFile</string>
<string name="mexico">Ex : Mexico</string>
<string name="sessionOutputFile">session_output_file</string>
......
......@@ -181,7 +181,6 @@ public class RecordingLig extends Recording {
super.importMov(recordingUUID, getId());
} else {
this.importWav(recordingUUID, WAV_EXT);
}
......@@ -223,12 +222,11 @@ public class RecordingLig extends Recording {
JSONObject jsonObj = FileIO.readJSONObject(metadataFile);
RecordingLig recording = new RecordingLig(read(jsonObj));
String code = (String) jsonObj.get(RecordingMetadataLig.metaRecordLang);
recording.recordLang = code.isEmpty() ? null : new Language(Aikuma.getLanguageCodeMap().get(code), code);
recording.recordLang = code.isEmpty() ? new Language("","") : new Language(Aikuma.getLanguageCodeMap().get(code), code);
JSONArray jsonArray = (JSONArray) jsonObj.get("languages");
recording.languages = Language.decodeJSONArray(jsonArray);
code = (String) jsonObj.get(RecordingMetadataLig.metaMotherTong);
if (code != null)
recording.motherTong = code.isEmpty() ? null : new Language(Aikuma.getLanguageCodeMap().get(code), code);
recording.motherTong = code.isEmpty() ? new Language("", "") : new Language(Aikuma.getLanguageCodeMap().get(code), code);
recording.regionOrigin = (String) jsonObj.get(RecordingMetadataLig.metaOrigin);
recording.speakerName = (String) jsonObj.get(RecordingMetadataLig.metaSpkrName);
long age = (Long) jsonObj.get(RecordingMetadataLig.metaSpkrBirthYr);
......@@ -254,8 +252,7 @@ public class RecordingLig extends Recording {
encodedRecording.put(RecordingMetadataLig.metaSpkrBirthYr, speakerBirthYear);
encodedRecording.put(RecordingMetadataLig.metaSpkrGender, speakerGender);
encodedRecording.put(RecordingMetadataLig.metaRecordLang, this.recordLang.getCode());
if (this.motherTong != null)
encodedRecording.put(RecordingMetadataLig.metaMotherTong, this.motherTong.getCode());
encodedRecording.put(RecordingMetadataLig.metaMotherTong, this.motherTong.getCode());
Log.i(TAG, "encoding metadata into json format");
return encodedRecording;
}
......
......@@ -22,7 +22,7 @@ import org.lp20.aikuma.util.FileIO;
* @author Oliver Adams <oliver.adams@gmail.com>
* @author Florian Hanke <florian.hanke@gmail.com>
*/
public class Segments implements Serializable {
public class Segments {
/**
* Creates an object that represents a mapping of recording segments between
......
......@@ -86,7 +86,7 @@ public class CheckWordVariant extends AikumaActivity {
variantchecked = prefsUserSession.getString(getString(R.string.sessionCheckExportFile),null);
Log.i(TAG, "Selected export file: " + variantchecked);
//retrieve number of lines already handled in the last session
nbReadLines = prefsUserSession.getInt(getString(R.string.sessionProgress),0);
nbReadLines = prefsUserSession.getInt(getString(R.string.nbReadLines),0);
append = true;
// clear the current stored session
......@@ -302,18 +302,21 @@ public class CheckWordVariant extends AikumaActivity {
* + fichier export: String variantchecked
* + date: String date
*/
Toast.makeText(this, "session saved", Toast.LENGTH_SHORT).show();
date = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.FRANCE).format(new Date());
SharedPreferences.Editor ed = prefsUserSession.edit();
ed.putBoolean(getString(R.string.sessionActive), true); //session activated
ed.putInt(getString(R.string.sessionProgress), nbReadLines); //nb lines
ed.putString(getString(R.string.sessionInputFile), variantTextFile); //handled file
ed.putString(getString(R.string.sessionCheckExportFile), variantchecked); //resulting file
ed.putString(getString(R.string.sessionDate), date); //set date
ed.putString(getString(R.string.sessionMode),TAG); //set mode
// ed.putBoolean(getString(R.string.checkVariant), true); //set submode
//save infos
ed.commit();
if((line == null && nbReadLines < totalNumberOfExpressions) || line != null) {
Toast.makeText(this, "session saved", Toast.LENGTH_SHORT).show();
date = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.FRANCE).format(new Date());
SharedPreferences.Editor ed = prefsUserSession.edit();
ed.putBoolean(getString(R.string.sessionActive), true); //session activated
ed.putInt(getString(R.string.nbReadLines), nbReadLines); //nb lines
ed.putString(getString(R.string.sessionProgress), nbReadLines + "/" + totalNumberOfExpressions);
ed.putString(getString(R.string.sessionInputFile), variantTextFile); //handled file
ed.putString(getString(R.string.sessionCheckExportFile), variantchecked); //resulting file
ed.putString(getString(R.string.sessionDate), date); //set date
ed.putString(getString(R.string.sessionMode),TAG); //set mode
// ed.putBoolean(getString(R.string.checkVariant), true); //set submode
//save infos
ed.commit();
}
} catch (IOException e) {
// TODO Auto-generated catch block
......
......@@ -32,6 +32,9 @@ import org.lp20.aikuma.util.FileIO;
import org.lp20.aikuma2.R;
import android.app.AlertDialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -48,6 +51,7 @@ import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewDebug.FlagToString;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.MediaController;
......@@ -88,7 +92,6 @@ public class RecordElicitation extends AikumaActivity {
super.onCreate(savedInstanceState);
recordUUID = UUID.randomUUID();
// retrieving metadata
prefsUserSession = getSharedPreferences(getString(R.string.userSession), MODE_PRIVATE);
initSession();
......@@ -109,9 +112,6 @@ public class RecordElicitation extends AikumaActivity {
break;
}
ImageButton nextButton = (ImageButton) findViewById(R.id.btn_next);
nextButton.setEnabled(false);
setProgressBarsAtNotTouchableState();
try {
......@@ -132,6 +132,7 @@ public class RecordElicitation extends AikumaActivity {
break;
}
updateProgressBar();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
Log.e(TAG,"text file could not be found: " + e1);
......@@ -246,9 +247,14 @@ public class RecordElicitation extends AikumaActivity {
return BitmapFactory.decodeFile(file.getAbsolutePath(), options);
}
private void initBufferedWriter() throws FileNotFoundException {
FileOutputStream fos;
fos = new FileOutputStream(textFile, true);
bufferedWriter = new BufferedWriter(new OutputStreamWriter(fos));
}
@SuppressWarnings("unchecked")
private void initSession() {
if (prefsUserSession.getBoolean(getString(R.string.sessionActive), false)) {
strFolderDate=prefsUserSession.getString(getString(R.string.sessionDate), "");
recordLang = new Language(prefsUserSession.getString(getString(R.string.language_name), ""),
......@@ -267,12 +273,6 @@ public class RecordElicitation extends AikumaActivity {
ed.clear();
ed.commit();
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(ptrSelectedReference)));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
numberOfEntities = countNumberOfEntities();
......@@ -290,13 +290,6 @@ public class RecordElicitation extends AikumaActivity {
Log.i(TAG, "Selected file: " + ptrSelectedReference);
choiceMode = getIntent().getIntExtra(getString(R.string.selectedFileType), 0);
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(ptrSelectedReference)));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
recordLang = MetadataSession.getMetadataSession().getRecordLanguage();
Bundle bundle = getIntent().getBundleExtra(RecordingMetadataLig.metaBundle);
......@@ -310,35 +303,41 @@ public class RecordElicitation extends AikumaActivity {
strFolderDate = new SimpleDateFormat("yyMMdd-HHmmss").format(date);
}
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 {
FileOutputStream fos;
fos = new FileOutputStream(textFile, true);
bufferedWriter = new BufferedWriter(new OutputStreamWriter(fos));
} 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();
}
}
}
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(ptrSelectedReference)));
if (!isNewSession)
goToGoodPlaceInTextFile();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
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();
}
}
}
}
private void initTxtEncodedFile() {
try {
if (entityId == 0) {
FileOutputStream fos;
fos = new FileOutputStream(textFile);
bufferedWriter = new BufferedWriter(new OutputStreamWriter(fos));
if (!textFile.exists()) {
initBufferedWriter();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
......@@ -472,12 +471,10 @@ public class RecordElicitation extends AikumaActivity {
* @param _view the next button
*/
public void onNextClick(View _view) {
if (saveRecording()) {
saveOneRecord();
} else {
if (!saveRecording())
Toast.makeText(this, "Going to next sentence...", Toast.LENGTH_LONG).show();
}
_view.setEnabled(false);
saveOneRecord();
}
public void onValidate(View _view) {
......@@ -498,11 +495,20 @@ public class RecordElicitation extends AikumaActivity {
*/
private void restoreMetaDataFromJson() {
if (entityId > 0) {
File metadataFile = new File(FileIO.getOwnerPath().getAbsolutePath() + "/"+ "recordings" + "/" +this.strFolderDate + "_"+recordLang.getCode()+"_"+Aikuma.getDeviceId(),
this.strFolderDate + "_" + recordLang.getCode() + "_" + Aikuma.getDeviceId() + "_" + (entityId-1) + RecordingLig.METADATA_SUFFIX);
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);
i--;
} while (!metadataFile.exists());
Log.d("metadataFile : ", "metadataFile : " + metadataFile.getAbsolutePath());
try {
recordingLig = RecordingLig.read(metadataFile);
int duration = recorder.getCurrentMsec();
recordingLig.setDurationMsec(duration);
recordingLig.setRecordingUUID(recordUUID);
recordingLig.setDeviceName(Aikuma.getDeviceName());
} catch (IOException e) {
......@@ -523,8 +529,10 @@ public class RecordElicitation extends AikumaActivity {
ArrayList<String> speakerIds = new ArrayList<String>();
Double latitude = MainActivity.locationDetector.getLatitude();
Double longitude = MainActivity.locationDetector.getLongitude();
String suffix = new File(ptrSelectedReference).getName().replace(".txt", "").length() >= 10 ? new File(ptrSelectedReference).getName().substring(0, 10)
: new File(ptrSelectedReference).getName().replace(".txt", "");
String idDevice = Aikuma.getDeviceId();
String name = strFolderDate + "_" +
MetadataSession.getMetadataSession().getRecordLanguage().getCode()
......@@ -541,14 +549,15 @@ public class RecordElicitation extends AikumaActivity {
recordingLig = new RecordingLig(recordUUID, name, date,
AikumaSettings.getLatestVersion(),
AikumaSettings.getCurrentUserId(), MetadataSession.getMetadataSession().getRecordLanguage(),
MetadataSession.getMetadataSession().getMotherTongue(),
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().getRegionOrigin(),
MetadataSession.getMetadataSession().getSpeakerName(),
MetadataSession.getMetadataSession().getSpeakerAge(), gender);
} else{
restoreMetaDataFromJson();
}
......@@ -559,6 +568,10 @@ public class RecordElicitation extends AikumaActivity {
* @return
*/
private boolean saveRecording() {
if ((recorder != null && recorder.getFile().getPayloadSize() == 0) || recorder == null) {
return false;
}
try {
recorder.stop();
} catch (MicException e) {
......@@ -569,11 +582,6 @@ public class RecordElicitation extends AikumaActivity {
setRecordingLig();
if (recorder != null && recorder.getFile().getPayloadSize() == 0) {
Log.d("recorder1", "recorder <= 50");
return false;
}
try {
recordingLig.write();
String filename = recordingLig.getFile().getAbsolutePath();
......@@ -710,8 +718,7 @@ public class RecordElicitation extends AikumaActivity {
default:
ed.putString(getString(R.string.session_submode), "text");
break;
}
}
ed.commit();
}
......@@ -729,6 +736,7 @@ public class RecordElicitation extends AikumaActivity {
if (safeActivityTransitionMessage != null) {
message = safeActivityTransitionMessage;
}
if (entityId == 0)
this.finish();
......@@ -739,7 +747,8 @@ public class RecordElicitation extends AikumaActivity {
@Override
public void onClick(DialogInterface dialog,
int which) {
if (entityId<numberOfEntities) {
if (entityId<numberOfEntities && textFile.exists()) {
saveCurrentState();
}
if ((choiceMode == ElicitationMode.IMAGE_MODE || choiceMode == ElicitationMode.VIDEO_MODE) && bufferedWriter != null) {
......@@ -749,6 +758,7 @@ public class RecordElicitation extends AikumaActivity {
e.printStackTrace();
}
}
if (isNewSession)
RecordElicitation.this.finish();
else
......
......@@ -340,6 +340,7 @@ public class RespeakingMetadataLig extends AikumaActivity implements OnClickList
// intent.putExtra(RecordActivityLig.intent_versionName, versionName);
// intent.putExtra(RespeakingSelection.RESPEAK, respeak);
startActivity(intent);
finish();
}
})
.setNegativeButton("Cancel", null)
......
......@@ -367,6 +367,7 @@ public class ThumbRespeakActivityLig extends AikumaActivity {
fragment.getRespeaker().saveRespeaking();
//fragment.getRespeaker().playOriginal(1);
setRecordingLig();
saveRecordingJsonInNoSync();
saveCurrentState();
try {
......@@ -386,6 +387,7 @@ public class ThumbRespeakActivityLig extends AikumaActivity {
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
})
......@@ -408,6 +410,7 @@ public class ThumbRespeakActivityLig extends AikumaActivity {
Intent intent = new Intent(ThumbRespeakActivityLig.this, RespeakingSelection.class);
startActivity(intent);
finish();
}
}
})
......
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