Commit b2b8989e authored by mistermad's avatar mistermad

- Change the processing of the session backup in eliciting mode

- Adds the generation of an ELAN-compatible mappin file (.csv)
- Deleting classes and dependencies
- Change naming convention
parent f597ed01
......@@ -3,7 +3,6 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "org.getalp.ligaikuma"
minSdkVersion 16
......@@ -34,12 +33,9 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(path: ':library')
compile project(path: ':waveform_view_library')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-core-utils:25.3.1'
compile 'com.android.support:multidex:1.0.1'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.itextpdf:itextg:5.5.10'
testCompile 'junit:junit:4.12'
}
......@@ -20,7 +20,6 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
......@@ -32,11 +31,6 @@
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan">
</activity>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakActivity"
android:configChanges="orientation"
android:label="@string/app_name">
</activity>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ModeSelection">
<intent-filter>
......@@ -45,29 +39,29 @@
</intent-filter>
</activity>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataLig"
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadata"
android:configChanges="orientation|screenSize">
</activity>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.LanguageFilterList"/>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RecordActivityLig"
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RecordActivity"
android:configChanges="orientation|screenSize"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.RespeakingSelection"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.RespeakingFileExplorer"/>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RespeakingMetadataLig"
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RespeakingMetadata"
android:configChanges="orientation|screenSize"/>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakActivityLig"
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakActivity"
android:configChanges="orientation|screenSize"/>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakSummaryLig"
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakSummary"
android:configChanges="orientation|screenSize">
</activity>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ElicitationMode"
android:configChanges="orientation|screenSize"/>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.RecordElicitation"
android:name="org.getalp.ligaikuma.lig_aikuma.ui.ElicitationRecord"
android:configChanges="orientation|screenSize"/>
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.CheckMode"
......@@ -78,9 +72,9 @@
<activity
android:name="org.getalp.ligaikuma.lig_aikuma.ui.CheckTranscription"
android:configChanges="orientation|screenSize"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.SpeakerActivity"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.ShareFileActivity"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.ElicitationFileSearch"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.SpeakerProfile"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.ShareFile"/>
<activity android:name="org.getalp.ligaikuma.lig_aikuma.ui.ElicitationFileExplorer"/>
</application>
</manifest>
\ No newline at end of file
......@@ -6,15 +6,10 @@ package org.getalp.ligaikuma.lig_aikuma;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import org.getalp.ligaikuma.lig_aikuma.model.Language;
import org.getalp.ligaikuma.lig_aikuma.util.AikumaSettings;
import org.getalp.ligaikuma.lig_aikuma.util.FileIO;
import java.io.IOException;
......@@ -38,7 +33,6 @@ public class Aikuma extends android.app.Application {
private static Aikuma instance;
private static Map<String, String> languageCodeMap;
private static SharedPreferences preferences;
private static List<Language> languages;
public static Context appContext = null;
......@@ -91,24 +85,6 @@ public class Aikuma extends android.app.Application {
public static String getDeviceId() {
return getAndroidID().substring(0, 3);
}
/**
* Checks whether the device is currently connected to a network
* @return boolean for status
*/
public static boolean isDeviceOnline() {
if(preferences == null) {
preferences = PreferenceManager.getDefaultSharedPreferences(appContext);
AikumaSettings.isOnlyWifi = preferences.getBoolean(AikumaSettings.WIFI_MODE_KEY, true);
}
ConnectivityManager connMgr = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = (AikumaSettings.isOnlyWifi)?
connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI):
connMgr.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
}
/**
* Returns the ISO 639-3 languages once they are loaded.
......@@ -134,8 +110,6 @@ public class Aikuma extends android.app.Application {
return languageCodeMap;
}
/**
* Loads the ISO 639-3 languages.
*/
......
......@@ -5,28 +5,18 @@
package org.getalp.ligaikuma.lig_aikuma;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.BuildConfig;
import org.getalp.ligaikuma.lig_aikuma.lig_aikuma.R;
import org.getalp.ligaikuma.lig_aikuma.model.Recording;
import org.getalp.ligaikuma.lig_aikuma.ui.sensors.LocationDetector;
import org.getalp.ligaikuma.lig_aikuma.util.AikumaSettings;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
/**
* The primary activity that lists existing recordings and allows you to select
......@@ -39,9 +29,6 @@ public class MainActivity extends ListActivity {
private static final String TAG = "MainActivity";
private static final int RECOVER_FROM_AUTH_ERROR_REQUEST_CODE = 1001;
private static final int RECOVER_FROM_GOOGLEPLAY_ERROR_REQUEST_CODE = 1002;
public static LocationDetector locationDetector;
// Helps us store how far down the list we are when MainActivity gets
......@@ -54,24 +41,13 @@ public class MainActivity extends ListActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//new Aikuma();
//Aikuma.loadLanguages(this.getApplicationContext());
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// Load setting values
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
// settings.edit().clear().commit();
AikumaSettings.isBackupEnabled = settings.getBoolean(AikumaSettings.BACKUP_MODE_KEY, false);
AikumaSettings.isAutoDownloadEnabled = settings.getBoolean(AikumaSettings.AUTO_DOWNLOAD_MODE_KEY, false);
// Start gathering location data
MainActivity.locationDetector = new LocationDetector(this);
checkDate();
// Create an index file when app starts
try {
Recording.indexAll();
......@@ -89,10 +65,8 @@ public class MainActivity extends ListActivity {
@Override
public void onResume() {
super.onResume();
List<Recording> recordings = Recording.readAll();
if(BuildConfig.DEBUG)Log.i(TAG, "num: " +recordings.size());
super.onResume();
if(BuildConfig.DEBUG)Log.i(TAG, "num: " +Recording.readAll().size());
if(listViewState != null)
getListView().onRestoreInstanceState(listViewState);
......@@ -103,7 +77,6 @@ public class MainActivity extends ListActivity {
@Override
protected void onStart() {
super.onStart();
//LocalBroadcastManager.getInstance(this).registerReceiver(syncReceiver, new IntentFilter(GoogleCloudService.SYNC_RESULT));
showProgressStatus(View.GONE);
}
......@@ -117,68 +90,13 @@ public class MainActivity extends ListActivity {
super.onDestroy();
MainActivity.locationDetector.stop();
}
// If current year < 2000, make the user type in the correct date continuously
private void checkDate() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
if(BuildConfig.DEBUG)Log.i(TAG, "year: " + year);
if(year < 2000) {
new AlertDialog.Builder(this)
.setTitle("Set the current date correctly")
.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
startActivityForResult(intent, PICK_DATE_REQUEST_CODE);
}
}).show();
}
}
/**
* Show the status of cloud-background thread
* @param visibility Visibility of the progress bar View
*/
public void showProgressStatus(int visibility) {
ProgressBar pStatus = (ProgressBar) findViewById(R.id.cloudProgress);
pStatus.setVisibility(visibility);
findViewById(R.id.cloudProgress).setVisibility(visibility);
}
private static final int PICK_DATE_REQUEST_CODE = 0;
/////////////////////////////////////////////////////
//// /////
//// Things pertaining to getting Google token. /////
//// /////
/////////////////////////////////////////////////////
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == RECOVER_FROM_AUTH_ERROR_REQUEST_CODE ||
requestCode == RECOVER_FROM_GOOGLEPLAY_ERROR_REQUEST_CODE)
&& resultCode == RESULT_OK) {
handleReRequestResult(resultCode, data);
return;
} else if(requestCode == PICK_DATE_REQUEST_CODE)
checkDate();
super.onActivityResult(requestCode, resultCode, data);
}
private void handleReRequestResult(int resultCode, Intent data) {
if (data == null) {
Toast.makeText(this, "Unknown error, Retry it", Toast.LENGTH_LONG).show();
return;
}
if (resultCode == RESULT_OK) {
// User recovered error, retry to get access_token
if(!Aikuma.isDeviceOnline())
Toast.makeText(this, "Network is disconnected", Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(this, "Unknown error, Retry it", Toast.LENGTH_SHORT).show();
}
}
......@@ -26,11 +26,11 @@ import org.getalp.ligaikuma.lig_aikuma.ui.CheckMode;
import org.getalp.ligaikuma.lig_aikuma.ui.CheckTranscription;
import org.getalp.ligaikuma.lig_aikuma.ui.CheckWordVariant;
import org.getalp.ligaikuma.lig_aikuma.ui.ElicitationMode;
import org.getalp.ligaikuma.lig_aikuma.ui.RecordElicitation;
import org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataLig;
import org.getalp.ligaikuma.lig_aikuma.ui.RespeakingSelection;
import org.getalp.ligaikuma.lig_aikuma.ui.ShareFileActivity;
import org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakActivityLig;
import org.getalp.ligaikuma.lig_aikuma.ui.ElicitationRecord;
import org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadata;
import org.getalp.ligaikuma.lig_aikuma.ui.RespeakingFileExplorer;
import org.getalp.ligaikuma.lig_aikuma.ui.ShareFile;
import org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakActivity;
import org.getalp.ligaikuma.lig_aikuma.ui.sensors.LocationDetector;
import org.getalp.ligaikuma.lig_aikuma.util.AikumaSettings;
import org.getalp.ligaikuma.lig_aikuma.util.FileIO;
......@@ -101,14 +101,14 @@ public class ModeSelection extends Activity implements OnClickListener{
// TODO then adapt the respeaking interface to allow the edition of latest segments
// TODO then adapt the summary view to allow the edition and playing of every segment
case R.id.button_mode_respeak:
startActivity(new Intent(ModeSelection.this, RespeakingSelection.class));
startActivity(new Intent(ModeSelection.this, RespeakingFileExplorer.class));
if(BuildConfig.DEBUG)Log.i(TAG, "Mode respeaking selected; view id: " + v.getId());
break;
case R.id.button_mode_record:
startActivity(new Intent(ModeSelection.this, RecordingMetadataLig.class));
startActivity(new Intent(ModeSelection.this, RecordingMetadata.class));
break;
case R.id.mainTradBtn:
Intent intent = new Intent(ModeSelection.this, RespeakingSelection.class);
Intent intent = new Intent(ModeSelection.this, RespeakingFileExplorer.class);
intent.putExtra(TRANSLATE_MODE, true);
startActivity(intent);
if(BuildConfig.DEBUG)Log.i(TAG, "Mode translation selected; view id: " + v.getId());
......@@ -148,7 +148,7 @@ public class ModeSelection extends Activity implements OnClickListener{
public void onShareButtonClick(View _v)
{
startActivity(new Intent(this, ShareFileActivity.class));
startActivity(new Intent(this, ShareFile.class));
}
// START DIALOG DECLARATION
......@@ -188,36 +188,31 @@ public class ModeSelection extends Activity implements OnClickListener{
startActivity(new Intent(ModeSelection.this, CheckTranscription.class));
else if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0)
startActivity(new Intent(ModeSelection.this, CheckWordVariant.class));
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
startActivity(new Intent(ModeSelection.this, ThumbRespeakActivityLig.class));
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
startActivity(new Intent(ModeSelection.this, RecordElicitation.class));
else if (mode.compareToIgnoreCase(ThumbRespeakActivity.TAG) == 0)
startActivity(new Intent(ModeSelection.this, ThumbRespeakActivity.class));
else if (mode.compareToIgnoreCase(ElicitationRecord.TAG) == 0)
startActivity(new Intent(ModeSelection.this, ElicitationRecord.class));
else
Toast.makeText(this, "An error ocurred. The session could not be retrieved", Toast.LENGTH_LONG).show();
}
public void setDialogDetails(LinearLayout ll) {
String mode = prefsUserSession.getString("mode", "undefined");
if (mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || mode.compareTo(CheckTranscription.TAG) == 0)
{
;
if(mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0 || mode.compareTo(CheckTranscription.TAG) == 0)
((TextView) ll.findViewById(R.id.session_submode)).setText(
(mode.compareToIgnoreCase(CheckWordVariant.TAG) == 0) ? CheckWordVariant.TAG : CheckTranscription.TAG);
}
else if (mode.compareToIgnoreCase(RecordElicitation.TAG) == 0)
else if(mode.compareToIgnoreCase(ElicitationRecord.TAG) == 0)
{
String submode = prefsUserSession.getString("submode", "text");
((TextView) ll.findViewById(R.id.session_mode)).setText("Elicitation");
((TextView) ll.findViewById(R.id.session_submode)).setText(submode.toLowerCase());
((TextView) ll.findViewById(R.id.session_submode)).setText(prefsUserSession.getString("submode", "text").toLowerCase());
}
else if (mode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0)
else if(mode.compareToIgnoreCase(ThumbRespeakActivity.TAG) == 0)
{
String submode = prefsUserSession.getString("submode", "undefined");
if(submode.compareToIgnoreCase("Respeaking") == 0)
((TextView) ll.findViewById(R.id.session_mode)).setText("Respeaking");
else if(submode.compareToIgnoreCase("translation") == 0)
((TextView) ll.findViewById(R.id.session_mode)).setText("Translation");
((TextView) ll.findViewById(R.id.session_submode)).setText("None");
}
......@@ -256,7 +251,7 @@ public class ModeSelection extends Activity implements OnClickListener{
if(BuildConfig.DEBUG)Log.i(TAG, "saved file erased: "+savedFile);
/*Elicitation Mode*/
} else if (savedMode.compareToIgnoreCase(RecordElicitation.TAG) == 0) {
} else if (savedMode.compareToIgnoreCase(ElicitationRecord.TAG) == 0) {
if(BuildConfig.DEBUG)Log.d(TAG, "saved submode: "+savedSubmode);
String idDevice = Aikuma.getDeviceId(), savedDate = prefsUserSession.getString("date", "");
Language savedRecordLang = new Language(prefsUserSession.getString("Language name", ""),
......@@ -291,7 +286,7 @@ public class ModeSelection extends Activity implements OnClickListener{
* user does not want to save its session
* nor its recordings
*/
}// else if (savedMode.compareToIgnoreCase(ThumbRespeakActivityLig.TAG) == 0) {
}// else if (savedMode.compareToIgnoreCase(ThumbRespeakActivity.TAG) == 0) {
// if (savedSubmode.compareToIgnoreCase(getString(R.string.respeak)) == 0) {
/*TODO
* erase the _rspk files
......
/*
Copyright (C) 2013, The Aikuma Project
AUTHORS: Oliver Adams and Florian Hanke
*/
package org.getalp.ligaikuma.lig_aikuma.audio;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
/**
* Provides methods to change which of the phone's speakers the audio is played
* through.
*
* @author Oliver Adams <oliver.adams@gmail.com>
* @author Florian Hanke <florian.hanke@gmail.com>
*/
public class Audio {
/**
* Resets the activity playing through the main speakers.
*
* @param activity The activity in question.
*/
public static void reset(Activity activity) {
playThroughSpeaker(activity);
}
/**
* Plays the audio through the earpiece, like a phone call.
*
* @param activity The activity that this method governs.
* @param toSetMode True if the Audiomanager needs to be set to call mode.
*/
public static void playThroughEarpiece(Activity activity, boolean toSetMode) {
AudioManager audioManager = getAudioManager(activity);
if(toSetMode) audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(false);
}
/**
* Plays the audio through the main speaker (not the earpiece as a phone
* call would)
*
* @param activity The activity that this method governs.
*/
public static void playThroughSpeaker(Activity activity) {
AudioManager audioManager = getAudioManager(activity);
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
}
/**
* Gets the audio manager for the given activity.
*
* @param activity The activity whose AudioManager is needed.
* @return The audiomanager.
*/
protected static AudioManager getAudioManager(Activity activity) {
return (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
}
}
......@@ -91,16 +91,6 @@ public class Beeper {
start(context, listener, R.raw.beeps2);
}
/**
* Plays a long beep.
*
* @param context The context to play the beep in
* @param listener The callback to play when the beep is complete.
*/
public static void longBeep(Context context, OnCompletionListener listener) {
start(context, listener, R.raw.longbeep);
}
// Starts playing the given audio resource.
private static void start(Context context, final OnCompletionListener listener, int resource) {
new Beeper(context).create(listener, resource).start();
......
......@@ -34,8 +34,8 @@ public class InterleavedPlayer extends Player {
*/
public InterleavedPlayer(Recording recording) throws IOException {
setRecording(recording);
if (recording.isOriginal())
throw new IllegalArgumentException("The supplied Recording is " + "not a respeaking. Use SimplePlayer instead.");
if(recording.isOriginal())
throw new IllegalArgumentException("The supplied Recording is not a respeaking. Use SimplePlayer instead.");
setSampleRate(recording.getSampleRate());
original = new MarkedPlayer(recording.getOriginal(), new OriginalMarkerReachedListener(), true);
respeaking = new MarkedPlayer(recording, new RespeakingMarkerReachedListener(), true);
......@@ -53,8 +53,8 @@ public class InterleavedPlayer extends Player {
//boolean completedOnce = false;
@Override
public void onCompletion(Player p) {
if (completedOnce) {
if (onCompletionListener != null)
if(completedOnce) {
if(onCompletionListener != null)
onCompletionListener.onCompletion(p);
reset();
}
......
......@@ -5,7 +5,6 @@
package org.getalp.ligaikuma.lig_aikuma.audio;
import org.getalp.ligaikuma.lig_aikuma.model.Recording;
import org.getalp.ligaikuma.lig_aikuma.model.Segments.Segment;
import java.io.File;
......
......@@ -3,7 +3,7 @@ package org.getalp.ligaikuma.lig_aikuma.audio;
import android.app.Activity;
import org.getalp.ligaikuma.lig_aikuma.model.Segments.Segment;
import org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakSummaryLig;
import org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakSummary;
import java.io.File;
import java.io.IOException;
......@@ -78,7 +78,7 @@ public class SegmentPlayer extends MarkedPlayer
OnMarkerReachedListener onEndSegmentMarkerReachedListener =
new OnMarkerReachedListener() {
public void onMarkerReached(MarkedPlayer p) {
((ThumbRespeakSummaryLig) activity).pauseFragment(segment);
((ThumbRespeakSummary) activity).pauseFragment(segment);
// p.pause();
p.seekTo(segment);
setNotificationMarkerPosition(segment);
......
......@@ -18,6 +18,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.UUID;
import static org.getalp.ligaikuma.lig_aikuma.model.RecordingLig.MAP_EXT;
......@@ -94,13 +95,13 @@ public class Mapper {
}
private void restoreFromMappingFile() throws IOException {
String line;
String line, pair[], strFirstSeg[], strSecondSeg[];
while((line = reader.readLine()) != null && (line.isEmpty() || line.split(":").length <= 1));
if(BuildConfig.DEBUG && line!=null)Log.d("line", line);
do {
String[] pair = (line != null) ? line.split(":"):new String[0],
strFirstSeg = pair[0].split(","),
strSecondSeg = pair[1].split(",");
pair = (line != null) ? line.split(":"):new String[0];
strFirstSeg = pair[0].split(",");
strSecondSeg = pair[1].split(",");
Segments.Segment original = new Segments.Segment(Long.parseLong(strFirstSeg[0]), Long.parseLong(strFirstSeg[1]));
if(BuildConfig.DEBUG)Log.d("original seg ", original.getStartSample() + " -> " + original.getEndSample());
Segments.Segment rspkSeg = new Segments.Segment(Long.parseLong(strSecondSeg[0]), Long.parseLong(strSecondSeg[1]));
......@@ -180,13 +181,100 @@ public class Mapper {
try {
// Read original map file and remap it on buffer
String[] v = FileIO.read(mappingFile).split("\n");
for(int i=0,j=0;i<v.length&&j<index.length;i++) {
if (i == index[j]) {
for(int i=0,j=0;i<v.length&&j<index.length;i++)
if(i == index[j]) {
bufferWrite += v[i] + "\n";
j++;
}
}
FileIO.write(new File(FileIO.getNoSyncPath(),"tmp_no_speech"+MAP_EXT), bufferWrite);
} catch (IOException ignored) {}
}
/** Convert map files to csv file can be processed by softwar like ELAN
*
* @param index index used for remap
*/
public void toCSV(int [] index){toCSV(index, mappingFile);}
/** Convert map files to csv file can be processed by softwar like ELAN
*
* @param index index used for remap
* @param mapFile Original map file use to create csv
*/
public void toCSV(int [] index, File mapFile)
{
String bufferWrite="", tSplit1[], tSplit2[], tNospeach;
float a,b,c,d;
Arrays.sort(index);
try {
// Read original map file and remap it on buffer
String[] v = FileIO.read(mapFile).split("\n");
for(int i=0,j=0;i<v.length&&j<index.length;i++) {
tSplit1 = v[i].split(":");
tSplit2 = tSplit1[1].split(",");
tSplit1 = tSplit1[0].split(",");
a = Float.parseFloat(tSplit1[0])/16000;
b = Float.parseFloat(tSplit1[1])/16000;
c = Float.parseFloat(tSplit2[0])/16000;
d = Float.parseFloat(tSplit2[1])/16000;
if(i == index[j]){tNospeach = "non-speech";j++;}
else tNospeach = "";
if(i!=0) bufferWrite+="\n";
bufferWrite += "original,"+ Float.toString(a)+","+Float.toString(b)+","+Float.toString(b-a)+","+tNospeach+"\n"+
"trsl,"+ Float.toString(c)+","+Float.toString(d)+","+Float.toString(d-c)+","+tNospeach;
}
FileIO.write(new File(FileIO.getNoSyncPath(),"tmp_elan.csv"), bufferWrite);
} catch (IOException ignored) {}
}
/** Not tested but use it if you want integrate it on an other soft
*
* @param mapFile Base map file
* @param noSpeechFile Map file used to select non-speech segments
* @param destinationFile Full name and path of destination file example: ./record/csv/example.csv
*/
public void toCSV(File mapFile, File noSpeechFile, File destinationFile)
{
// Get index of non-speech segment
LinkedList<Integer> l = new LinkedList<>();
try {
String[] v1 = FileIO.read(mapFile).split("\n"),
v2 = FileIO.read(noSpeechFile).split("\n");
for(int i=0,j=0;i<v1.length&&j<v2.length;i++)
if(v1[i].equals(v2[j]))
{
l.add(i);
j++;
}
} catch (IOException ignored) {}