From 2e405277c6c49eb717270e8cf19c3b79e0aeb0f4 Mon Sep 17 00:00:00 2001 From: Andre Natal Date: Tue, 28 Aug 2018 19:09:40 -0700 Subject: [PATCH] Complete Implementation --- .gitignore | 97 + app/.gitignore | 1 + app/build.gradle | 34 + app/proguard-rules.pro | 21 + .../speechmodule/ExampleInstrumentedTest.java | 26 + app/src/main/AndroidManifest.xml | 26 + .../com/mozilla/speechapp/MainActivity.java | 128 ++ .../drawable-v24/ic_launcher_foreground.xml | 34 + .../res/drawable/ic_launcher_background.xml | 170 ++ app/src/main/res/layout/activity_main.xml | 52 + .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 + .../mozilla/speechmodule/ExampleUnitTest.java | 17 + build.gradle | 28 + gradle.properties | 29 + gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++ gradlew.bat | 84 + mozillaspeechlibrary/.gitignore | 1 + mozillaspeechlibrary/build.gradle | 49 + mozillaspeechlibrary/gradle.properties | 3 + mozillaspeechlibrary/maven-push.gradle | 112 ++ mozillaspeechlibrary/proguard-rules.pro | 21 + .../ExampleInstrumentedTest.java | 26 + .../src/main/AndroidManifest.xml | 2 + mozillaspeechlibrary/src/main/cpp/Android.mk | 37 + .../src/main/cpp/cpu_features_wrapper.h | 51 + .../src/main/cpp/signal_processing_library.h | 1686 ++++++++++++++++ mozillaspeechlibrary/src/main/cpp/spl_inl.h | 159 ++ .../src/main/cpp/spl_inl_armv7.h | 137 ++ mozillaspeechlibrary/src/main/cpp/typedefs.h | 145 ++ .../cpp/webrtc/common_audio/audio_util.cc | 41 + .../webrtc/common_audio/include/audio_util.h | 47 + .../webrtc/common_audio/include/typedefs.h | 112 ++ .../common_audio/signal_processing/Android.mk | 126 ++ .../signal_processing/complex_bit_reverse.c | 108 + .../signal_processing/complex_fft.c | 307 +++ .../signal_processing/complex_fft_tables.h | 148 ++ .../signal_processing/cross_correlation.c | 31 + .../signal_processing/division_operations.c | 143 ++ .../signal_processing/downsample_fast.c | 48 + .../common_audio/signal_processing/energy.c | 36 + .../signal_processing/get_scaling_square.c | 44 + .../signal_processing/include/real_fft.h | 128 ++ .../include/signal_processing_library.h | 1779 +++++++++++++++++ .../signal_processing/include/spl_inl.h | 177 ++ .../signal_processing/include/spl_inl_armv7.h | 165 ++ .../signal_processing/include/spl_inl_mips.h | 281 +++ .../signal_processing/min_max_operations.c | 243 +++ .../common_audio/signal_processing/real_fft.c | 126 ++ .../common_audio/signal_processing/resample.c | 505 +++++ .../signal_processing/resample_48khz.c | 186 ++ .../signal_processing/resample_by_2.c | 183 ++ .../resample_by_2_internal.c | 679 +++++++ .../resample_by_2_internal.h | 47 + .../signal_processing/resample_fractional.c | 242 +++ .../common_audio/signal_processing/spl_init.c | 157 ++ .../common_audio/signal_processing/spl_sqrt.c | 184 ++ .../signal_processing/spl_version.c | 25 + .../sqrt_of_one_minus_x_squared.c | 35 + .../vector_scaling_operations.c | 169 ++ .../cpp/webrtc/common_audio/vad/Android.mk | 51 + .../common_audio/vad/include/webrtc_vad.h | 91 + .../cpp/webrtc/common_audio/vad/vad_core.c | 682 +++++++ .../cpp/webrtc/common_audio/vad/vad_core.h | 115 ++ .../webrtc/common_audio/vad/vad_filterbank.c | 334 ++++ .../webrtc/common_audio/vad/vad_filterbank.h | 44 + .../cpp/webrtc/common_audio/vad/vad_gmm.c | 83 + .../cpp/webrtc/common_audio/vad/vad_gmm.h | 39 + .../main/cpp/webrtc/common_audio/vad/vad_sp.c | 179 ++ .../main/cpp/webrtc/common_audio/vad/vad_sp.h | 56 + .../cpp/webrtc/common_audio/vad/webrtc_vad.c | 135 ++ .../src/main/cpp/webrtc_jni.c | 43 + .../src/main/cpp/webrtc_vad.h | 159 ++ .../axet/audiolibrary/encoders/Encoder.java | 9 + .../audiolibrary/encoders/EncoderInfo.java | 14 + .../axet/audiolibrary/encoders/Factory.java | 46 + .../audiolibrary/encoders/FormatOPUS.java | 173 ++ .../audiolibrary/encoders/FormatOPUS_OGG.java | 85 + .../axet/audiolibrary/encoders/Natives.java | 94 + .../axet/audiolibrary/encoders/Resample.java | 104 + .../axet/audiolibrary/encoders/Sound.java | 74 + .../ISpeechRecognitionListener.java | 5 + .../speechlibrary/MozillaSpeechService.java | 80 + .../com/mozilla/speechlibrary/Networking.java | 94 + .../com/mozilla/speechlibrary/STTResult.java | 12 + .../speechlibrary/SpeechRecognition.java | 140 ++ .../java/com/mozilla/speechlibrary/Vad.java | 13 + .../src/main/res/values/strings.xml | 3 + .../speechlibrary/ExampleUnitTest.java | 17 + settings.gradle | 1 + 104 files changed, 12861 insertions(+) create mode 100644 .gitignore create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/mozilla/speechmodule/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/mozilla/speechapp/MainActivity.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/mozilla/speechmodule/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 mozillaspeechlibrary/.gitignore create mode 100644 mozillaspeechlibrary/build.gradle create mode 100644 mozillaspeechlibrary/gradle.properties create mode 100644 mozillaspeechlibrary/maven-push.gradle create mode 100644 mozillaspeechlibrary/proguard-rules.pro create mode 100644 mozillaspeechlibrary/src/androidTest/java/com/mozilla/speechlibrary/ExampleInstrumentedTest.java create mode 100644 mozillaspeechlibrary/src/main/AndroidManifest.xml create mode 100644 mozillaspeechlibrary/src/main/cpp/Android.mk create mode 100644 mozillaspeechlibrary/src/main/cpp/cpu_features_wrapper.h create mode 100644 mozillaspeechlibrary/src/main/cpp/signal_processing_library.h create mode 100644 mozillaspeechlibrary/src/main/cpp/spl_inl.h create mode 100644 mozillaspeechlibrary/src/main/cpp/spl_inl_armv7.h create mode 100644 mozillaspeechlibrary/src/main/cpp/typedefs.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/audio_util.cc create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/include/audio_util.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/include/typedefs.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/Android.mk create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/complex_bit_reverse.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/complex_fft.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/complex_fft_tables.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/cross_correlation.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/division_operations.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/downsample_fast.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/energy.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/get_scaling_square.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/include/real_fft.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/include/signal_processing_library.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/include/spl_inl.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/include/spl_inl_armv7.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/include/spl_inl_mips.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/min_max_operations.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/real_fft.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/resample.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/resample_48khz.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/resample_by_2.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/resample_by_2_internal.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/resample_by_2_internal.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/resample_fractional.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/spl_init.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/spl_sqrt.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/spl_version.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/sqrt_of_one_minus_x_squared.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/signal_processing/vector_scaling_operations.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/Android.mk create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/include/webrtc_vad.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_core.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_core.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_filterbank.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_filterbank.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_gmm.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_gmm.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_sp.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/vad_sp.h create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc/common_audio/vad/webrtc_vad.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc_jni.c create mode 100644 mozillaspeechlibrary/src/main/cpp/webrtc_vad.h create mode 100644 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/Encoder.java create mode 100644 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/EncoderInfo.java create mode 100644 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/Factory.java create mode 100755 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/FormatOPUS.java create mode 100755 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/FormatOPUS_OGG.java create mode 100644 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/Natives.java create mode 100644 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/Resample.java create mode 100644 mozillaspeechlibrary/src/main/java/com/github/axet/audiolibrary/encoders/Sound.java create mode 100644 mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/ISpeechRecognitionListener.java create mode 100644 mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/MozillaSpeechService.java create mode 100644 mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/Networking.java create mode 100644 mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/STTResult.java create mode 100644 mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/SpeechRecognition.java create mode 100644 mozillaspeechlibrary/src/main/java/com/mozilla/speechlibrary/Vad.java create mode 100644 mozillaspeechlibrary/src/main/res/values/strings.xml create mode 100644 mozillaspeechlibrary/src/test/java/com/mozilla/speechlibrary/ExampleUnitTest.java create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25cbd61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,97 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild + +# [Android] ======================== +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + + +## Directory-based project format: +.idea/ + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml + + +# [Maven] ======================== +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties + + +# [Gradle-Android] ======================== + +# Ignore Gradle GUI config +gradle-app.setting + +# Gradle Signing +signing.properties +trestle.keystore + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# Misc +/.idea/workspace.xml +.DS_Store +/captures +**/*.iml +*.class diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..cbe5ca8 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 27 + defaultConfig { + applicationId "com.mozilla.speechmodule" + minSdkVersion 24 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation project(':mozillaspeechlibrary') + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' + implementation 'com.jjoe64:graphview:4.2.2' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/mozilla/speechmodule/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/mozilla/speechmodule/ExampleInstrumentedTest.java new file mode 100644 index 0000000..4cee819 --- /dev/null +++ b/app/src/androidTest/java/com/mozilla/speechmodule/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.mozilla.speechmodule; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.mozilla.speechmodule", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7b2e730 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/mozilla/speechapp/MainActivity.java b/app/src/main/java/com/mozilla/speechapp/MainActivity.java new file mode 100644 index 0000000..d971073 --- /dev/null +++ b/app/src/main/java/com/mozilla/speechapp/MainActivity.java @@ -0,0 +1,128 @@ +package com.mozilla.speechapp; + +import android.Manifest; +import android.app.Activity; +import android.content.pm.PackageManager; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.EditText; + +import com.jjoe64.graphview.GraphView; +import com.jjoe64.graphview.series.DataPoint; +import com.jjoe64.graphview.series.LineGraphSeries; +import com.mozilla.speechlibrary.ISpeechRecognitionListener; +import com.mozilla.speechlibrary.MozillaSpeechService; +import com.mozilla.speechlibrary.STTResult; +import com.mozilla.speechmodule.R; + +import static android.support.constraint.Constraints.TAG; + +public class MainActivity extends AppCompatActivity implements ISpeechRecognitionListener { + + private Button mButtonStart, mButtonCancel; + private MozillaSpeechService mMozillaSpeechService; + private GraphView mGraph; + private long mDtstart; + private LineGraphSeries mSeries1; + private EditText mPlain_text_input; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mMozillaSpeechService = MozillaSpeechService.getInstance(); + mMozillaSpeechService.addListener(this); + initialize(); + } + + private void initialize() { + + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) + != PackageManager.PERMISSION_GRANTED) { + + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, + 123); + } + + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + 124); + } + mButtonStart = findViewById(R.id.button_start); + mButtonCancel = findViewById(R.id.button_cancel); + + mPlain_text_input = findViewById(R.id.plain_text_input); + mButtonStart.setOnClickListener((View v) -> { + try { + mDtstart = System.currentTimeMillis(); + mSeries1.resetData(new DataPoint[0]); + mMozillaSpeechService.start(getApplicationContext()); + } catch (Exception e) { + Log.d(TAG, e.getLocalizedMessage()); + e.printStackTrace(); + } + }); + + mButtonCancel.setOnClickListener((View v) -> { + try { + mMozillaSpeechService.cancel(); + } catch (Exception e) { + Log.d(TAG, e.getLocalizedMessage()); + e.printStackTrace(); + } + }); + + mGraph = findViewById(R.id.graph); + mSeries1 = new LineGraphSeries<>(new DataPoint[0]); + mGraph.addSeries(mSeries1); + mGraph.getViewport().setXAxisBoundsManual(true); + mGraph.getViewport().setScalable(true); + mGraph.getViewport().setScalableY(true); + mGraph.getViewport().setScrollable(true); // enables horizontal scrolling + mGraph.getViewport().setScrollableY(true); // enables vertical scrolling + } + + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + } + + public void onSpeechStatusChanged(MozillaSpeechService.SpeechState aState, Object aPayload){ + this.runOnUiThread(() -> { + switch (aState) { + case DECODING: + mPlain_text_input.append("Decoding... \n"); + break; + case MIC_ACTIVITY: + long mPointx = System.currentTimeMillis() - mDtstart; + mSeries1.appendData(new DataPoint(Math.round(mPointx) + 1, (double)aPayload * -1), true, 3000); + break; + case STT_RESULT: + String message = String.format("Success: %s (%s)", ((STTResult)aPayload).mTranscription, ((STTResult)aPayload).mConfidence); + mPlain_text_input.append(message + "\n"); + break; + case START_LISTEN: + mPlain_text_input.append("Started to listen\n"); + break; + case NO_VOICE: + mPlain_text_input.append("No Voice detected\n"); + break; + case CANCELED: + mPlain_text_input.append("Canceled\n"); + break; + case ERROR: + mPlain_text_input.append("Error:" + aPayload + " \n"); + break; + default: + break; + } + }); + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..4c38eef --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,52 @@ + + + + + + +