diff --git a/app/src/main/java/com/mozilla/speechapp/MainActivity.java b/app/src/main/java/com/mozilla/speechapp/MainActivity.java
index a93b8eb..65ae7d2 100644
--- a/app/src/main/java/com/mozilla/speechapp/MainActivity.java
+++ b/app/src/main/java/com/mozilla/speechapp/MainActivity.java
@@ -11,7 +11,9 @@ import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
+import android.widget.CompoundButton;
import android.widget.EditText;
+import android.widget.Switch;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
@@ -23,9 +25,8 @@ import com.mozilla.speechmodule.R;
import static android.support.constraint.Constraints.TAG;
-public class MainActivity extends AppCompatActivity implements ISpeechRecognitionListener {
+public class MainActivity extends AppCompatActivity implements ISpeechRecognitionListener, CompoundButton.OnCheckedChangeListener {
- private Button mButtonStart, mButtonCancel;
private MozillaSpeechService mMozillaSpeechService;
private GraphView mGraph;
private long mDtstart;
@@ -42,6 +43,11 @@ public class MainActivity extends AppCompatActivity implements ISpeechRecognitio
private void initialize() {
+ Button buttonStart, buttonCancel;
+ EditText txtProdutTag, txtLanguage;
+ Switch switchTranscriptions = findViewById(R.id.switchTranscriptions);
+ Switch switchSamples = findViewById(R.id.switchSamples);
+
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
@@ -55,15 +61,20 @@ public class MainActivity extends AppCompatActivity implements ISpeechRecognitio
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
124);
}
- mButtonStart = findViewById(R.id.button_start);
- mButtonCancel = findViewById(R.id.button_cancel);
+
+ buttonStart = findViewById(R.id.button_start);
+ buttonCancel = findViewById(R.id.button_cancel);
+ txtProdutTag = findViewById(R.id.txtProdutTag);
+ txtLanguage = findViewById(R.id.txtLanguage);
mPlain_text_input = findViewById(R.id.plain_text_input);
- mButtonStart.setOnClickListener((View v) -> {
+ buttonStart.setOnClickListener((View v) -> {
try {
mMozillaSpeechService.addListener(this);
mDtstart = System.currentTimeMillis();
mSeries1.resetData(new DataPoint[0]);
+ mMozillaSpeechService.setLanguage(txtLanguage.getText().toString());
+ mMozillaSpeechService.setProductTag(txtProdutTag.getText().toString());
mMozillaSpeechService.start(getApplicationContext());
} catch (Exception e) {
Log.d(TAG, e.getLocalizedMessage());
@@ -71,7 +82,7 @@ public class MainActivity extends AppCompatActivity implements ISpeechRecognitio
}
});
- mButtonCancel.setOnClickListener((View v) -> {
+ buttonCancel.setOnClickListener((View v) -> {
try {
mMozillaSpeechService.cancel();
} catch (Exception e) {
@@ -80,6 +91,11 @@ public class MainActivity extends AppCompatActivity implements ISpeechRecognitio
}
});
+ switchTranscriptions.setOnCheckedChangeListener(this);
+ switchSamples.setOnCheckedChangeListener(this);
+ mMozillaSpeechService.storeTranscriptions(false);
+ mMozillaSpeechService.storeSamples(false);
+
mGraph = findViewById(R.id.graph);
mSeries1 = new LineGraphSeries<>(new DataPoint[0]);
mGraph.addSeries(mSeries1);
@@ -134,4 +150,12 @@ public class MainActivity extends AppCompatActivity implements ISpeechRecognitio
mMozillaSpeechService.removeListener(this);
}
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (buttonView.equals(findViewById(R.id.switchTranscriptions))) {
+ mMozillaSpeechService.storeTranscriptions(isChecked);
+ } else {
+ mMozillaSpeechService.storeSamples(isChecked);
+ }
+ }
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4c38eef..3a2b0c8 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -35,18 +35,56 @@
android:layout_toEndOf="@+id/button_start"
android:text="Cancel" />
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/MozillaSpeechService.java b/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/MozillaSpeechService.java
index 5215670..b238d7e 100644
--- a/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/MozillaSpeechService.java
+++ b/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/MozillaSpeechService.java
@@ -14,6 +14,7 @@ public class MozillaSpeechService {
private ArrayList mListeners;
private Context mContext;
private boolean isIdle = true;
+ NetworkSettings mNetworkSettings;
public enum SpeechState
{
@@ -32,6 +33,7 @@ public class MozillaSpeechService {
private MozillaSpeechService() {
mVad = new Vad();
+ mNetworkSettings = new NetworkSettings();
}
public void start(Context aContext) {
@@ -45,7 +47,8 @@ public class MozillaSpeechService {
if (retVal < 0) {
notifyListeners(SpeechState.ERROR, "Error Initializing VAD " + String.valueOf(retVal));
} else {
- this.mSpeechRecognition = new SpeechRecognition(SAMPLERATE, CHANNELS, mVad, aContext, this);
+ this.mSpeechRecognition = new SpeechRecognition(SAMPLERATE, CHANNELS, mVad, aContext,
+ this, mNetworkSettings);
Thread audio_thread = new Thread(this.mSpeechRecognition);
audio_thread.start();
isIdle = false;
@@ -84,4 +87,20 @@ public class MozillaSpeechService {
}
}
+ public void storeSamples(boolean yesOrNo) {
+ this.mNetworkSettings.mStoreSamples = yesOrNo;
+ }
+
+ public void storeTranscriptions(boolean yesOrNo) {
+ this.mNetworkSettings.mStoreTranscriptions = yesOrNo;
+ }
+
+ public void setLanguage(String language) {
+ this.mNetworkSettings.mLanguage = language;
+ }
+
+ public void setProductTag(String tag) {
+ this.mNetworkSettings.mProductTag = tag;
+ }
+
}
diff --git a/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/Networking.java b/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/Networking.java
index 77b737d..90e3ed1 100644
--- a/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/Networking.java
+++ b/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/Networking.java
@@ -23,7 +23,7 @@ public class Networking {
this.mSpeechService = aSpeechService;
}
- protected void doSTT(final ByteArrayOutputStream baos) {
+ protected void doSTT(final ByteArrayOutputStream baos, NetworkSettings mNetworkSettings) {
if (cancelled) {
mSpeechService.notifyListeners(MozillaSpeechService.SpeechState.CANCELED, null);
@@ -34,7 +34,12 @@ public class Networking {
Looper.prepare();
ByteArrayEntity byteArrayEntity = new ByteArrayEntity(baos.toByteArray());
SyncHttpClient client = new SyncHttpClient();
- client.post(mContext,STT_ENDPOINT, byteArrayEntity, "audio/3gpp",
+ client.addHeader("Accept-Language-STT", mNetworkSettings.mLanguage);
+ client.addHeader("Store-Transcription", mNetworkSettings.mStoreTranscriptions ? "1": "0" );
+ client.addHeader("Store-Sample", mNetworkSettings.mStoreSamples ? "1": "0");
+ client.addHeader("Product-Tag", mNetworkSettings.mProductTag);
+
+ client.post(mContext, STT_ENDPOINT, byteArrayEntity, "audio/3gpp",
new AsyncHttpResponseHandler() {
@Override
@@ -92,3 +97,9 @@ public class Networking {
}
}
+class NetworkSettings {
+ boolean mStoreSamples = true;
+ boolean mStoreTranscriptions = true;
+ String mLanguage;
+ String mProductTag = "moz-android-speech-lib";
+}
\ No newline at end of file
diff --git a/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/SpeechRecognition.java b/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/SpeechRecognition.java
index 90f2762..9e1f007 100644
--- a/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/SpeechRecognition.java
+++ b/mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/SpeechRecognition.java
@@ -27,13 +27,16 @@ class SpeechRecognition implements Runnable {
int mChannels;
MozillaSpeechService mService;
Networking network;
+ NetworkSettings mNetworkSettings;
- protected SpeechRecognition(int aSampleRate, int aChannels, Vad aVad, Context aContext, MozillaSpeechService aService) {
+ protected SpeechRecognition(int aSampleRate, int aChannels, Vad aVad, Context aContext,
+ MozillaSpeechService aService, NetworkSettings mNetworkSettings) {
this.mVad = aVad;
this.mContext = aContext;
this.mSampleRate = aSampleRate;
this.mChannels = aChannels;
this.mService = aService;
+ this.mNetworkSettings = mNetworkSettings;
}
public void run() {
@@ -94,13 +97,13 @@ class SpeechRecognition implements Runnable {
if (finishedvoice) {
this.done = true;
- network.doSTT(baos);
+ network.doSTT(baos, mNetworkSettings);
}
if ((dtdepois - dtantes)/1000 > mUpperLimit ) {
this.done = true;
if (touchedvoice) {
- network.doSTT(baos);
+ network.doSTT(baos, mNetworkSettings);
}
else {
raisenovoice = true;