Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Laurent Besacier
lig-aikuma
Commits
5f0d9e6e
Commit
5f0d9e6e
authored
May 29, 2017
by
mistermad
Browse files
- Adding a comment system in Translating and Respeaking mode
- Minor changes and bugfixing of the file explorer
parent
1d8247e0
Changes
38
Expand all
Hide whitespace changes
Inline
Side-by-side
Lig-Aikuma/app/src/main/AndroidManifest.xml
View file @
5f0d9e6e
...
...
@@ -45,164 +45,138 @@
android:name=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
android:label=
"@string/app_name"
android:windowSoftInputMode=
"adjustPan"
>
android:parentActivityName="org.getalp.ligaikuma.lig_aikuma.ModeSelection">
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.ListenActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.ListenRespeakingActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.CloudSearchActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordVideoActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.SettingsActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataActivity1"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataActivity2"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
tools:targetApi=
"jelly_bean"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataActivity3"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordingMetadataActivity4"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.LanguageFilterList"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.RecordingSpeakersActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.MainSpeakersActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.AddSpeakerActivity1"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.AddSpeakerActivity2"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.AddSpeakerActivity3"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.AddSpeakerActivity4"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.ThumbRespeakActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.PhoneRespeakActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.AddCustomLanguageActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.DefaultLanguagesActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.CloudSettingsActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.SyncSettingsActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.AboutActivity"
android:configChanges=
"orientation"
android:label=
"@string/app_name"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/app_name"
>
</activity>
<activity
android:name=
"org.getalp.ligaikuma.lig_aikuma.ui.HttpServerActivity"
android:label=
"@string/http_server_activity_title"
android:parentActivityName=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
>
android:label=
"@string/http_server_activity_title"
>
<meta-data
android:name=
"android.support.PARENT_ACTIVITY"
android:value=
"org.getalp.ligaikuma.lig_aikuma.MainActivity"
/>
...
...
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/MainActivity.java
View file @
5f0d9e6e
...
...
@@ -90,8 +90,8 @@ public class MainActivity extends ListActivity {
menuBehaviour
=
new
MenuBehaviour
(
this
);
SyncUtil
.
startSyncLoop
(
this
);
new
Aikuma
();
Aikuma
.
loadLanguages
(
this
.
getApplicationContext
());
//
new Aikuma();
//
Aikuma.loadLanguages(this.getApplicationContext());
ActionBar
actionBar
=
getActionBar
();
actionBar
.
setDisplayShowHomeEnabled
(
true
);
...
...
@@ -200,10 +200,6 @@ public class MainActivity extends ListActivity {
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
TAG
,
"original num: "
+
originals
.
size
());
adapter
=
new
RecordingArrayAdapter
(
this
,
originals
);
/*
if(searchView != null) {
adapter.getFilter().filter(searchView.getQuery());
}*/
setListAdapter
(
adapter
);
if
(
listViewState
!=
null
)
getListView
().
onRestoreInstanceState
(
listViewState
);
...
...
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/ModeSelection.java
View file @
5f0d9e6e
...
...
@@ -62,37 +62,31 @@ public class ModeSelection extends Activity implements OnClickListener{
setContentView
(
R
.
layout
.
mode_selection
);
// set owner id with gmail account first but replaced with a random id now
SharedPreferences
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
SharedPreferences
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
//AikumaSettings.setUserId(settings.getString(AikumaSettings.SETTING_OWNER_ID_KEY, null));
if
(
AikumaSettings
.
getCurrentUserId
()
==
null
)
{
Random
r
=
new
Random
();
AikumaSettings
.
setUserId
(
Integer
.
toString
(
r
.
nextInt
()));
AikumaSettings
.
setUserId
(
Integer
.
toString
(
new
Random
().
nextInt
()));
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
TAG
,
AikumaSettings
.
getCurrentUserId
());
}
// DEBUG
Map
<
String
,?>
mapPrefs
=
settings
.
getAll
();
for
(
String
key
:
mapPrefs
.
keySet
())
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
TAG
,
"DEBUG - Shared Preferences - "
+
key
+
" -> "
+
mapPrefs
.
get
(
key
));
if
(
BuildConfig
.
DEBUG
)
{
Map
<
String
,
?>
mapPrefs
=
settings
.
getAll
();
for
(
String
key
:
mapPrefs
.
keySet
())
Log
.
i
(
TAG
,
"DEBUG - Shared Preferences - "
+
key
+
" -> "
+
mapPrefs
.
get
(
key
));
}
// hides the action bar instead of removing it
// getActionBar().hide();
Aikuma
.
loadLanguages
(
this
.
getApplicationContext
());
Button
btn_rec
=
(
Button
)
findViewById
(
R
.
id
.
button_mode_record
);
btn_rec
.
setOnClickListener
(
this
);
Button
btn_respk
=
(
Button
)
findViewById
(
R
.
id
.
button_mode_respeak
);
btn_respk
.
setOnClickListener
(
this
);
Button
btn_trad
=
(
Button
)
findViewById
(
R
.
id
.
mainTradBtn
);
btn_trad
.
setOnClickListener
(
this
);
Button
btn_elicit
=
(
Button
)
findViewById
(
R
.
id
.
mainElicitBtn
);
btn_elicit
.
setOnClickListener
(
this
);
Button
btn_check
=
(
Button
)
findViewById
(
R
.
id
.
mainCheckBtn
);
btn_check
.
setOnClickListener
(
this
);
// Button btn_old_aikuma = (Button) findViewById(R.id.button_mode_slct_old_aikuma);
// btn_old_aikuma.setOnClickListener(this);
findViewById
(
R
.
id
.
button_mode_record
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
button_mode_respeak
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
mainTradBtn
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
mainElicitBtn
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
mainCheckBtn
).
setOnClickListener
(
this
);
// Start gathering location data
MainActivity
.
locationDetector
=
new
LocationDetector
(
this
);
...
...
@@ -177,9 +171,8 @@ public class ModeSelection extends Activity implements OnClickListener{
@Override
public
Dialog
onCreateDialog
(
Bundle
savedInstanceState
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
getActivity
());
LayoutInflater
inflater
=
getActivity
().
getLayoutInflater
();
LinearLayout
ll
=
(
LinearLayout
)
inflater
.
inflate
(
R
.
layout
.
session_dialog
,
null
);
LinearLayout
ll
=
(
LinearLayout
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
session_dialog
,
null
);
setDialogDetails
(
ll
);
...
...
@@ -221,7 +214,7 @@ public class ModeSelection extends Activity implements OnClickListener{
{
String
mode
=
prefsUserSession
.
getString
(
"mode"
,
null
);
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
"mode retrieval: "
+
mode
);
if
(
((
mode
!
=
null
)?
mode
.
compareToIgnoreCase
(
CheckTranscription
.
TAG
)
:
0
)
==
0
)
if
(
mode
=
=
null
||
mode
.
compareToIgnoreCase
(
CheckTranscription
.
TAG
)
==
0
)
startActivity
(
new
Intent
(
getActivity
(),
CheckTranscription
.
class
));
else
if
(
mode
.
compareToIgnoreCase
(
CheckWordVariant
.
TAG
)
==
0
)
startActivity
(
new
Intent
(
getActivity
(),
CheckWordVariant
.
class
));
...
...
@@ -249,7 +242,6 @@ public class ModeSelection extends Activity implements OnClickListener{
* "" / translation ----------> Translation / null
*/
String
mode
=
prefsUserSession
.
getString
(
"mode"
,
"undefined"
);
String
submode
=
prefsUserSession
.
getString
(
"submode"
,
"undefined"
);
String
modeDialog
=
null
,
submodeDialog
=
null
;
if
(
mode
.
compareToIgnoreCase
(
CheckWordVariant
.
TAG
)
==
0
||
mode
.
compareTo
(
CheckTranscription
.
TAG
)
==
0
)
{
...
...
@@ -258,6 +250,7 @@ public class ModeSelection extends Activity implements OnClickListener{
}
else
if
(
mode
.
compareToIgnoreCase
(
RecordElicitation
.
TAG
)
==
0
)
{
String
submode
=
prefsUserSession
.
getString
(
"submode"
,
"undefined"
);
modeDialog
=
"Elicitation"
;
if
(
submode
.
compareToIgnoreCase
(
"text"
)
==
0
)
submodeDialog
=
"text"
;
else
if
(
submode
.
compareToIgnoreCase
(
"image"
)
==
0
)
submodeDialog
=
"image"
;
...
...
@@ -265,6 +258,7 @@ public class ModeSelection extends Activity implements OnClickListener{
}
else
if
(
mode
.
compareToIgnoreCase
(
ThumbRespeakActivityLig
.
TAG
)
==
0
)
{
String
submode
=
prefsUserSession
.
getString
(
"submode"
,
"undefined"
);
if
(
submode
.
compareToIgnoreCase
(
"Respeaking"
)
==
0
)
modeDialog
=
"Respeaking"
;
else
if
(
submode
.
compareToIgnoreCase
(
"translation"
)
==
0
)
modeDialog
=
"Translation"
;
submodeDialog
=
"None"
;
...
...
@@ -290,20 +284,19 @@ public class ModeSelection extends Activity implements OnClickListener{
//Usefull only for Translating and Respeaking ode
MediaPlayerFactory
.
_currentReadFile
=
FileIO
.
getOwnerPath
()+
"/recordings/"
+
file
+
"/"
+
file
+
".wav"
;
Log
.
d
(
TAG
,
MediaPlayerFactory
.
_currentReadFile
);
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
MediaPlayerFactory
.
_currentReadFile
);
}
}
public
void
eraseFiles
()
{
File
savedFile
;
String
savedMode
=
prefsUserSession
.
getString
(
"mode"
,
null
);
String
savedSubmode
=
prefsUserSession
.
getString
(
"submode"
,
"undefined"
);
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
"saved mode: "
+
savedMode
);
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
"saved submode: "
+
savedSubmode
);
String
savedMode
=
prefsUserSession
.
getString
(
"mode"
,
null
),
savedSubmode
=
prefsUserSession
.
getString
(
"submode"
,
"undefined"
);
if
(
BuildConfig
.
DEBUG
){
Log
.
d
(
TAG
,
"saved mode: "
+
savedMode
);
Log
.
d
(
TAG
,
"saved submode: "
+
savedSubmode
);}
/*Check Mode*/
if
(
savedMode
.
compareToIgnoreCase
(
CheckWordVariant
.
TAG
)
==
0
||
savedMode
.
compareTo
(
CheckTranscription
.
TAG
)
==
0
)
{
savedFile
=
new
File
(
prefsUserSession
.
getString
(
"checkExportFile"
,
"undefined"
));
File
savedFile
=
new
File
(
prefsUserSession
.
getString
(
"checkExportFile"
,
"undefined"
));
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
"saved file: "
+
savedFile
);
savedFile
.
delete
();
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
TAG
,
"saved file erased: "
+
savedFile
);
...
...
@@ -311,8 +304,7 @@ public class ModeSelection extends Activity implements OnClickListener{
/*Elicitation Mode*/
}
else
if
(
savedMode
.
compareToIgnoreCase
(
RecordElicitation
.
TAG
)
==
0
)
{
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
"saved submode: "
+
savedSubmode
);
String
idDevice
=
Aikuma
.
getDeviceId
();
String
savedDate
=
prefsUserSession
.
getString
(
"date"
,
""
);
String
idDevice
=
Aikuma
.
getDeviceId
(),
savedDate
=
prefsUserSession
.
getString
(
"date"
,
""
);
Language
savedRecordLang
=
new
Language
(
prefsUserSession
.
getString
(
"Language name"
,
""
),
prefsUserSession
.
getString
(
"LanguageCode"
,
""
));
String
name
=
savedDate
+
"_"
+
savedRecordLang
.
getCode
()
+
"_"
+
idDevice
;
...
...
@@ -324,9 +316,9 @@ public class ModeSelection extends Activity implements OnClickListener{
//erase metadata and audio files
int
savedProgress
=
prefsUserSession
.
getInt
(
"currentLine"
,
0
);
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
"saved progress: "
+
savedProgress
);
for
(
int
i
=
savedProgress
;
i
>=
0
;
i
--)
{
File
savedMetadataFile
=
new
File
(
FileIO
.
getOwnerPath
()+
"/recordings/"
+
name
+
"/"
+
name
+
"_"
+
i
+
RecordingLig
.
METADATA_SUFFIX
)
;
File
savedWavFile
=
new
File
(
FileIO
.
getOwnerPath
()+
"/recordings/"
+
name
+
"/"
+
name
+
"_"
+
i
+
".wav"
);
for
(
int
i
=
savedProgress
;
i
>=
0
;
i
--)
{
File
savedMetadataFile
=
new
File
(
FileIO
.
getOwnerPath
()+
"/recordings/"
+
name
+
"/"
+
name
+
"_"
+
i
+
RecordingLig
.
METADATA_SUFFIX
)
,
savedWavFile
=
new
File
(
FileIO
.
getOwnerPath
()+
"/recordings/"
+
name
+
"/"
+
name
+
"_"
+
i
+
".wav"
);
if
(
BuildConfig
.
DEBUG
)
{
Log
.
d
(
TAG
,
"saved metadata file: "
+
savedMetadataFile
);
Log
.
d
(
TAG
,
"saved metadata file: "
+
savedWavFile
);
...
...
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/audio/record/Mapper.java
View file @
5f0d9e6e
...
...
@@ -10,12 +10,15 @@ import org.getalp.ligaikuma.lig_aikuma.audio.Sampler;
import
org.getalp.ligaikuma.lig_aikuma.lig_aikuma.BuildConfig
;
import
org.getalp.ligaikuma.lig_aikuma.model.Recording
;
import
org.getalp.ligaikuma.lig_aikuma.model.Segments
;
import
org.getalp.ligaikuma.lig_aikuma.util.FileIO
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.UUID
;
import
static
org
.
getalp
.
ligaikuma
.
lig_aikuma
.
model
.
RecordingLig
.
MAP_EXT
;
...
...
@@ -28,7 +31,9 @@ import static org.getalp.ligaikuma.lig_aikuma.model.RecordingLig.MAP_EXT;
* @author Florian Hanke <florian.hanke@gmail.com>
*/
public
class
Mapper
{
public
static
String
TAG
=
"Mapper"
;
/** The segment mapping between the original and the respeaking. */
private
Segments
segments
;
...
...
@@ -85,7 +90,7 @@ public class Mapper {
*
* @return The start of the original segment; or 0L if there is none.
*/
public
Long
getOriginalStartSample
()
{
Long
getOriginalStartSample
()
{
return
(
originalStartOfSegment
!=
null
)?
originalStartOfSegment:
0L
;
}
...
...
@@ -112,7 +117,7 @@ public class Mapper {
*
* @param original The source of the original segments.
*/
public
void
markOriginal
(
Sampler
original
)
{
void
markOriginal
(
Sampler
original
)
{
// If we have already specified an end of the segment then we're
// starting a new one. Otherwise just continue with the old
// originalStartOfSegment
...
...
@@ -127,7 +132,7 @@ public class Mapper {
* @param original The source of the original segments.
* @param respoken The source of the respoken segments.
*/
public
void
markRespeaking
(
Sampler
original
,
Sampler
respoken
)
{
void
markRespeaking
(
Sampler
original
,
Sampler
respoken
)
{
originalEndOfSegment
=
original
.
getCurrentSample
();
respeakingStartOfSegment
=
respoken
.
getCurrentSample
();
}
...
...
@@ -142,7 +147,7 @@ public class Mapper {
* @param respoken The source of the respoken segments.
* @return Returns true if a segment gets stored; false otherwise.
*/
public
boolean
store
(
Sampler
original
,
Sampler
respoken
)
{
boolean
store
(
Sampler
original
,
Sampler
respoken
)
{
//If we're not respeaking and still playing an original segment, do nothing
if
(
originalEndOfSegment
==
null
)
return
false
;
//Otherwise lets end this respeaking segment
...
...
@@ -153,7 +158,7 @@ public class Mapper {
originalSegment
=
new
Segments
.
Segment
(
originalStartOfSegment
,
originalEndOfSegment
);
}
catch
(
IllegalArgumentException
e
)
{
// This could only have happened if no original had been recorded at all.
originalSegment
=
new
Segments
.
Segment
(
0
l
,
0
l
);
originalSegment
=
new
Segments
.
Segment
(
0
L
,
0
L
);
}
segments
.
put
(
originalSegment
,
new
Segments
.
Segment
(
respeakingStartOfSegment
,
respeakingEndOfSegment
));
//Now we say we're marking the start of the new original and respekaing
...
...
@@ -164,5 +169,28 @@ public class Mapper {
originalEndOfSegment
=
null
;
return
true
;
}
/** Remap an existing map file with index file, used the create a no speak map file
*
* @param index index used for remap
*/
public
void
remap
(
int
[]
index
)
{
Log
.
d
(
TAG
,
"Start remap: "
+
Arrays
.
toString
(
index
));
Log
.
d
(
TAG
,
"Destination: "
+
new
File
(
FileIO
.
getNoSyncPath
(),
"tmp_no_speak"
+
MAP_EXT
).
toString
());
String
bufferWrite
=
""
;
Arrays
.
sort
(
index
);
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
;
i
++)
if
(
i
==
index
[
j
])
{
bufferWrite
+=
v
[
i
]+
"\n"
;
j
++;
}
// Write buffer on new map file
Log
.
d
(
TAG
,
"Buffer:\n"
+
bufferWrite
);
FileIO
.
write
(
new
File
(
FileIO
.
getNoSyncPath
(),
"tmp_no_speak"
+
MAP_EXT
),
bufferWrite
);
}
catch
(
IOException
ignored
)
{}
}
}
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/audio/record/Microphone.java
View file @
5f0d9e6e
...
...
@@ -38,22 +38,19 @@ public class Microphone {
/**
* Constructor
*
* @param sampleRate The sample rate at which the audio should be
* recorded
* @throws MicException If the microphone couldn't be set up.
*/
public
Microphone
(
long
sampleRate
)
throws
MicException
{
sampleRate
=
16000
l
;
public
Microphone
()
throws
MicException
{
physicalMicrophone
=
getListener
(
(
int
)
sampleRate
,
(
int
)
16000L
,
AudioFormat
.
ENCODING_PCM_16BIT
,
AudioFormat
.
CHANNEL_IN_MONO
);
boolean
acgOff
=
ensureAGCIsOff
();
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
"agc"
,
"Is the ACG is definitely off: "
+
acgOff
);
if
(
physicalMicrophone
.
getState
()
!=
AudioRecord
.
STATE_INITIALIZED
)
{
if
(
physicalMicrophone
.
getState
()
!=
AudioRecord
.
STATE_INITIALIZED
)
throw
new
MicException
(
"Microphone failed to initialize"
);
};
initializeBuffer
();
}
...
...
@@ -153,17 +150,14 @@ public class Microphone {
// Sample size and Channels.
int
sampleSize
=
(
audioFormat
==
AudioFormat
.
ENCODING_PCM_16BIT
)?
16
:
8
,
numberOfChannels
=
(
channelConfig
==
AudioFormat
.
CHANNEL_IN_MONO
)?
1
:
2
,
// Calculate buffer size.
/** The period used for callbacks to onBufferFull. */
framePeriod
=
sampleRate
*
120
/
1000
,
/** The buffer needed for the above period */
bufferSize
=
framePeriod
*
2
*
sampleSize
*
numberOfChannels
/
8
;
/* The period used for callbacks to onBufferFull. */
framePeriod
=
sampleRate
*
120
/
1000
;
return
new
AudioRecord
(
MediaRecorder
.
AudioSource
.
MIC
,
sampleRate
,
AudioFormat
.
CHANNEL_IN_MONO
,
AudioFormat
.
ENCODING_PCM_16BIT
,
bufferSize
);
AudioFormat
.
ENCODING_PCM_16BIT
,
(
framePeriod
*
2
*
sampleSize
*
((
channelConfig
==
AudioFormat
.
CHANNEL_IN_MONO
)?
1
:
2
/
8
))
);
}
/** Read from the listener's buffer and call the callback. */
...
...
@@ -171,10 +165,8 @@ public class Microphone {
physicalMicrophone
.
startRecording
();
// Wait until something is heard.
while
(
true
)
{
while
(
physicalMicrophone
.
read
(
buffer
,
0
,
buffer
.
length
)
>
0
)
{
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
"thread"
,
"read"
);
if
(
physicalMicrophone
.
read
(
buffer
,
0
,
buffer
.
length
)
<=
0
)
break
;
if
(
Thread
.
interrupted
())
{
if
(
BuildConfig
.
DEBUG
)
Log
.
i
(
"thread"
,
"interrupted"
);
...
...
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/audio/record/PCMWriter.java
View file @
5f0d9e6e
...
...
@@ -161,7 +161,7 @@ public class PCMWriter implements Sampler {
* @param channelConfig Eg. AudioFormat.CHANNEL_IN_MONO
* @param audioFormat Eg. AudioFormat.ENCODING_PCM_16BIT
*/
p
ublic
PCMWriter
(
int
sampleRate
,
int
channelConfig
,
int
audioFormat
)
{
p
rivate
PCMWriter
(
int
sampleRate
,
int
channelConfig
,
int
audioFormat
)
{
currentSample
=
0
;
// Convert the Android attributes to internal attributes.
//
...
...
@@ -187,7 +187,7 @@ public class PCMWriter implements Sampler {
// Check to make sure buffer size is not smaller than
// the smallest allowed size.
//
if
(
bufferSize
<
AudioRecord
.
getMinBufferSize
(
sampleRate
,
channelConfig
,
audioFormat
))
if
(
bufferSize
<
AudioRecord
.
getMinBufferSize
(
sampleRate
,
channelConfig
,
audioFormat
))
{
bufferSize
=
AudioRecord
.
getMinBufferSize
(
sampleRate
,
channelConfig
,
audioFormat
);
if
(
BuildConfig
.
DEBUG
)
Log
.
w
(
PCMWriter
.
class
.
getName
(),
"Increasing buffer size to "
+
Integer
.
toString
(
bufferSize
));
...
...
@@ -197,9 +197,8 @@ public class PCMWriter implements Sampler {
/**
* Tries to create a RandomAccessFile.
*
* @param fullFilename The full path of the file to write.
*/
private
void
createRandomAccessFile
(
String
fullFilename
)
{
private
void
createRandomAccessFile
()
{
try
{
// Random access file.
//
...
...
@@ -227,7 +226,7 @@ public class PCMWriter implements Sampler {
if(BuildConfig.DEBUG)Log.d("new full", "targetFileName => "+fullFilename);
}*/
createRandomAccessFile
(
fullFilename
);
createRandomAccessFile
();
// Write the full WAV PCM file header.
//
...
...
@@ -323,7 +322,7 @@ public class PCMWriter implements Sampler {
// This is only necessary as the randomAccessWriter
// might have been closed.
//
createRandomAccessFile
(
fullFilename
);
createRandomAccessFile
();
try
{
// Write size to RIFF header.
...
...
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/audio/record/PhoneRespeaker.java
View file @
5f0d9e6e
...
...
@@ -55,7 +55,7 @@ public class PhoneRespeaker implements
/** Sets up the microphone for recording. */
private
void
setUpMicrophone
(
long
sampleRate
)
throws
MicException
{
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
"Rte-PhoneRespeak"
,
"sampleRate : "
+
sampleRate
);
this
.
microphone
=
new
Microphone
(
sampleRate
);
this
.
microphone
=
new
Microphone
();
}
/** Sets the file up for writing. */
...
...
Lig-Aikuma/app/src/main/java/org/getalp/ligaikuma/lig_aikuma/audio/record/Recorder.java
View file @
5f0d9e6e
...
...
@@ -148,7 +148,7 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
private
void
setUpMicrophone
(
long
sampleRate
)
throws
MicException
{
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
"Rte-Recorder"
,
"samrate: "
+
sampleRate
);
this
.
sampleRate
=
sampleRate
;
this
.
microphone
=
new
Microphone
(
sampleRate
);
this
.
microphone
=
new
Microphone
();
}
/** Sets the file up for writing. */
...
...
@@ -357,6 +357,6 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
/** Analyzer that analyzes the incoming data. */
private
Analyzer
analyzer
;
/** Facilitates beeping when recording starts and stops.*/
/*
* Facilitates beeping when recording starts and stops.*/