Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ hs_err_pid*
/captures
**/*.iml
*.class

mozillaspeechlibrary/.cxx/
15 changes: 8 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "com.mozilla.speechmodule"
minSdkVersion 24
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
}
Expand All @@ -31,12 +31,13 @@ android {

dependencies {
implementation project(':mozillaspeechlibrary')
implementation 'com.loopj.android:android-async-http:1.4.9'
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 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'net.lingala.zip4j:zip4j:1.3.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'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mozilla.speechmodule;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/com/mozilla/speechapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.Manifest;

import android.app.Activity;
import android.app.DownloadManager;

import android.content.pm.PackageManager;
Expand All @@ -13,9 +12,9 @@

import android.database.Cursor;

import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;

Expand All @@ -25,7 +24,6 @@
import android.util.Log;

import android.view.View;
import android.view.WindowManager;

import android.widget.Button;
import android.widget.CompoundButton;
Expand All @@ -46,10 +44,10 @@

import net.lingala.zip4j.core.ZipFile;

import static android.support.constraint.Constraints.TAG;

public class MainActivity extends AppCompatActivity implements ISpeechRecognitionListener, CompoundButton.OnCheckedChangeListener {

private static final String TAG = MainActivity.class.getSimpleName();

private static long sDownloadId;
private static DownloadManager sDownloadManager;

Expand Down Expand Up @@ -103,7 +101,7 @@ private void initialize() {
mMozillaSpeechService.setLanguage(txtLanguage.getText().toString());
mMozillaSpeechService.setProductTag(txtProdutTag.getText().toString());
mMozillaSpeechService.setModelPath(getExternalFilesDir("models").getAbsolutePath());
if (mMozillaSpeechService.ensureModelInstalled()) {
if (!useDeepSpeech.isChecked() || mMozillaSpeechService.ensureModelInstalled()) {
mMozillaSpeechService.start(getApplicationContext());
} else {
maybeDownloadOrExtractModel(getExternalFilesDir("models").getAbsolutePath(), mMozillaSpeechService.getLanguageDir());
Expand Down
72 changes: 39 additions & 33 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mozilla.speechapp.MainActivity">

<RelativeLayout
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.jjoe64.graphview.GraphView
android:layout_width="wrap_content"
android:layout_height="200dip"
android:id="@+id/graph"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
/>
<com.jjoe64.graphview.GraphView
android:id="@+id/graph"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="15dp"/>

<Button
android:id="@+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/graph"
android:text="Start" />
<Button
android:id="@+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_below="@+id/graph"
android:text="Start" />

<Button
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/graph"
android:layout_toEndOf="@+id/button_start"
android:text="Cancel" />
<Button
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/graph"
android:layout_toEndOf="@+id/button_start"
android:text="Cancel" />

<EditText
android:id="@+id/plain_text_input"
android:layout_width="match_parent"
android:layout_height="123dp"
android:layout_height="match_parent"
android:layout_below="@+id/button_start"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="15dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:enabled="false"
android:gravity="top"
android:inputType="textMultiLine"
Expand All @@ -53,25 +56,28 @@
android:id="@+id/useDeepSpeech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/switchTranscriptions"
android:layout_alignParentEnd="true"
android:switchPadding="5dp"
android:text="Use DeepSpeech" />

<Switch
android:id="@+id/switchTranscriptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/switchSamples"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_below="@+id/switchSamples"
android:switchPadding="5dp"
android:text="Store Transcriptions" />

<Switch
android:id="@+id/switchSamples"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/graph"
android:layout_alignParentEnd="true"
android:switchPadding="5dp"
android:text="Store Samples" />

<EditText
Expand All @@ -95,6 +101,6 @@
android:ems="10"
android:inputType="textPersonName"
android:text="en-us" />

</RelativeLayout>
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.mozilla.org/maven2"
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ org.gradle.jvmargs=-Xmx1536m
# org.gradle.parallel=true


VERSION_NAME=1.0.10
VERSION_CODE=10010
VERSION_NAME=1.0.11
VERSION_CODE=10011
GROUP=com.github.mozilla

POM_DESCRIPTION=This is an Android library containing an API to Mozilla's speech recognition services
Expand All @@ -26,4 +26,6 @@ POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=anatal@gmail.com
POM_DEVELOPER_NAME=Andre Natal
POM_DEVELOPER_NAME=Andre Natal
android.useAndroidX=true
android.enableJetifier=true
30 changes: 17 additions & 13 deletions mozillaspeechlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ apply from: 'maven-push.gradle'

def versionMajor = 1
def versionMinor = 0
def versionPatch = 10
def versionPatch = 11

android {
compileSdkVersion 25
compileSdkVersion 28
defaultConfig {
minSdkVersion 24
targetSdkVersion 25
targetSdkVersion 28
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-consumer-rules.pro'

ndk {
Expand All @@ -34,8 +34,8 @@ android {
}

compileOptions {
sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

lintOptions {
Expand All @@ -45,13 +45,17 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'org.mozilla.deepspeech:libdeepspeech:0.6.1@aar'
implementation 'org.gagravarr:vorbis-java-core:0.8'
implementation 'com.github.axet:opus:1.0.2'
implementation 'com.github.axet:jssrc:1.0.2-2'
implementation 'org.apache.commons:commons-math3:3.6.1'
implementation 'androidx.annotation:annotation:1.1.0'

compileOnly 'com.loopj.android:android-async-http:1.4.9'
compileOnly "org.mozilla.geckoview:geckoview-nightly-x86_64:75.0.20200213035745"

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'
api 'org.gagravarr:vorbis-java-core:0.8'
api 'com.github.axet:opus:1.0.2'
api 'com.github.axet:jssrc:1.0.2-2'
api 'org.apache.commons:commons-math3:3.6.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mozilla.speechlibrary;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.mozilla.speechlibrary;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

import com.mozilla.speechlibrary.networking.NetworkSettings;

import org.mozilla.geckoview.GeckoWebExecutor;

import java.util.ArrayList;

public class MozillaSpeechService {
Expand All @@ -12,11 +17,11 @@ public class MozillaSpeechService {
private final int SAMPLERATE = 16000;
private final int CHANNELS = 1;
private ArrayList<ISpeechRecognitionListener> mListeners;
private Context mContext;
private boolean isIdle = true;
NetworkSettings mNetworkSettings;
private NetworkSettings mNetworkSettings;
private boolean useDeepSpeech = false;
private String mModelPath;
private GeckoWebExecutor mExecutor;

public enum SpeechState
{
Expand All @@ -27,7 +32,6 @@ public enum SpeechState
private static final MozillaSpeechService ourInstance = new MozillaSpeechService();
private NetworkSpeechRecognition mNetworkSpeechRecognition;
private LocalSpeechRecognition mLocalSpeechRecognition;
private SpeechState mState;
private Vad mVad;

public static MozillaSpeechService getInstance() {
Expand All @@ -46,7 +50,6 @@ public void start(Context aContext) {
notifyListeners(SpeechState.ERROR, "Recognition already In progress");
} else {
int retVal = mVad.start();
this.mContext = aContext;
if (retVal < 0) {
notifyListeners(SpeechState.ERROR, "Error Initializing VAD " + String.valueOf(retVal));
} else {
Expand Down Expand Up @@ -77,12 +80,11 @@ public void addListener(ISpeechRecognitionListener aListener) {
mListeners.add(aListener);
}

protected void notifyListeners(MozillaSpeechService.SpeechState aState, Object aPayload) {
public void notifyListeners(MozillaSpeechService.SpeechState aState, Object aPayload) {
if (aState == SpeechState.STT_RESULT || aState == SpeechState.ERROR
|| aState == SpeechState.NO_VOICE || aState == SpeechState.CANCELED) {
isIdle = true;
}
mState = aState;
for (ISpeechRecognitionListener listener : mListeners) {
listener.onSpeechStatusChanged(aState, aPayload);
}
Expand Down Expand Up @@ -144,4 +146,14 @@ public void setProductTag(String tag) {
this.mNetworkSettings.mProductTag = tag;
}

public void setGeckoWebExecutor(@NonNull GeckoWebExecutor executor) {
mExecutor = executor;
}

GeckoWebExecutor getGeckoWebExecutor() {
// We used to be able to get the GeckoRuntime instance through GeckoRuntime.getInstance but
// it has been made private so now we need to provide the GeckoWebExecutor from outside
return mExecutor;
}

}
Loading