";
20 | }
21 | android.util.Log.i(LOG_TAG, msg);
22 | }
23 | }
24 | }
25 |
26 | public static void e(String msg) {
27 | if (DEBUG) android.util.Log.e(LOG_TAG, msg);
28 | }
29 |
30 | public static void i(String tag, String msg) {
31 | if (DEBUG) android.util.Log.i(tag, msg);
32 | }
33 |
34 | public static void e(String tag, String msg) {
35 | if (DEBUG) android.util.Log.e(tag, msg);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/MediaFormatFactory.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.annotation.TargetApi;
4 | import android.media.MediaFormat;
5 | import android.os.Build;
6 |
7 | public class MediaFormatFactory {
8 |
9 | // TODO: add mimes
10 | public enum Type {
11 | AAC, AMR, FLAC
12 | }
13 |
14 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
15 | public static MediaFormat createMediaFormat(Type type, int sampleRate) {
16 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
17 | MediaFormat format = new MediaFormat();
18 | // TODO: this causes a crash in MediaCodec.configure
19 | //format.setString(MediaFormat.KEY_FRAME_RATE, null);
20 | format.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);
21 | format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
22 | if (type == Type.AAC) {
23 | format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
24 | format.setInteger(MediaFormat.KEY_AAC_PROFILE, 2); // TODO: or 39?
25 | format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
26 | } else if (type == Type.FLAC) {
27 | //format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_FLAC); // API=21
28 | format.setString(MediaFormat.KEY_MIME, "audio/flac");
29 | format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
30 | //TODO: use another bit rate, does not seem to have effect always
31 | //format.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
32 | } else {
33 | format.setString(MediaFormat.KEY_MIME, "audio/amr-wb");
34 | format.setInteger(MediaFormat.KEY_BIT_RATE, 23050);
35 | }
36 | return format;
37 | }
38 | return null;
39 | }
40 |
41 | //final int kAACProfiles[] = {
42 | // 2 /* OMX_AUDIO_AACObjectLC */,
43 | // 5 /* OMX_AUDIO_AACObjectHE */,
44 | // 39 /* OMX_AUDIO_AACObjectELD */
45 | //};
46 |
47 | //if (kAACProfiles[k] == 5 && kSampleRates[i] < 22050) {
48 | // // Is this right? HE does not support sample rates < 22050Hz?
49 | // continue;
50 | //}
51 | // final int kSampleRates[] = {8000, 11025, 22050, 44100, 48000};
52 | // final int kBitRates[] = {64000, 128000};
53 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/RawAudioRecorder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2015, Institute of Cybernetics at Tallinn University of Technology
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ee.ioc.phon.android.speechutils;
18 |
19 | /**
20 | * Records raw audio using SpeechRecord and stores it into a byte array as
21 | *
22 | * - signed
23 | * - 16-bit
24 | * - native endian
25 | * - mono
26 | * - 16kHz (recommended, but a different sample rate can be specified in the constructor)
27 | *
28 | *
29 | * For example, the corresponding arecord
settings are
30 | *
31 | *
32 | * arecord --file-type raw --format=S16_LE --channels 1 --rate 16000
33 | * arecord --file-type raw --format=S16_BE --channels 1 --rate 16000 (possibly)
34 | *
35 | *
36 | * TODO: maybe use: ByteArrayOutputStream
37 | *
38 | * @author Kaarel Kaljurand
39 | */
40 | public class RawAudioRecorder extends AbstractAudioRecorder {
41 |
42 | /**
43 | * Instantiates a new recorder and sets the state to INITIALIZING.
44 | * In case of errors, no exception is thrown, but the state is set to ERROR.
45 | *
46 | * Android docs say: 44100Hz is currently the only rate that is guaranteed to work on all devices,
47 | * but other rates such as 22050, 16000, and 11025 may work on some devices.
48 | *
49 | * @param audioSource Identifier of the audio source (e.g. microphone)
50 | * @param sampleRate Sample rate (e.g. 16000)
51 | */
52 | public RawAudioRecorder(int audioSource, int sampleRate) {
53 | super(audioSource, sampleRate);
54 | try {
55 | int bufferSize = getBufferSize();
56 | int framePeriod = bufferSize / (2 * RESOLUTION_IN_BYTES * CHANNELS);
57 | createRecorder(audioSource, sampleRate, bufferSize);
58 | createBuffer(framePeriod);
59 | setState(State.READY);
60 | } catch (Exception e) {
61 | if (e.getMessage() == null) {
62 | handleError("Unknown error occurred while initializing recorder");
63 | } else {
64 | handleError(e.getMessage());
65 | }
66 | }
67 | }
68 |
69 |
70 | public RawAudioRecorder(int sampleRate) {
71 | this(DEFAULT_AUDIO_SOURCE, sampleRate);
72 | }
73 |
74 |
75 | public RawAudioRecorder() {
76 | this(DEFAULT_AUDIO_SOURCE, DEFAULT_SAMPLE_RATE);
77 | }
78 |
79 | public String getWsArgs() {
80 | return "?content-type=audio/x-raw,+layout=(string)interleaved,+rate=(int)" + getSampleRate() + ",+format=(string)S16LE,+channels=(int)1";
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/SpeechRecord.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.media.AudioFormat;
4 | import android.media.AudioRecord;
5 | import android.media.MediaRecorder;
6 | import android.media.audiofx.AcousticEchoCanceler;
7 | import android.media.audiofx.AutomaticGainControl;
8 | import android.media.audiofx.NoiseSuppressor;
9 | import android.os.Build;
10 |
11 | /**
12 | * The following takes effect only on Jelly Bean and higher.
13 | *
14 | * @author Kaarel Kaljurand
15 | */
16 | public class SpeechRecord extends AudioRecord {
17 |
18 | public SpeechRecord(int sampleRateInHz, int bufferSizeInBytes)
19 | throws IllegalArgumentException {
20 |
21 | this(
22 | MediaRecorder.AudioSource.VOICE_RECOGNITION,
23 | sampleRateInHz,
24 | AudioFormat.CHANNEL_IN_MONO,
25 | AudioFormat.ENCODING_PCM_16BIT,
26 | bufferSizeInBytes,
27 | false,
28 | false,
29 | false
30 | );
31 | }
32 |
33 |
34 | public SpeechRecord(int sampleRateInHz, int bufferSizeInBytes, boolean noise, boolean gain, boolean echo)
35 | throws IllegalArgumentException {
36 |
37 | this(
38 | MediaRecorder.AudioSource.VOICE_RECOGNITION,
39 | sampleRateInHz,
40 | AudioFormat.CHANNEL_IN_MONO,
41 | AudioFormat.ENCODING_PCM_16BIT,
42 | bufferSizeInBytes,
43 | noise,
44 | gain,
45 | echo
46 | );
47 | }
48 |
49 |
50 | // This is a copy of the AudioRecord constructor
51 | public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)
52 | throws IllegalArgumentException {
53 |
54 | this(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes, false, false, false);
55 | }
56 |
57 |
58 | public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes,
59 | boolean noise, boolean gain, boolean echo)
60 | throws IllegalArgumentException {
61 |
62 | super(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);
63 |
64 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
65 | Log.i("Trying to enhance audio because running on SDK " + Build.VERSION.SDK_INT);
66 |
67 | int audioSessionId = getAudioSessionId();
68 |
69 | if (noise) {
70 | if (NoiseSuppressor.create(audioSessionId) == null) {
71 | Log.i("NoiseSuppressor: failed");
72 | } else {
73 | Log.i("NoiseSuppressor: ON");
74 | }
75 | } else {
76 | Log.i("NoiseSuppressor: OFF");
77 | }
78 |
79 | if (gain) {
80 | if (AutomaticGainControl.create(audioSessionId) == null) {
81 | Log.i("AutomaticGainControl: failed");
82 | } else {
83 | Log.i("AutomaticGainControl: ON");
84 | }
85 | } else {
86 | Log.i("AutomaticGainControl: OFF");
87 | }
88 |
89 | if (echo) {
90 | if (AcousticEchoCanceler.create(audioSessionId) == null) {
91 | Log.i("AcousticEchoCanceler: failed");
92 | } else {
93 | Log.i("AcousticEchoCanceler: ON");
94 | }
95 | } else {
96 | Log.i("AcousticEchoCanceler: OFF");
97 | }
98 | }
99 | }
100 |
101 |
102 | public static boolean isNoiseSuppressorAvailable() {
103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
104 | return NoiseSuppressor.isAvailable();
105 | }
106 | return false;
107 | }
108 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/TtsLocaleMapper.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashMap;
6 | import java.util.List;
7 | import java.util.Locale;
8 | import java.util.Map;
9 |
10 | public class TtsLocaleMapper {
11 |
12 | private static final List SIMILAR_LOCALES_ET;
13 |
14 | static {
15 | List aListEt = new ArrayList();
16 | aListEt.add(new Locale("fi-FI"));
17 | aListEt.add(new Locale("es-ES"));
18 | SIMILAR_LOCALES_ET = Collections.unmodifiableList(aListEt);
19 | }
20 |
21 | private static final Map> SIMILAR_LOCALES;
22 |
23 | static {
24 | Map> aMap = new HashMap>();
25 | aMap.put(new Locale("et-EE"), SIMILAR_LOCALES_ET);
26 | SIMILAR_LOCALES = Collections.unmodifiableMap(aMap);
27 | }
28 |
29 | public static List getSimilarLocales(Locale locale) {
30 | return SIMILAR_LOCALES.get(locale);
31 | }
32 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/editor/Command.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils.editor;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Pair;
5 |
6 | import java.util.regex.Matcher;
7 | import java.util.regex.Pattern;
8 |
9 | public class Command {
10 | private final static String SEPARATOR = "___";
11 | private final Pattern mPattern;
12 | private final String mReplacement;
13 | private final String mId;
14 | private final String[] mArgs;
15 | private final String mArgsAsStr;
16 |
17 | /**
18 | * @param pattern regular expression with capturing groups
19 | * @param replacement replacement string for the matched substrings, typically empty in case of commands
20 | * @param id name of the command to execute, null if missing
21 | * @param args arguments of the command
22 | */
23 | public Command(Pattern pattern, String replacement, String id, String[] args) {
24 | mPattern = pattern;
25 | mReplacement = replacement;
26 | mId = id;
27 | if (args == null) {
28 | mArgs = new String[0];
29 | } else {
30 | mArgs = args;
31 | }
32 | mArgsAsStr = TextUtils.join(SEPARATOR, mArgs);
33 | }
34 |
35 | public Command(String pattern, String replacement, String id, String[] args) {
36 | this(Pattern.compile(pattern), replacement, id, args);
37 | }
38 |
39 | public String getId() {
40 | return mId;
41 | }
42 |
43 | public Pattern getPattern() {
44 | return mPattern;
45 | }
46 |
47 | public String getReplacement() {
48 | return mReplacement;
49 | }
50 |
51 | public String[] getArgs() {
52 | return mArgs;
53 | }
54 |
55 | private Matcher matcher(CharSequence str) {
56 | return mPattern.matcher(str);
57 | }
58 |
59 | public Pair match(CharSequence str) {
60 | Matcher m = matcher(str);
61 | if (m.matches()) {
62 | String newStr = m.replaceAll(mReplacement);
63 | String[] argsEvaluated = TextUtils.split(m.replaceAll(mArgsAsStr), SEPARATOR);
64 | return new Pair<>(newStr, argsEvaluated);
65 | }
66 | return null;
67 | }
68 |
69 | public String toString() {
70 | return mPattern + "/" + mReplacement + "/" + mId + "(" + mArgs + ")";
71 | }
72 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/editor/CommandEditor.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils.editor;
2 |
3 | /**
4 | * TODO: work in progress
5 | */
6 | public interface CommandEditor {
7 |
8 | boolean commitFinalResult(String str);
9 |
10 | boolean commitPartialResult(String str);
11 |
12 | // Moving between fields
13 |
14 | // Go to the previous field
15 | boolean goToPreviousField();
16 |
17 | // Go to the next field
18 | boolean goToNextField();
19 |
20 | // Moving around in the string
21 |
22 | // Go to the character at the given position
23 | boolean goToCharacterPosition(int pos);
24 |
25 | boolean select(String str);
26 |
27 | // Reset selection
28 | boolean reset();
29 |
30 | // Context menu actions
31 | boolean selectAll();
32 |
33 | boolean cut();
34 |
35 | boolean copy();
36 |
37 | boolean paste();
38 |
39 | // Editing
40 |
41 | boolean capitalize(String str);
42 |
43 | boolean addSpace();
44 |
45 | boolean addNewline();
46 |
47 | boolean deleteLeftWord();
48 |
49 | boolean delete(String str);
50 |
51 | boolean replace(String str1, String str2);
52 |
53 | /**
54 | * Performs the Search-action, e.g. to launch search on a searchbar.
55 | */
56 | boolean go();
57 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/editor/Constants.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils.editor;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashSet;
5 | import java.util.Set;
6 |
7 | public class Constants {
8 |
9 | public static final Set CHARACTERS_WS =
10 | new HashSet<>(Arrays.asList(new Character[]{' ', '\n', '\t'}));
11 |
12 | // Symbols that should not be preceded by space in a written text.
13 | public static final Set CHARACTERS_PUNCT =
14 | new HashSet<>(Arrays.asList(new Character[]{',', ':', ';', '.', '!', '?'}));
15 |
16 | // Symbols after which the next word should be capitalized.
17 | // We include ) because ;-) often finishes a sentence.
18 | public static final Set CHARACTERS_EOS =
19 | new HashSet<>(Arrays.asList(new Character[]{'.', '!', '?', ')'}));
20 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/java/ee/ioc/phon/android/speechutils/utils/PreferenceUtils.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils.utils;
2 |
3 | import android.content.SharedPreferences;
4 | import android.content.res.Resources;
5 |
6 | import java.util.Arrays;
7 | import java.util.Collections;
8 | import java.util.HashSet;
9 | import java.util.List;
10 | import java.util.Set;
11 | import java.util.UUID;
12 |
13 | public class PreferenceUtils {
14 |
15 | public static String getPrefString(SharedPreferences prefs, Resources res, int key, int defaultValue) {
16 | return prefs.getString(res.getString(key), res.getString(defaultValue));
17 | }
18 |
19 | public static String getPrefString(SharedPreferences prefs, Resources res, int key) {
20 | return prefs.getString(res.getString(key), null);
21 | }
22 |
23 | public static Set getPrefStringSet(SharedPreferences prefs, Resources res, int key) {
24 | return prefs.getStringSet(res.getString(key), Collections.emptySet());
25 | }
26 |
27 | public static Set getPrefStringSet(SharedPreferences prefs, Resources res, int key, int defaultValue) {
28 | return prefs.getStringSet(res.getString(key), getStringSetFromStringArray(res, defaultValue));
29 | }
30 |
31 | public static boolean getPrefBoolean(SharedPreferences prefs, Resources res, int key, int defaultValue) {
32 | return prefs.getBoolean(res.getString(key), res.getBoolean(defaultValue));
33 | }
34 |
35 | public static int getPrefInt(SharedPreferences prefs, Resources res, int key, int defaultValue) {
36 | return Integer.parseInt(getPrefString(prefs, res, key, defaultValue));
37 | }
38 |
39 | public static String getUniqueId(SharedPreferences settings) {
40 | String id = settings.getString("id", null);
41 | if (id == null) {
42 | id = UUID.randomUUID().toString();
43 | SharedPreferences.Editor editor = settings.edit();
44 | editor.putString("id", id);
45 | editor.apply();
46 | }
47 | return id;
48 | }
49 |
50 | public static Set getStringSetFromStringArray(Resources res, int key) {
51 | return new HashSet<>(Arrays.asList(res.getStringArray(key)));
52 | }
53 |
54 | public static List getStringListFromStringArray(Resources res, int key) {
55 | return Arrays.asList(res.getStringArray(key));
56 | }
57 |
58 | public static void putPrefString(SharedPreferences prefs, Resources res, int key, String value) {
59 | SharedPreferences.Editor editor = prefs.edit();
60 | editor.putString(res.getString(key), value);
61 | editor.apply();
62 | }
63 |
64 | public static void putPrefStringSet(SharedPreferences prefs, Resources res, int key, Set value) {
65 | SharedPreferences.Editor editor = prefs.edit();
66 | editor.putStringSet(res.getString(key), value);
67 | editor.apply();
68 | }
69 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/anim/fade_inout_inf.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic.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 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic_recording_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic_recording_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic_recording_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic_recording_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic_transcribing.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/button_mic_waiting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/drawable/ic_voice_search_api_material.xml:
--------------------------------------------------------------------------------
1 |
18 |
24 |
25 |
28 |
29 |
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/raw/error.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willblaschko/AlexaAndroid/88255b64d02f33448a04ab6e715a81012575da9f/libs/speechutils-master/app/src/main/res/raw/error.wav
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/raw/explore_begin.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willblaschko/AlexaAndroid/88255b64d02f33448a04ab6e715a81012575da9f/libs/speechutils-master/app/src/main/res/raw/explore_begin.ogg
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/raw/explore_end.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willblaschko/AlexaAndroid/88255b64d02f33448a04ab6e715a81012575da9f/libs/speechutils-master/app/src/main/res/raw/explore_end.ogg
--------------------------------------------------------------------------------
/libs/speechutils-master/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffffff
4 | #808080
5 |
6 |
7 | #11404040
8 | #ffcc00
9 | #996600
10 | #996600
11 | #ffcc00
12 | #ffcc00
13 | #ffcc00
14 | #ff4444
15 | #cc0000
16 | #c58be2
17 | #9933cc
18 | #424242
19 |
--------------------------------------------------------------------------------
/libs/speechutils-master/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:2.3.0'
7 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
8 | }
9 | }
10 |
11 | apply plugin: 'com.android.library'
12 |
13 |
14 | android {
15 | compileSdkVersion 24
16 | buildToolsVersion '25.0.0'
17 |
18 | defaultConfig {
19 | minSdkVersion 11
20 | targetSdkVersion 24
21 |
22 | }
23 |
24 | sourceSets {
25 | main {
26 | manifest.srcFile 'AndroidManifest.xml'
27 | java.srcDirs = ['src']
28 | resources.srcDirs = ['src']
29 | aidl.srcDirs = ['src']
30 | renderscript.srcDirs = ['src']
31 | res.srcDirs = ['res']
32 | assets.srcDirs = ['assets']
33 | }
34 |
35 | // Move the tests to tests/java, tests/res, etc...
36 | instrumentTest.setRoot('tests')
37 |
38 | // Move the build types to build-types/
39 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
40 | // This moves them out of them default location under src//... which would
41 | // conflict with src/ being used by the main source set.
42 | // Adding new build types or product flavors should be accompanied
43 | // by a similar customization.
44 | debug.setRoot('build-types/debug')
45 | release.setRoot('build-types/release')
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/anim/fade_inout_inf.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic.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 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic_recording_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic_recording_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic_recording_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic_recording_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic_transcribing.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/button_mic_waiting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/drawable/ic_voice_search_api_material.xml:
--------------------------------------------------------------------------------
1 |
18 |
24 |
25 |
28 |
29 |
--------------------------------------------------------------------------------
/libs/speechutils-master/res/raw/error.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willblaschko/AlexaAndroid/88255b64d02f33448a04ab6e715a81012575da9f/libs/speechutils-master/res/raw/error.wav
--------------------------------------------------------------------------------
/libs/speechutils-master/res/raw/explore_begin.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willblaschko/AlexaAndroid/88255b64d02f33448a04ab6e715a81012575da9f/libs/speechutils-master/res/raw/explore_begin.ogg
--------------------------------------------------------------------------------
/libs/speechutils-master/res/raw/explore_end.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willblaschko/AlexaAndroid/88255b64d02f33448a04ab6e715a81012575da9f/libs/speechutils-master/res/raw/explore_end.ogg
--------------------------------------------------------------------------------
/libs/speechutils-master/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffffff
4 | #808080
5 |
6 |
7 | #11404040
8 | #ffcc00
9 | #996600
10 | #996600
11 | #ffcc00
12 | #ffcc00
13 | #ffcc00
14 | #ff4444
15 | #cc0000
16 | #c58be2
17 | #9933cc
18 | #424242
19 |
--------------------------------------------------------------------------------
/libs/speechutils-master/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/AudioCue.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.content.Context;
4 | import android.media.AudioManager;
5 | import android.media.MediaPlayer;
6 | import android.os.SystemClock;
7 |
8 | // TODO: add a method that calls back when audio is finished
9 | public class AudioCue {
10 |
11 | private static final int DELAY_AFTER_START_BEEP = 200;
12 |
13 | private final Context mContext;
14 | private final int mStartSound;
15 | private final int mStopSound;
16 | private final int mErrorSound;
17 |
18 | public AudioCue(Context context) {
19 | mContext = context;
20 | mStartSound = R.raw.explore_begin;
21 | mStopSound = R.raw.explore_end;
22 | mErrorSound = R.raw.error;
23 | }
24 |
25 | public AudioCue(Context context, int startSound, int stopSound, int errorSound) {
26 | mContext = context;
27 | mStartSound = startSound;
28 | mStopSound = stopSound;
29 | mErrorSound = errorSound;
30 | }
31 |
32 | public void playStartSoundAndSleep() {
33 | if (playSound(mStartSound)) {
34 | SystemClock.sleep(DELAY_AFTER_START_BEEP);
35 | }
36 | }
37 |
38 |
39 | public void playStopSound() {
40 | playSound(mStopSound);
41 | }
42 |
43 |
44 | public void playErrorSound() {
45 | playSound(mErrorSound);
46 | }
47 |
48 |
49 | private boolean playSound(int sound) {
50 | MediaPlayer mp = MediaPlayer.create(mContext, sound);
51 | // create can return null, e.g. on Android Wear
52 | if (mp == null) {
53 | return false;
54 | }
55 | mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
56 | mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
57 | @Override
58 | public void onCompletion(MediaPlayer mp) {
59 | mp.release();
60 | }
61 | });
62 | mp.start();
63 | return true;
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/AudioPauser.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.content.Context;
4 | import android.media.AudioManager;
5 | import android.media.AudioManager.OnAudioFocusChangeListener;
6 |
7 | /**
8 | * Pauses the audio stream by requesting the audio focus and
9 | * muting the music stream.
10 | *
11 | * TODO: Test this is two interleaving instances of AudioPauser, e.g.
12 | * TTS starts playing and calls the AudioPauser, at the same time
13 | * the recognizer starts listening and also calls the AudioPauser.
14 | */
15 | public class AudioPauser {
16 |
17 | private final boolean mIsMuteStream;
18 | private final AudioManager mAudioManager;
19 | private final OnAudioFocusChangeListener mAfChangeListener;
20 | private int mCurrentVolume = 0;
21 | private boolean isPausing = false;
22 |
23 | public AudioPauser(Context context) {
24 | this(context, true);
25 | }
26 |
27 |
28 | public AudioPauser(Context context, boolean isMuteStream) {
29 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
30 | mIsMuteStream = isMuteStream;
31 |
32 | mAfChangeListener = new OnAudioFocusChangeListener() {
33 | public void onAudioFocusChange(int focusChange) {
34 | Log.i("onAudioFocusChange" + focusChange);
35 | }
36 | };
37 | }
38 |
39 |
40 | /**
41 | * Requests audio focus with the goal of pausing any existing audio player.
42 | * Additionally mutes the music stream, since some audio players might
43 | * ignore the focus request.
44 | * In other words, during the pause no sound will be heard,
45 | * but whether the audio resumes from the same position after the pause
46 | * depends on the audio player.
47 | */
48 | public void pause() {
49 | if (!isPausing) {
50 | int result = mAudioManager.requestAudioFocus(mAfChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
51 | if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
52 | Log.i("AUDIOFOCUS_REQUEST_GRANTED");
53 | }
54 |
55 | if (mIsMuteStream) {
56 | mCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
57 | if (mCurrentVolume > 0) {
58 | mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
59 | }
60 | }
61 | isPausing = true;
62 | }
63 | }
64 |
65 |
66 | /**
67 | * Abandons audio focus and restores the audio volume.
68 | */
69 | public void resume() {
70 | if (isPausing) {
71 | mAudioManager.abandonAudioFocus(mAfChangeListener);
72 | if (mIsMuteStream && mCurrentVolume > 0) {
73 | mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mCurrentVolume, 0);
74 | }
75 | isPausing = false;
76 | }
77 | }
78 |
79 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/AudioRecorder.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.media.MediaRecorder;
4 |
5 | public interface AudioRecorder {
6 | int DEFAULT_AUDIO_SOURCE = MediaRecorder.AudioSource.VOICE_RECOGNITION;
7 | int DEFAULT_SAMPLE_RATE = 16000;
8 | short RESOLUTION_IN_BYTES = 2;
9 | // Number of channels (MONO = 1, STEREO = 2)
10 | short CHANNELS = 1;
11 |
12 | String getWsArgs();
13 |
14 | State getState();
15 |
16 | byte[] consumeRecordingAndTruncate();
17 |
18 | byte[] consumeRecording();
19 |
20 | void start();
21 |
22 | float getRmsdb();
23 |
24 | void release();
25 |
26 | boolean isPausing();
27 |
28 | enum State {
29 | // recorder is ready, but not yet recording
30 | READY,
31 |
32 | // recorder recording
33 | RECORDING,
34 |
35 | // error occurred, reconstruction needed
36 | ERROR,
37 |
38 | // recorder stopped
39 | STOPPED
40 | }
41 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/Log.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import java.util.List;
4 |
5 | public class Log {
6 |
7 | public static final boolean DEBUG = BuildConfig.DEBUG;
8 |
9 | public static final String LOG_TAG = "speechutils";
10 |
11 | public static void i(String msg) {
12 | if (DEBUG) android.util.Log.i(LOG_TAG, msg);
13 | }
14 |
15 | public static void i(List msgs) {
16 | if (DEBUG) {
17 | for (String msg : msgs) {
18 | if (msg == null) {
19 | msg = "";
20 | }
21 | android.util.Log.i(LOG_TAG, msg);
22 | }
23 | }
24 | }
25 |
26 | public static void e(String msg) {
27 | if (DEBUG) android.util.Log.e(LOG_TAG, msg);
28 | }
29 |
30 | public static void i(String tag, String msg) {
31 | if (DEBUG) android.util.Log.i(tag, msg);
32 | }
33 |
34 | public static void e(String tag, String msg) {
35 | if (DEBUG) android.util.Log.e(tag, msg);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/MediaFormatFactory.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.annotation.TargetApi;
4 | import android.media.MediaFormat;
5 | import android.os.Build;
6 |
7 | public class MediaFormatFactory {
8 |
9 | // TODO: add mimes
10 | public enum Type {
11 | AAC, AMR, FLAC
12 | }
13 |
14 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
15 | public static MediaFormat createMediaFormat(Type type, int sampleRate) {
16 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
17 | MediaFormat format = new MediaFormat();
18 | // TODO: this causes a crash in MediaCodec.configure
19 | //format.setString(MediaFormat.KEY_FRAME_RATE, null);
20 | format.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);
21 | format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
22 | if (type == Type.AAC) {
23 | format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
24 | format.setInteger(MediaFormat.KEY_AAC_PROFILE, 2); // TODO: or 39?
25 | format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
26 | } else if (type == Type.FLAC) {
27 | //format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_FLAC); // API=21
28 | format.setString(MediaFormat.KEY_MIME, "audio/flac");
29 | format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
30 | //TODO: use another bit rate, does not seem to have effect always
31 | //format.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
32 | } else {
33 | format.setString(MediaFormat.KEY_MIME, "audio/amr-wb");
34 | format.setInteger(MediaFormat.KEY_BIT_RATE, 23050);
35 | }
36 | return format;
37 | }
38 | return null;
39 | }
40 |
41 | //final int kAACProfiles[] = {
42 | // 2 /* OMX_AUDIO_AACObjectLC */,
43 | // 5 /* OMX_AUDIO_AACObjectHE */,
44 | // 39 /* OMX_AUDIO_AACObjectELD */
45 | //};
46 |
47 | //if (kAACProfiles[k] == 5 && kSampleRates[i] < 22050) {
48 | // // Is this right? HE does not support sample rates < 22050Hz?
49 | // continue;
50 | //}
51 | // final int kSampleRates[] = {8000, 11025, 22050, 44100, 48000};
52 | // final int kBitRates[] = {64000, 128000};
53 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/RawAudioRecorder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011-2015, Institute of Cybernetics at Tallinn University of Technology
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ee.ioc.phon.android.speechutils;
18 |
19 | /**
20 | * Records raw audio using SpeechRecord and stores it into a byte array as
21 | *
22 | * - signed
23 | * - 16-bit
24 | * - native endian
25 | * - mono
26 | * - 16kHz (recommended, but a different sample rate can be specified in the constructor)
27 | *
28 | *
29 | * For example, the corresponding arecord
settings are
30 | *
31 | *
32 | * arecord --file-type raw --format=S16_LE --channels 1 --rate 16000
33 | * arecord --file-type raw --format=S16_BE --channels 1 --rate 16000 (possibly)
34 | *
35 | *
36 | * TODO: maybe use: ByteArrayOutputStream
37 | *
38 | * @author Kaarel Kaljurand
39 | */
40 | public class RawAudioRecorder extends AbstractAudioRecorder {
41 |
42 | /**
43 | * Instantiates a new recorder and sets the state to INITIALIZING.
44 | * In case of errors, no exception is thrown, but the state is set to ERROR.
45 | *
46 | * Android docs say: 44100Hz is currently the only rate that is guaranteed to work on all devices,
47 | * but other rates such as 22050, 16000, and 11025 may work on some devices.
48 | *
49 | * @param audioSource Identifier of the audio source (e.g. microphone)
50 | * @param sampleRate Sample rate (e.g. 16000)
51 | */
52 | public RawAudioRecorder(int audioSource, int sampleRate) {
53 | super(audioSource, sampleRate);
54 | try {
55 | int bufferSize = getBufferSize();
56 | int framePeriod = bufferSize / (2 * RESOLUTION_IN_BYTES * CHANNELS);
57 | createRecorder(audioSource, sampleRate, bufferSize);
58 | createBuffer(framePeriod);
59 | setState(State.READY);
60 | } catch (Exception e) {
61 | if (e.getMessage() == null) {
62 | handleError("Unknown error occurred while initializing recorder");
63 | } else {
64 | handleError(e.getMessage());
65 | }
66 | }
67 | }
68 |
69 |
70 | public RawAudioRecorder(int sampleRate) {
71 | this(DEFAULT_AUDIO_SOURCE, sampleRate);
72 | }
73 |
74 |
75 | public RawAudioRecorder() {
76 | this(DEFAULT_AUDIO_SOURCE, DEFAULT_SAMPLE_RATE);
77 | }
78 |
79 | public String getWsArgs() {
80 | return "?content-type=audio/x-raw,+layout=(string)interleaved,+rate=(int)" + getSampleRate() + ",+format=(string)S16LE,+channels=(int)1";
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/SpeechRecord.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import android.media.AudioFormat;
4 | import android.media.AudioRecord;
5 | import android.media.MediaRecorder;
6 | import android.media.audiofx.AcousticEchoCanceler;
7 | import android.media.audiofx.AutomaticGainControl;
8 | import android.media.audiofx.NoiseSuppressor;
9 | import android.os.Build;
10 |
11 | /**
12 | * The following takes effect only on Jelly Bean and higher.
13 | *
14 | * @author Kaarel Kaljurand
15 | */
16 | public class SpeechRecord extends AudioRecord {
17 |
18 | public SpeechRecord(int sampleRateInHz, int bufferSizeInBytes)
19 | throws IllegalArgumentException {
20 |
21 | this(
22 | MediaRecorder.AudioSource.VOICE_RECOGNITION,
23 | sampleRateInHz,
24 | AudioFormat.CHANNEL_IN_MONO,
25 | AudioFormat.ENCODING_PCM_16BIT,
26 | bufferSizeInBytes,
27 | false,
28 | false,
29 | false
30 | );
31 | }
32 |
33 |
34 | public SpeechRecord(int sampleRateInHz, int bufferSizeInBytes, boolean noise, boolean gain, boolean echo)
35 | throws IllegalArgumentException {
36 |
37 | this(
38 | MediaRecorder.AudioSource.VOICE_RECOGNITION,
39 | sampleRateInHz,
40 | AudioFormat.CHANNEL_IN_MONO,
41 | AudioFormat.ENCODING_PCM_16BIT,
42 | bufferSizeInBytes,
43 | noise,
44 | gain,
45 | echo
46 | );
47 | }
48 |
49 |
50 | // This is a copy of the AudioRecord constructor
51 | public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)
52 | throws IllegalArgumentException {
53 |
54 | this(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes, false, false, false);
55 | }
56 |
57 |
58 | public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes,
59 | boolean noise, boolean gain, boolean echo)
60 | throws IllegalArgumentException {
61 |
62 | super(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);
63 |
64 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
65 | Log.i("Trying to enhance audio because running on SDK " + Build.VERSION.SDK_INT);
66 |
67 | int audioSessionId = getAudioSessionId();
68 |
69 | if (noise) {
70 | if (NoiseSuppressor.create(audioSessionId) == null) {
71 | Log.i("NoiseSuppressor: failed");
72 | } else {
73 | Log.i("NoiseSuppressor: ON");
74 | }
75 | } else {
76 | Log.i("NoiseSuppressor: OFF");
77 | }
78 |
79 | if (gain) {
80 | if (AutomaticGainControl.create(audioSessionId) == null) {
81 | Log.i("AutomaticGainControl: failed");
82 | } else {
83 | Log.i("AutomaticGainControl: ON");
84 | }
85 | } else {
86 | Log.i("AutomaticGainControl: OFF");
87 | }
88 |
89 | if (echo) {
90 | if (AcousticEchoCanceler.create(audioSessionId) == null) {
91 | Log.i("AcousticEchoCanceler: failed");
92 | } else {
93 | Log.i("AcousticEchoCanceler: ON");
94 | }
95 | } else {
96 | Log.i("AcousticEchoCanceler: OFF");
97 | }
98 | }
99 | }
100 |
101 |
102 | public static boolean isNoiseSuppressorAvailable() {
103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
104 | return NoiseSuppressor.isAvailable();
105 | }
106 | return false;
107 | }
108 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/TtsLocaleMapper.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.HashMap;
6 | import java.util.List;
7 | import java.util.Locale;
8 | import java.util.Map;
9 |
10 | public class TtsLocaleMapper {
11 |
12 | private static final List SIMILAR_LOCALES_ET;
13 |
14 | static {
15 | List aListEt = new ArrayList();
16 | aListEt.add(new Locale("fi-FI"));
17 | aListEt.add(new Locale("es-ES"));
18 | SIMILAR_LOCALES_ET = Collections.unmodifiableList(aListEt);
19 | }
20 |
21 | private static final Map> SIMILAR_LOCALES;
22 |
23 | static {
24 | Map> aMap = new HashMap>();
25 | aMap.put(new Locale("et-EE"), SIMILAR_LOCALES_ET);
26 | SIMILAR_LOCALES = Collections.unmodifiableMap(aMap);
27 | }
28 |
29 | public static List getSimilarLocales(Locale locale) {
30 | return SIMILAR_LOCALES.get(locale);
31 | }
32 | }
--------------------------------------------------------------------------------
/libs/speechutils-master/src/ee/ioc/phon/android/speechutils/utils/PreferenceUtils.java:
--------------------------------------------------------------------------------
1 | package ee.ioc.phon.android.speechutils.utils;
2 |
3 | import android.content.SharedPreferences;
4 | import android.content.res.Resources;
5 |
6 | import java.util.Arrays;
7 | import java.util.Collections;
8 | import java.util.HashSet;
9 | import java.util.List;
10 | import java.util.Set;
11 | import java.util.UUID;
12 |
13 | public class PreferenceUtils {
14 |
15 | public static String getPrefString(SharedPreferences prefs, Resources res, int key, int defaultValue) {
16 | return prefs.getString(res.getString(key), res.getString(defaultValue));
17 | }
18 |
19 | public static String getPrefString(SharedPreferences prefs, Resources res, int key) {
20 | return prefs.getString(res.getString(key), null);
21 | }
22 |
23 | public static Set getPrefStringSet(SharedPreferences prefs, Resources res, int key) {
24 | return prefs.getStringSet(res.getString(key), Collections.emptySet());
25 | }
26 |
27 | public static Set getPrefStringSet(SharedPreferences prefs, Resources res, int key, int defaultValue) {
28 | return prefs.getStringSet(res.getString(key), getStringSetFromStringArray(res, defaultValue));
29 | }
30 |
31 | public static boolean getPrefBoolean(SharedPreferences prefs, Resources res, int key, int defaultValue) {
32 | return prefs.getBoolean(res.getString(key), res.getBoolean(defaultValue));
33 | }
34 |
35 | public static int getPrefInt(SharedPreferences prefs, Resources res, int key, int defaultValue) {
36 | return Integer.parseInt(getPrefString(prefs, res, key, defaultValue));
37 | }
38 |
39 | public static String getUniqueId(SharedPreferences settings) {
40 | String id = settings.getString("id", null);
41 | if (id == null) {
42 | id = UUID.randomUUID().toString();
43 | SharedPreferences.Editor editor = settings.edit();
44 | editor.putString("id", id);
45 | editor.apply();
46 | }
47 | return id;
48 | }
49 |
50 | public static Set getStringSetFromStringArray(Resources res, int key) {
51 | return new HashSet<>(Arrays.asList(res.getStringArray(key)));
52 | }
53 |
54 | public static List getStringListFromStringArray(Resources res, int key) {
55 | return Arrays.asList(res.getStringArray(key));
56 | }
57 |
58 | public static void putPrefString(SharedPreferences prefs, Resources res, int key, String value) {
59 | SharedPreferences.Editor editor = prefs.edit();
60 | editor.putString(res.getString(key), value);
61 | editor.apply();
62 | }
63 |
64 | public static void putPrefStringSet(SharedPreferences prefs, Resources res, int key, Set value) {
65 | SharedPreferences.Editor editor = prefs.edit();
66 | editor.putStringSet(res.getString(key), value);
67 | editor.apply();
68 | }
69 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app',
2 | ':libs:AlexaAndroid',
3 | ':libs:RecorderLevelView',
4 | ':libs:speechutils-master'
5 |
--------------------------------------------------------------------------------