├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ └── sync
│ │ │ │ ├── models
│ │ │ │ ├── en-us-ptm
│ │ │ │ │ ├── mdef.md5
│ │ │ │ │ ├── means.md5
│ │ │ │ │ ├── noisedict.md5
│ │ │ │ │ ├── sendump.md5
│ │ │ │ │ ├── variances.md5
│ │ │ │ │ ├── en-phone.dmp.md5
│ │ │ │ │ ├── feat.params.md5
│ │ │ │ │ ├── transition_matrices.md5
│ │ │ │ │ ├── noisedict
│ │ │ │ │ ├── mdef
│ │ │ │ │ ├── means
│ │ │ │ │ ├── sendump
│ │ │ │ │ ├── variances
│ │ │ │ │ ├── en-phone.dmp
│ │ │ │ │ ├── transition_matrices
│ │ │ │ │ └── feat.params
│ │ │ │ └── lm
│ │ │ │ │ └── words.dic.md5
│ │ │ │ └── assets.lst
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_stat_hearing.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_stat_hearing.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_stat_hearing.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_stat_hearing.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── arrays.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_hotword.xml
│ │ │ │ ├── fragment_hotword_detected.xml
│ │ │ │ └── listener_fragment.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ └── ic_launcher.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_mic_gray_128dp.xml
│ │ │ │ ├── ic_mic_green_128dp.xml
│ │ │ │ ├── ic_mic_light_gray_128dp.xml
│ │ │ │ ├── ic_mic_off_red_128dp.xml
│ │ │ │ ├── ic_happy_36.xml
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable-anydpi-v24
│ │ │ │ └── ic_stat_hearing.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── tuckercr
│ │ │ │ └── zamzam
│ │ │ │ ├── HotWordDetectedFragment.kt
│ │ │ │ ├── prefs
│ │ │ │ └── PrefsManager.kt
│ │ │ │ ├── ListenerService.kt
│ │ │ │ ├── BindingAdapters.kt
│ │ │ │ ├── DictionaryRepository.kt
│ │ │ │ ├── ListenerFragment.kt
│ │ │ │ ├── NotificationUtils.kt
│ │ │ │ ├── ListenerViewModel.kt
│ │ │ │ └── HotWordActivity.kt
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── tuckercr
│ │ └── zamzam
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshots
├── main.png
├── fg_service.png
└── triggered.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── codeStyles
│ └── Project.xml
└── markdown-navigator.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── README.md
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/mdef.md5:
--------------------------------------------------------------------------------
1 | ba13d30c2fee63e039e119ab449bd618
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/means.md5:
--------------------------------------------------------------------------------
1 | d0ee21e7d0e03575f27497b2833c6f02
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/lm/words.dic.md5:
--------------------------------------------------------------------------------
1 | 7966c7291fc744969ea90a961178e924
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/noisedict.md5:
--------------------------------------------------------------------------------
1 | 05034ffef21f4810d10d3c76a6f5e921
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/sendump.md5:
--------------------------------------------------------------------------------
1 | 75328625279cdbb72f800b315365ff45
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/variances.md5:
--------------------------------------------------------------------------------
1 | d4d6ba74707952aa7e00c3bc1e7d0fb4
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/en-phone.dmp.md5:
--------------------------------------------------------------------------------
1 | 912236bae5e072d02ab1ec5b0c202a68
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/feat.params.md5:
--------------------------------------------------------------------------------
1 | 1124afb8cc8f875fd2daa47683e68530
2 |
--------------------------------------------------------------------------------
/screenshots/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/screenshots/main.png
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/transition_matrices.md5:
--------------------------------------------------------------------------------
1 | 7a63d8971f81eef2154ea38b8bdfe520
2 |
--------------------------------------------------------------------------------
/screenshots/fg_service.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/screenshots/fg_service.png
--------------------------------------------------------------------------------
/screenshots/triggered.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/screenshots/triggered.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/noisedict:
--------------------------------------------------------------------------------
1 | SIL
2 | SIL
3 | SIL
4 | [NOISE] +NSN+
5 | [SPEECH] +SPN+
6 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/mdef:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/assets/sync/models/en-us-ptm/mdef
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/means:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/assets/sync/models/en-us-ptm/means
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/sendump:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/assets/sync/models/en-us-ptm/sendump
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/variances:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/assets/sync/models/en-us-ptm/variances
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_stat_hearing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/drawable-hdpi/ic_stat_hearing.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_stat_hearing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/drawable-mdpi/ic_stat_hearing.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_stat_hearing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/drawable-xhdpi/ic_stat_hearing.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_stat_hearing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/res/drawable-xxhdpi/ic_stat_hearing.png
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/en-phone.dmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/assets/sync/models/en-us-ptm/en-phone.dmp
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/transition_matrices:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tuckercr/wakewordapp/HEAD/app/src/main/assets/sync/models/en-us-ptm/transition_matrices
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #B71C1C
4 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/assets.lst:
--------------------------------------------------------------------------------
1 | models/lm/words.dic
2 | models/en-us-ptm/feat.params
3 | models/en-us-ptm/mdef
4 | models/en-us-ptm/means
5 | models/en-us-ptm/noisedict
6 | models/en-us-ptm/sendump
7 | models/en-us-ptm/transition_matrices
8 | models/en-us-ptm/variances
9 |
--------------------------------------------------------------------------------
/app/src/main/assets/sync/models/en-us-ptm/feat.params:
--------------------------------------------------------------------------------
1 | -lowerf 130
2 | -upperf 6800
3 | -nfilt 25
4 | -transform dct
5 | -lifter 22
6 | -feat 1s_c_d_dd
7 | -svspec 0-12/13-25/26-38
8 | -agc none
9 | -cmn batch
10 | -varnorm no
11 | -model ptm
12 | -cmninit 40,10,10
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_hotword.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 28 14:06:48 EDT 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #b71c1c
4 | #7f0000
5 | #f05545
6 | #e8e6d9
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_mic_gray_128dp.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_mic_green_128dp.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_mic_light_gray_128dp.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_mic_off_red_128dp.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_happy_36.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tuckercr/zamzam/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.assertEquals;
12 |
13 | /**
14 | * Instrumentation test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.tuckercr.zamzam", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/wolf/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
16 |
17 |
18 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi-v24/ic_stat_hearing.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ZamZam
3 |
4 | Sensitivity:
5 | Go Back
6 | Listening for hotword
7 | Background Service Notifications
8 | Alerts you when the app is listening
9 | Hot Word Notifications
10 | Alerts you when the app hears a hot word
11 | Hotword Detected!
12 | Click here to return to app.
13 | ZamZam is listening in the background
14 | Click the button to test again.
15 | Yes
16 | No
17 | Do you want to stop the recognizer?
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/HotWordDetectedFragment.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 |
9 | /**
10 | * A simple Fragment for when the hotword is detected
11 | */
12 | class HotWordDetectedFragment : Fragment() {
13 | override fun onCreateView(
14 | inflater: LayoutInflater, container: ViewGroup?,
15 | savedInstanceState: Bundle?
16 | ): View? {
17 | return inflater.inflate(R.layout.fragment_hotword_detected, container, false)
18 | }
19 |
20 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
21 | super.onViewCreated(view, savedInstanceState)
22 | view.findViewById(R.id.button).setOnClickListener { v: View? -> buttonPressed() }
23 | }
24 |
25 | private fun buttonPressed() {
26 | // Go back
27 | requireActivity().onBackPressed()
28 | }
29 |
30 | companion object {
31 | const val FTAG = "HotWordDetectedFragment"
32 | fun newInstance(): HotWordDetectedFragment {
33 | return HotWordDetectedFragment()
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ZamZam
2 |
3 | An POC app demonstrating on-device wake word voice recognition using the PocketSphinx engine
4 |
5 | The app lets you select a wake word, and then - even with the app in the background or the phone in your pocket - it notifies you noisily and with vibration when that word is head.
6 |
7 | The sensitivity of the voice reco engine is tunable to balance between false positives and not hearing the word.
8 |
9 | The idea of this app is that it could be useful for someone that is hearing impaired to help them when someone says their names. The app does not use or require any kind of network connection for the voice recognition.
10 |
11 | ## Technologies Used:
12 |
13 | - [PocketSphinx](http://www.speech.cs.cmu.edu/pocketsphinx/)
14 | - [Databinding](https://developer.android.com/topic/libraries/data-binding)
15 | - [View Binding](https://developer.android.com/topic/libraries/view-binding)
16 | - [Smart Material Spinner](https://developer.android.com/guide/components/loaders)
17 | - [Foreground Services](https://developer.android.com/guide/components/foreground-services)
18 | - [Notifications](https://developer.android.com/guide/topics/ui/notifiers/notifications)
19 |
20 | ## Screenshots
21 |
22 | ### Main Page
23 | 
24 |
25 | ### Foreground Service
26 | 
27 |
28 | ### Wake Word Triggered
29 | 
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | .idea/jarRepositories.xml
48 | # Android Studio 3 in .gitignore file.
49 | .idea/caches
50 | .idea/modules.xml
51 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
52 | .idea/navEditor.xml
53 |
54 | .idea/compiler.xml
55 | .idea/misc.xml
56 |
57 | # Keystore files
58 | # Uncomment the following lines if you do not want to check your keystore files in.
59 | *.jks
60 | *.keystore
61 |
62 | # External native build folder generated in Android Studio 2.2 and later
63 | .externalNativeBuild
64 | .cxx/
65 |
66 | # Google Services (e.g. APIs or Firebase)
67 | # google-services.json
68 |
69 | # Freeline
70 | freeline.py
71 | freeline/
72 | freeline_project_description.json
73 |
74 | # fastlane
75 | fastlane/report.xml
76 | fastlane/Preview.html
77 | fastlane/screenshots
78 | fastlane/test_output
79 | fastlane/readme.md
80 |
81 | # Version control
82 | vcs.xml
83 |
84 | # lint
85 | lint/intermediates/
86 | lint/generated/
87 | lint/outputs/
88 | lint/tmp/
89 | # lint/reports/
90 |
91 | # Android Profiling
92 | *.hprof
93 | .DS_Store
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
25 |
26 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/prefs/PrefsManager.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam.prefs
2 |
3 | import android.content.Context
4 | import android.content.SharedPreferences
5 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener
6 |
7 | class PrefsManager private constructor(context: Context) {
8 | private val mPref: SharedPreferences
9 | fun getInt(key: String, defValue: Int): Int {
10 | return mPref.getInt(key, defValue)
11 | }
12 |
13 | fun putInt(key: String, value: Int) {
14 | mPref.edit().putInt(key, value).apply()
15 | }
16 |
17 | fun getString(key: String, defValue: String): String? {
18 | return mPref.getString(key, defValue)
19 | }
20 |
21 | fun putString(key: String, value: String) {
22 | mPref.edit().putString(key, value).apply()
23 | }
24 |
25 | fun getBoolean(key: String): Boolean {
26 | return mPref.getBoolean(key, false)
27 | }
28 |
29 | fun putBoolean(key: String, value: Boolean) {
30 | mPref.edit().putBoolean(key, value).apply()
31 | }
32 |
33 | fun remove(key: String) {
34 | mPref.edit().remove(key).apply()
35 | }
36 |
37 | fun clear(): Boolean {
38 | return mPref.edit().clear().commit()
39 | }
40 |
41 | fun registerListener(listener: OnSharedPreferenceChangeListener?) {
42 | mPref.registerOnSharedPreferenceChangeListener(listener)
43 | }
44 |
45 | fun unregisterListener(listener: OnSharedPreferenceChangeListener?) {
46 | mPref.unregisterOnSharedPreferenceChangeListener(listener)
47 | }
48 |
49 | companion object {
50 | const val KEY_WAKE_WORD = "wake_word"
51 | private const val PREF_NAME = "com.tuckercr.zamzam.prefs"
52 | private var sInstance: PrefsManager? = null
53 | @Synchronized
54 | fun initialize(context: Context) {
55 | if (sInstance == null) {
56 | sInstance = PrefsManager(context)
57 | }
58 | }
59 |
60 | @JvmStatic
61 | @get:Synchronized
62 | val instance: PrefsManager?
63 | get() {
64 | checkNotNull(sInstance) { "Not initialized" }
65 | return sInstance
66 | }
67 | }
68 |
69 | init {
70 | mPref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
71 | }
72 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 |
5 | android {
6 | compileSdkVersion 31
7 | defaultConfig {
8 | applicationId 'com.tuckercr.zamzam'
9 | minSdkVersion 21
10 | //noinspection ExpiredTargetSdkVersion
11 | targetSdkVersion 29
12 | versionCode 2
13 | versionName "1.0"
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | compileOptions {
23 | sourceCompatibility = 1.8
24 | targetCompatibility = 1.8
25 | }
26 | buildFeatures {
27 | dataBinding true
28 | }
29 | }
30 |
31 | dependencies {
32 | def lifecycle_version = "2.4.0"
33 | def paging_version = "3.1.0"
34 |
35 | implementation 'androidx.core:core-ktx:1.7.0'
36 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
37 |
38 | // Test stuff
39 | testImplementation 'junit:junit:4.13.2'
40 | androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
41 | exclude group: 'com.android.support', module: 'support-annotations'
42 | })
43 |
44 | // Pocket Sphinx
45 | implementation fileTree(dir: 'libs', include: ['*.jar'])
46 | implementation(name: 'pocketsphinx-android-5prealpha-release', ext: 'aar')
47 |
48 | // AndroidX Libs
49 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
50 | implementation 'androidx.appcompat:appcompat:1.4.1'
51 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
52 |
53 |
54 | // ViewModel
55 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
56 | // LiveData
57 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
58 |
59 | // Searchable Spinner library
60 | implementation 'com.github.chivorns:smartmaterialspinner:1.5.0'
61 |
62 | // Saved state module for ViewModel
63 | implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
64 |
65 | // Annotation processor
66 | implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
67 |
68 | implementation "androidx.paging:paging-runtime-ktx:$paging_version"
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/ListenerService.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.app.Activity
4 | import android.app.Service
5 | import android.content.Intent
6 | import android.os.IBinder
7 | import android.util.Log
8 |
9 | /**
10 | * Foreground Service for sticky notifications
11 | *
12 | * @author colintucker
13 | */
14 | class ListenerService : Service() {
15 | override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
16 | if (ACTION_START_FOREGROUND == intent.action) {
17 | Log.i(TAG, "onStartCommand: Received Start Foreground Intent")
18 | val wakeWord = intent.getStringExtra(EXTRA_WAKE_WORD)!!
19 | val notification = NotificationUtils.createServiceNotification(this, wakeWord)
20 | startForeground(NotificationUtils.NOTIFICATION_ID_SERVICE, notification)
21 | } else if (ACTION_STOP_FOREGROUND == intent.action) {
22 | Log.i(TAG, "onStartCommand: Received Stop Foreground Intent")
23 | stopForeground(true)
24 | stopSelf()
25 | }
26 |
27 | // This was START_STICKY but when service is recreated it causes the intent to be null
28 | return START_REDELIVER_INTENT
29 | }
30 |
31 | override fun onCreate() {
32 | super.onCreate()
33 | Log.d(TAG, "onCreate() called")
34 | }
35 |
36 | override fun onDestroy() {
37 | super.onDestroy()
38 | Log.d(TAG, "onDestroy() called")
39 | }
40 |
41 | override fun onBind(intent: Intent): IBinder? {
42 | // Used only in case of bound services.
43 | return null
44 | }
45 |
46 | companion object {
47 | private const val TAG = "ListeningService"
48 | private const val ACTION_START_FOREGROUND = "action_start_foreground"
49 | private const val ACTION_STOP_FOREGROUND = "action_stop_foreground"
50 | private const val EXTRA_WAKE_WORD = "wake_word"
51 | fun createStartForegroundIntent(activity: Activity, wakeWord: String): Intent {
52 | val intent = Intent(activity, ListenerService::class.java)
53 | intent.action = ACTION_START_FOREGROUND
54 | intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
55 | intent.putExtra(EXTRA_WAKE_WORD, wakeWord)
56 | return intent
57 | }
58 |
59 | fun createStopForegroundIntent(activity: Activity): Intent {
60 | val stopForegroundIntent = Intent(activity, ListenerService::class.java)
61 | stopForegroundIntent.action = ACTION_STOP_FOREGROUND
62 | return stopForegroundIntent
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/BindingAdapters.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.view.View
4 | import android.widget.AdapterView
5 | import android.widget.AdapterView.OnItemSelectedListener
6 | import android.widget.ArrayAdapter
7 | import androidx.appcompat.widget.AppCompatImageView
8 | import androidx.appcompat.widget.AppCompatSpinner
9 | import androidx.databinding.BindingAdapter
10 | import androidx.databinding.InverseBindingAdapter
11 | import androidx.databinding.InverseBindingListener
12 | import com.tuckercr.zamzam.ListenerFragment.MicState
13 | import com.tuckercr.zamzam.prefs.PrefsManager
14 | import com.tuckercr.zamzam.prefs.PrefsManager.Companion.instance
15 |
16 | object BindingAdapters {
17 | @JvmStatic
18 | @BindingAdapter("micState")
19 | fun setMicStateImage(view: View?, @MicState micState: Int) {
20 | if (view !is AppCompatImageView) {
21 | return
22 | }
23 | when (micState) {
24 | MicState.DISABLED_NO_PERMISSION -> view.setImageResource(R.drawable.ic_mic_off_red_128dp)
25 | MicState.OFF -> view.setImageResource(R.drawable.ic_mic_light_gray_128dp)
26 | MicState.LISTENING -> view.setImageResource(R.drawable.ic_mic_gray_128dp)
27 | MicState.SPEAKING -> view.setImageResource(R.drawable.ic_mic_green_128dp)
28 | }
29 | }
30 |
31 | @JvmStatic
32 | @BindingAdapter(value = ["selectedValue", "selectedValueAttrChanged"], requireAll = false)
33 | fun bindSpinnerData(
34 | pAppCompatSpinner: AppCompatSpinner,
35 | newSelectedValue: String?,
36 | newTextAttrChanged: InverseBindingListener
37 | ) {
38 | pAppCompatSpinner.onItemSelectedListener = object : OnItemSelectedListener {
39 | override fun onItemSelected(
40 | parent: AdapterView<*>?,
41 | view: View,
42 | position: Int,
43 | id: Long
44 | ) {
45 | newTextAttrChanged.onChange()
46 | }
47 |
48 | override fun onNothingSelected(parent: AdapterView<*>?) {}
49 | }
50 | if (newSelectedValue != null) {
51 | val pos =
52 | (pAppCompatSpinner.adapter as ArrayAdapter).getPosition(newSelectedValue)
53 | pAppCompatSpinner.setSelection(pos, true)
54 | }
55 | }
56 |
57 | @JvmStatic
58 | @InverseBindingAdapter(attribute = "selectedValue", event = "selectedValueAttrChanged")
59 | fun captureSelectedValue(pAppCompatSpinner: AppCompatSpinner): String? {
60 |
61 | // Log.d(TAG, "captureSelectedValue: selectedItem = [" + pAppCompatSpinner.getSelectedItem() + "]");
62 | if (pAppCompatSpinner.selectedItem == null) {
63 | return null
64 | }
65 |
66 | // There's a shared preference listener in the ViewModel that'll notice this changed
67 | instance!!.putString(PrefsManager.KEY_WAKE_WORD, pAppCompatSpinner.selectedItem.toString())
68 | return pAppCompatSpinner.selectedItem as String
69 | }
70 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_hotword_detected.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
26 |
27 |
40 |
41 |
50 |
51 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/DictionaryRepository.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.app.Application
4 | import android.util.Log
5 | import edu.cmu.pocketsphinx.Assets
6 | import java.io.BufferedReader
7 | import java.io.IOException
8 | import java.io.InputStreamReader
9 | import java.util.*
10 |
11 | internal object DictionaryRepository {
12 | private const val TAG = "DictionaryRepository"
13 |
14 | // Map>
15 | fun loadList(application: Application): List {
16 | Log.d(TAG, "loadList() called")
17 | val wordList: MutableList = ArrayList()
18 | try {
19 | val assets = Assets(application)
20 | val assetsDir = assets.syncAssets()
21 | val open = application.assets.open(assetsDir.name + "/models/lm/words.dic")
22 | val reader = BufferedReader(InputStreamReader(open))
23 |
24 | // do reading, usually loop until end of file reading
25 | var line: String?
26 | while (reader.readLine().also { line = it } != null) {
27 | if (line == null) {
28 | break
29 | }
30 | val word = line!!.substring(0, line!!.indexOf(' '))
31 | if (line!!.indexOf('(') > 0) {
32 | // Log.i(TAG, "loadList: Ignoring secondary pronunciation: $line");
33 | continue
34 | }
35 |
36 | wordList.add(word)
37 | }
38 | } catch (e: Exception) {
39 | Log.e(TAG, "Caught: " + e.message, e)
40 | }
41 |
42 | // Log.i(TAG, "loadList: returning ${wordList.size} words")
43 | return wordList
44 | }
45 |
46 | fun loadMap(application: Application): Map> {
47 | Log.d(TAG, "loadMap() called with: application = [$application]")
48 | val wordMapList: MutableMap> = HashMap()
49 | try {
50 | val assets = Assets(application)
51 | val assetsDir = assets.syncAssets()
52 | val open = application.assets.open(assetsDir.name + "/models/lm/words.dic")
53 | val reader = BufferedReader(InputStreamReader(open))
54 |
55 | // do reading, usually loop until end of file reading
56 | var line: String
57 | while (reader.readLine().also { line = it } != null) {
58 | //process line
59 | val firstWord = line.substring(0, line.indexOf(' '))
60 | val indexOfParenthesis = line.indexOf('(')
61 | if (indexOfParenthesis > 0) {
62 | Log.i(TAG, "Adding secondary pronunciation: $line")
63 | val firstWordKey = line.substring(0, indexOfParenthesis)
64 | val strings = wordMapList[firstWordKey]
65 | if (strings != null) {
66 | strings.add(firstWord)
67 | wordMapList[firstWordKey] = strings
68 | }
69 | continue
70 | }
71 | val strings: MutableList = ArrayList()
72 | strings.add(firstWord)
73 | wordMapList[firstWord] = strings
74 | }
75 | } catch (e: IOException) {
76 | Log.e(TAG, "Caught: " + e.message, e)
77 | }
78 | return wordMapList
79 | }
80 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/ListenerFragment.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.os.Bundle
4 | import android.util.Log
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.ArrayAdapter
9 | import android.widget.SeekBar
10 | import android.widget.SeekBar.OnSeekBarChangeListener
11 | import androidx.annotation.IntDef
12 | import androidx.databinding.DataBindingUtil
13 | import androidx.fragment.app.Fragment
14 | import androidx.lifecycle.ViewModelProvider
15 | import com.tuckercr.zamzam.databinding.ListenerFragmentBinding
16 |
17 | class ListenerFragment : Fragment() {
18 | private lateinit var mViewModel: ListenerViewModel
19 | private lateinit var mBinding: ListenerFragmentBinding
20 | override fun onCreateView(
21 | inflater: LayoutInflater, container: ViewGroup?,
22 | savedInstanceState: Bundle?
23 | ): View {
24 | mViewModel = ViewModelProvider(requireActivity()).get(ListenerViewModel::class.java)
25 | mBinding = DataBindingUtil.inflate(
26 | inflater, R.layout.listener_fragment,
27 | container, false
28 | )
29 | mBinding.lifecycleOwner = activity
30 | mBinding.viewModel = mViewModel
31 | return mBinding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 | mViewModel.dictionaryList.observe(requireActivity(), { list: List? ->
37 | if (list == null) {
38 | Log.e(TAG, "onViewCreated: list is null")
39 | val arrayAdapter = ArrayAdapter(
40 | requireActivity(),
41 | android.R.layout.simple_spinner_item, arrayOf(mViewModel.wakeWord.get())
42 | )
43 | mBinding.wakeWordSpinner.adapter = arrayAdapter
44 | mBinding.wakeWordSpinner.setSelection(0)
45 | return@observe
46 | }
47 | // if (activity == null) {
48 | // Log.e(TAG, "onViewCreated: activity null")
49 | // return@observe
50 | // }
51 |
52 | // Create a new adapter
53 | val arrayAdapter = ArrayAdapter(
54 | requireActivity(),
55 | android.R.layout.simple_spinner_item, list
56 | )
57 | arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
58 | mBinding.wakeWordSpinner.adapter = arrayAdapter
59 | // mBinding.wakeWordSpinner.item = list
60 |
61 | // FIXME even with animate=false, this takes forever to scroll. Also there's a bug
62 | // in the library that means it crashes if you begin searching while scrolling.
63 |
64 | // FIXME pt2 - if you uncomment this the spinner doesn't show the wake word
65 | mBinding.wakeWordSpinner.setSelection(list.indexOf(mViewModel.wakeWord.get()), false)
66 | })
67 | mBinding.seekbar.progress = mViewModel.sensitivity.get()
68 | mBinding.seekbar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
69 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
70 | // Updating here causes us to repeatedly rebuild the recognizer
71 | }
72 |
73 | override fun onStartTrackingTouch(seekBar: SeekBar) {
74 | // Not required
75 | }
76 |
77 | override fun onStopTrackingTouch(seekBar: SeekBar) {
78 | val progress = seekBar.progress
79 | Log.i(TAG, "onStopTrackingTouch: $progress")
80 | mViewModel.setSensitivity(progress)
81 | }
82 | })
83 | }
84 |
85 | @Retention(AnnotationRetention.SOURCE)
86 | @IntDef(MicState.DISABLED_NO_PERMISSION, MicState.LISTENING, MicState.SPEAKING, MicState.OFF)
87 | annotation class MicState {
88 | companion object {
89 | const val DISABLED_NO_PERMISSION = 0
90 | const val LISTENING = 1
91 | const val SPEAKING = 2
92 | const val OFF: Int = 3
93 | }
94 | }
95 |
96 | companion object {
97 | const val FTAG = "ListenerFragment"
98 | private const val TAG = "ListenerFragment"
99 | fun newInstance(): ListenerFragment {
100 | return ListenerFragment()
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/NotificationUtils.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.app.Notification
4 | import android.app.NotificationChannel
5 | import android.app.NotificationManager
6 | import android.app.PendingIntent
7 | import android.content.Context
8 | import android.content.Intent
9 | import android.graphics.Color
10 | import android.os.Build
11 | import androidx.core.app.NotificationCompat
12 |
13 | /**
14 | * Notification helper methods
15 | *
16 | * @author colintucker
17 | */
18 | internal object NotificationUtils {
19 | private const val TAG = "NotificationUtils"
20 | private const val CHANNEL_ID_HOT_WORD = "hot_word_channel_id"
21 | private const val CHANNEL_ID_SERVICE = "main_channel_id"
22 | const val NOTIFICATION_ID_SERVICE = 42
23 | const val NOTIFICATION_ID_HOT_WORD = 43
24 | val VIBRATION_PATTERN = longArrayOf(0, 1000, 500, 1000, 500)
25 | fun initChannels(context: Context) {
26 | if (Build.VERSION.SDK_INT < 26) {
27 | return
28 | }
29 | val notificationManager =
30 | context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
31 |
32 | // TODO we could have a custom sound
33 | // Uri alertSoundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.xxxxxxxx);
34 | // AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
35 |
36 | // The alert channel is for ongoing notifications
37 | val mainChannel = NotificationChannel(
38 | CHANNEL_ID_SERVICE,
39 | context.getString(R.string.channel_name_service), NotificationManager.IMPORTANCE_HIGH
40 | )
41 | mainChannel.description = context.getString(R.string.channel_desc_service)
42 | // mainChannel.setSound(alertSoundUri, audioAttributes);
43 | mainChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
44 | notificationManager.createNotificationChannel(mainChannel)
45 |
46 | // The alert channel is for hot word detection notifications
47 | val hotWordChannel = NotificationChannel(
48 | CHANNEL_ID_HOT_WORD,
49 | context.getString(R.string.channel_name_hotword), NotificationManager.IMPORTANCE_HIGH
50 | )
51 | hotWordChannel.description = context.getString(R.string.channel_desc_hotword)
52 | hotWordChannel.enableLights(true)
53 | hotWordChannel.lightColor = Color.RED
54 | hotWordChannel.enableVibration(true)
55 | hotWordChannel.vibrationPattern = VIBRATION_PATTERN
56 | hotWordChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
57 | notificationManager.createNotificationChannel(hotWordChannel)
58 | }
59 |
60 | /**
61 | * Creates the running service notification
62 | */
63 | fun createServiceNotification(context: Context, wakeWord: String): Notification {
64 | initChannels(context)
65 | val intent = Intent(context, HotWordActivity::class.java)
66 | val pendingIntent = PendingIntent.getActivity(
67 | context, 0,
68 | intent, PendingIntent.FLAG_UPDATE_CURRENT
69 | )
70 | val notificationBuilder = NotificationCompat.Builder(context, CHANNEL_ID_SERVICE)
71 | .setSmallIcon(R.drawable.ic_stat_hearing)
72 | .setOngoing(true)
73 | .setContentTitle(context.getString(R.string.listening_for_hotword) + " \"" + wakeWord + "\"")
74 | .setContentText(context.getString(R.string.the_test_app_is_still_running))
75 | .setPriority(NotificationCompat.PRIORITY_HIGH)
76 | .setCategory(NotificationCompat.CATEGORY_SERVICE) //.setFullScreenIntent(pendingIntent, true);
77 | .setContentIntent(pendingIntent)
78 | return notificationBuilder.build()
79 | }
80 |
81 | fun createHotWordNotification(context: Context): Notification {
82 | val intent = Intent(context, HotWordActivity::class.java)
83 | intent.putExtra(HotWordActivity.EXTRA_OPEN_HOT_WORD_DETECTED, true)
84 | val pendingIntent = PendingIntent.getActivity(
85 | context, 0,
86 | intent, PendingIntent.FLAG_UPDATE_CURRENT
87 | )
88 | val notificationBuilder = NotificationCompat.Builder(context, CHANNEL_ID_HOT_WORD)
89 | .setSmallIcon(R.drawable.ic_stat_hearing)
90 | .setOngoing(true)
91 | .setAutoCancel(true)
92 | .setContentTitle(context.getString(R.string.hotword_detected))
93 | .setContentText(context.getString(R.string.the_hotword_was_heard_click_to_return_to_test_app))
94 | .setPriority(NotificationCompat.PRIORITY_HIGH) // .setFullScreenIntent(pendingIntent, true);
95 | .setContentIntent(pendingIntent)
96 | return notificationBuilder.build()
97 | }
98 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/listener_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
26 |
27 |
40 |
41 |
54 |
55 |
67 |
68 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
111 |
112 |
113 |
128 |
129 |
130 |
136 |
137 |
143 |
144 |
145 |
146 |
147 |
148 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tuckercr/zamzam/ListenerViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.tuckercr.zamzam
2 |
3 | import android.Manifest
4 | import android.app.Application
5 | import android.content.SharedPreferences
6 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener
7 | import android.content.pm.PackageManager
8 | import android.text.TextUtils
9 | import android.util.Log
10 | import androidx.core.content.ContextCompat
11 | import androidx.databinding.ObservableField
12 | import androidx.databinding.ObservableInt
13 | import androidx.lifecycle.AndroidViewModel
14 | import androidx.lifecycle.LiveData
15 | import androidx.lifecycle.MutableLiveData
16 | import com.tuckercr.zamzam.ListenerFragment.MicState
17 | import com.tuckercr.zamzam.prefs.PrefsManager
18 | import com.tuckercr.zamzam.prefs.PrefsManager.Companion.instance
19 | import edu.cmu.pocketsphinx.*
20 | import java.io.File
21 | import java.io.IOException
22 | import java.util.concurrent.Executors
23 |
24 | class ListenerViewModel(application: Application) : AndroidViewModel(application),
25 | OnSharedPreferenceChangeListener {
26 | private var mIsInitialized = false
27 | val sensitivity = ObservableInt(DEFAULT_SENSITIVITY)
28 | val sensitivityAsString = ObservableField(DEFAULT_SENSITIVITY.toString())
29 | val micState: ObservableInt = ObservableInt(MicState.OFF)
30 | val wakeWordTriggered = ObservableField()
31 | val wakeWord = ObservableField(
32 | instance!!.getString(
33 | PrefsManager.KEY_WAKE_WORD,
34 | getApplication().getString(R.string.default_wake_word)
35 | )
36 | )
37 | var recognizer: SpeechRecognizer? = null
38 | private set
39 | private var mDictionaryMap: MutableLiveData