-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
android studio demo for alexa
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Snowboy Demo on Adroid | ||
|
||
Note: | ||
|
||
1. supported building platforms are Android Studio running on Mac OS X or Ubuntu. Windows is not supported. | ||
2. supported target CPU is ARMv7 (most Android phones run on ARM CPUs) | ||
|
||
## General Workflow | ||
|
||
1. Install `swig`. For Mac, do `brew install swig`; for Ubuntu, do `sudo apt-get install swig3.0`. Make sure your `swig` version is at least `3.0.10`. | ||
|
||
2. Go to `swig/Android` and build swig wrappers for Snowboy: | ||
|
||
cd swig/Android | ||
make | ||
|
||
Ths will generate a cross-compiled library for ARM: | ||
|
||
jniLibs/armeabi-v7a/libsnowboy-detect-android.so | ||
|
||
and a few Java wrapper files: | ||
|
||
java | ||
└── ai | ||
└── kitt | ||
└── snowboy | ||
├── SnowboyDetect.java | ||
├── snowboy.java | ||
└── snowboyJNI.java | ||
|
||
The generated `.so` and `.java` files are hyperlinked to the `examples/Android/SnowboyAlexaDemo` folder. | ||
|
||
3. Use Android Studio to open the project in `examples/Android/SnowboyAlexaDemo` and run it. | ||
|
||
Screenshot (say "Alexa" after clicking "Start"): | ||
|
||
<img src="https://s3-us-west-2.amazonaws.com/kittai-cdn/Snowboy/SnowboyAlexaDemo-Andriod.jpeg" alt="Android Alexa Demo" width=300 /> | ||
|
||
|
||
Don't forget to disable the "debug" option when releasing your Android App! | ||
|
||
Note: If you need to copy the Android demo to another folder, please use the `-RL` option of `cp` to replace the relative symbol links with real files: | ||
|
||
cp -RL SnowboyAlexaDemo Other_Folder | ||
|
||
Note: The sample app will save/overwrite all audio to a file (`recording.pcm`). Make sure you do not leave it on for a long time. | ||
|
||
## Useful Code Snippets | ||
|
||
|
||
To initialize Snowboy detector in Java: | ||
|
||
# Assume you put the model related files under /sdcard/snowboy/ | ||
SnowboyDetect snowboyDetector = new SnowboyDetect("/sdcard/snowboy/common.res", | ||
"/sdcard/snowboy/snowboy.umdl"); | ||
snowboyDetector.SetSensitivity("0.45"); // Sensitivity for each hotword | ||
snowboyDetector.SetAudioGain(2.0); // Audio gain for detection | ||
|
||
To run hotword detection in Java: | ||
|
||
int result = snowboyDetector.RunDetection(buffer, buffer.length); // buffer is a short array. | ||
|
||
You may want to play with the frequency of the calls to `RunDetection()`, which controls the CPU usage and the detection latency. | ||
|
||
|
||
## TODO | ||
|
||
The following TODOs will be fixed by 2017/4 in the upcoming Snowboy v1.2.0 release. | ||
|
||
- [x] softfloating point support with OpenBlas | ||
- [x] upgrade NDK version to newer than r11c | ||
- [x] NDK toolchain building: remove `--stl=libc++` option | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | ||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> | ||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="gen"/> | ||
<classpathentry kind="output" path="bin/classes"/> | ||
</classpath> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
*.apk | ||
*.ap_ | ||
.metadata/ | ||
.idea/workspace.xml | ||
.idea/tasks.xml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Alexa19</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:versionCode="1" | ||
android:versionName="1.0" package="ai.kitt.snowboy.demo" > | ||
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher"> | ||
<activity android:name="ai.kitt.snowboy.Demo" | ||
android:windowSoftInputMode="stateHidden" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
<uses-sdk android:minSdkVersion="3" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> | ||
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission> | ||
<uses-permission android:name="android.permission.INTERNET"></uses-permission> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../resources/alexa_02092017.umdl |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../resources/common.res |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../resources/ding.wav |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.3.0' | ||
} | ||
} | ||
apply plugin: 'android' | ||
|
||
dependencies { | ||
compile fileTree(include: '*.jar', dir: 'libs') | ||
} | ||
|
||
android { | ||
signingConfigs { | ||
} | ||
compileSdkVersion 25 | ||
buildToolsVersion '25.0.0' | ||
compileOptions.encoding = 'ISO-8859-1' | ||
sourceSets { | ||
main { | ||
manifest.srcFile 'AndroidManifest.xml' | ||
java.srcDirs = ['src'] | ||
resources.srcDirs = ['src'] | ||
aidl.srcDirs = ['src'] | ||
renderscript.srcDirs = ['src'] | ||
res.srcDirs = ['res'] | ||
assets.srcDirs = ['assets'] | ||
} | ||
|
||
// Move the tests to tests/java, tests/res, etc... | ||
instrumentTest.setRoot('tests') | ||
|
||
// Move the build types to build-types/<type> | ||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... | ||
// This moves them out of them default location under src/<type>/... which would | ||
// conflict with src/ being used by the main source set. | ||
// Adding new build types or product flavors should be accompanied | ||
// by a similar customization. | ||
debug.setRoot('build-types/debug') | ||
release.setRoot('build-types/release') | ||
} | ||
buildTypes { | ||
release { | ||
} | ||
} | ||
defaultConfig { | ||
} | ||
productFlavors { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Tue Mar 07 14:27:10 PST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip |