├── settings.gradle
├── app
├── proguard.cfg
├── src
│ └── main
│ │ ├── ic_launcher-playstore.png
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── styles.xml
│ │ │ ├── bools.xml
│ │ │ ├── keys.xml
│ │ │ ├── defaults.xml
│ │ │ └── strings.xml
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── xml
│ │ │ ├── recognition_service_ws.xml
│ │ │ ├── locales_config.xml
│ │ │ └── preferences_server_ws.xml
│ │ ├── layout
│ │ │ ├── list_item_server_ip.xml
│ │ │ ├── about.xml
│ │ │ └── recognition_service_ws_url.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ └── ic_launcher.xml
│ │ ├── drawable
│ │ │ ├── ic_menu_info.xml
│ │ │ ├── ic_menu_help.xml
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── menu
│ │ │ └── preferences_header.xml
│ │ ├── values-et
│ │ │ └── strings.xml
│ │ └── layout-watch
│ │ │ └── recognition_service_ws_url.xml
│ │ ├── java
│ │ └── ee
│ │ │ └── ioc
│ │ │ └── phon
│ │ │ └── android
│ │ │ └── k6neleservice
│ │ │ ├── activity
│ │ │ ├── AboutActivity.kt
│ │ │ ├── PreferencesRecognitionServiceWs.java
│ │ │ └── RecognitionServiceWsUrlActivity.java
│ │ │ ├── Log.kt
│ │ │ ├── utils
│ │ │ ├── Utils.kt
│ │ │ └── QueryUtils.java
│ │ │ ├── receiver
│ │ │ └── GetLanguageDetailsReceiver.kt
│ │ │ ├── Caller.java
│ │ │ ├── service
│ │ │ ├── WebSocketResponse.java
│ │ │ └── WebSocketRecognitionService.java
│ │ │ └── ChunkedWebRecSessionBuilder.java
│ │ └── AndroidManifest.xml
└── build.gradle
├── .gitmodules
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── docs
└── server
│ ├── start.sh
│ ├── pip_freeze.txt
│ └── README.md
├── .github
└── workflows
│ └── android.yml
├── privacy_policy.rst
├── README.md
├── gradlew
└── LICENSE.txt
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':speechutils:app'
2 |
--------------------------------------------------------------------------------
/app/proguard.cfg:
--------------------------------------------------------------------------------
1 | -printconfiguration r8-config.txt
2 | -printusage usage.txt
3 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "speechutils"]
2 | path = speechutils
3 | url = git@github.com:Kaljurand/speechutils.git
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kaljurand/K6nele-service/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kaljurand/K6nele-service/HEAD/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kaljurand/K6nele-service/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kaljurand/K6nele-service/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kaljurand/K6nele-service/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kaljurand/K6nele-service/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
](https://play.google.com/store/apps/details?id=ee.ioc.phon.android.k6neleservice)
11 |
12 | Building the APK from source
13 | ----------------------------
14 |
15 | Clone the source code including the `speechutils` submodule:
16 |
17 | git clone --recursive git@github.com:Kaljurand/K6nele-service.git
18 |
19 |
20 | Point to the Android SDK directory by setting the environment variable
21 | `ANDROID_HOME`, e.g.
22 |
23 | ANDROID_HOME=${HOME}/myapps/android-sdk/
24 |
25 | In order to change your build environment create the file `gradle.properties`
26 | at a location pointed to by the environment variable `GRADLE_USER_HOME`.
27 | This will extend and override the definitions found in the `gradle.properties`
28 | that is part of the release.
29 |
30 | Build the app
31 |
32 | ./gradlew assemble
33 |
34 | If you have access to a release keystore then add these lines to the extended `gradle.properties`:
35 |
36 | storeFilename=
37 | storePassword=application/x-www-form-urlencoded
79 | * list of parameters in an HTTP PUT or HTTP POST.
80 | *
81 | * Modification of org.apache.http.client.utils.URLEncodedUtils#format
82 | *
83 | * @param parameters The parameters to include.
84 | * @param encoding The encoding to use.
85 | */
86 | public static String encodeKeyValuePairs(
87 | final ListDescription of the caller that receives the transcription. 27 | * If the extras specify a pending intent (I've never encountered such an app though), 28 | * then the pending intent's target package's name is returned.
29 | * 30 | *Otherwise we use EXTRA_CALLING_PACKAGE because there does not seem to be a way to 31 | * find out which Activity called us, i.e. this does not work:
32 | * 33 | *
34 | * ComponentName callingActivity = getCallingActivity();
35 | * if (callingActivity != null) {
36 | * return callingActivity.getPackageName();
37 | * }
38 | *
39 | *
40 | * The above tries to detect the "primary caller" (e.g. a keyboard app). We also
41 | * look for the "secondary caller" (e.g. an app in which the keyboard is used).
42 | * by parsing the extras looking for another package name, e.g. included in the
43 | * android.speech.extras.RECOGNITION_CONTEXT extra which some keyboard
44 | * apps set.
The caller description can be obtained in two ways. First a string in the form 47 | * "1st-caller/2nd-caller" which can be used as a User-Agent string. Examples:
48 | * 49 | *Secondly, we try to determine which caller string is more informative so 57 | * that it can be used in the Apps-database, for counting, and server/grammar assignment. 58 | * There should be no difference in terms of grammar assigning if speech recognition 59 | * in the app is used via the keyboard or via a dedicated speech input button.
60 | */ 61 | public class Caller { 62 | 63 | private static final String KEY_PACKAGE_NAME = "packageName"; 64 | 65 | private final String mPrimaryCaller; 66 | private final String mSecondaryCaller; 67 | 68 | public Caller(PendingIntent pendingIntent, Bundle bundle) { 69 | if (pendingIntent == null) { 70 | mPrimaryCaller = bundle.getString(RecognizerIntent.EXTRA_CALLING_PACKAGE); 71 | } else { 72 | mPrimaryCaller = pendingIntent.getTargetPackage(); 73 | } 74 | mSecondaryCaller = getPackageName(bundle); 75 | } 76 | 77 | 78 | public String getActualCaller() { 79 | if (mSecondaryCaller == null) { 80 | if (mPrimaryCaller == null) { 81 | return "null"; 82 | } 83 | return mPrimaryCaller; 84 | } 85 | return mSecondaryCaller; 86 | } 87 | 88 | 89 | public String toString() { 90 | return mPrimaryCaller + "/" + mSecondaryCaller; 91 | } 92 | 93 | 94 | /** 95 | *Traverses the given bundle (which can contain other bundles) 96 | * looking for the key "packageName". 97 | * Returns its corresponding value if finds it.
98 | * 99 | * @param bundle bundle (e.g. intent extras) 100 | * @return package name possibly hidden deep into the given bundle 101 | */ 102 | private static String getPackageName(Bundle bundle) { 103 | Object obj = BundleUtils.getBundleValue(bundle, KEY_PACKAGE_NAME); 104 | if (obj instanceof String) { 105 | return (String) obj; 106 | } 107 | return null; 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/recognition_service_ws_url.xml: -------------------------------------------------------------------------------- 1 | 2 |
15 | * {"status": 9, "message": "No decoder available, try again later"}
16 | *
17 | * {"status": 0, "result": {"hypotheses": [{"transcript": "elas metsas..."}], "final": false}}
18 | * {"status": 0, "result": {"hypotheses": [{"transcript": "elas metsas..."}], "final": true}}
19 | *
20 | * {"status": 0, "adaptation_state": {"type": "string+gzip+base64", "value": "eJxlvcu7"}}
21 | *
22 | */
23 | public class WebSocketResponse {
24 |
25 | // Usually used when recognition results are sent.
26 | public static final int STATUS_SUCCESS = 0;
27 |
28 | // Audio contains a large portion of silence or non-speech.
29 | public static final int STATUS_NO_SPEECH = 1;
30 |
31 | // Recognition was aborted for some reason.
32 | public static final int STATUS_ABORTED = 2;
33 |
34 | // No valid frames found before end of stream.
35 | public static final int STATUS_NO_VALID_FRAMES = 5;
36 |
37 | // Used when all recognizer processes are currently in use and recognition cannot be performed.
38 | public static final int STATUS_NOT_AVAILABLE = 9;
39 |
40 | private final JSONObject mJson;
41 | private final int mStatus;
42 |
43 | public WebSocketResponse(String data) throws WebSocketResponseException {
44 | try {
45 | mJson = new JSONObject(data);
46 | mStatus = mJson.getInt("status");
47 | } catch (JSONException e) {
48 | throw new WebSocketResponseException(e);
49 | }
50 | }
51 |
52 | public int getStatus() {
53 | return mStatus;
54 | }
55 |
56 | public boolean isResult() {
57 | return mJson.has("result");
58 | }
59 |
60 |
61 | public Result parseResult() throws WebSocketResponseException {
62 | try {
63 | return new Result(mJson.getJSONObject("result"));
64 | } catch (JSONException e) {
65 | throw new WebSocketResponseException(e);
66 | }
67 | }
68 |
69 |
70 | public Message parseMessage() throws WebSocketResponseException {
71 | try {
72 | return new Message(mJson.getString("message"));
73 | } catch (JSONException e) {
74 | throw new WebSocketResponseException(e);
75 | }
76 | }
77 |
78 | public AdaptationState parseAdaptationState() throws WebSocketResponseException {
79 | try {
80 | return new AdaptationState(mJson.getJSONObject("adaptation_state"));
81 | } catch (JSONException e) {
82 | throw new WebSocketResponseException(e);
83 | }
84 | }
85 |
86 |
87 | public static class Result {
88 | private final JSONObject mResult;
89 |
90 | public Result(JSONObject result) throws JSONException {
91 | mResult = result;
92 | }
93 |
94 | // TODO: yield transcript and do pretty-printing in the client
95 | public ArrayListBuilds a query for the speech recognizer server combing information from various sources:
40 | * 41 | *Returns the package name of the app that receives the transcription,
157 | * or null if the package name could not be resolved.
If {@code EXTRA_MAX_RESULTS} was set (i.e. it is larger than 0) then we 173 | * pass it on to the server.
174 | *If it was not set then we check the type of the language model (this is an obligatory input parameter). 175 | * If the language model is unset (e.g. K6nele was launched via its own launcher icon), or 176 | * the model is "web search" (this is the case with some web browsers), then we ask the server 177 | * for several results. (TODO: this could be user-configurable.) 178 | * Otherwise we ask for just a single result.
179 | */ 180 | private static int makeNbest(Bundle extras) { 181 | int maxResults = extras.getInt(RecognizerIntent.EXTRA_MAX_RESULTS); 182 | if (maxResults <= 0) { 183 | String model = extras.getString(RecognizerIntent.EXTRA_LANGUAGE_MODEL); 184 | if (model == null || model.equals(RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH)) { 185 | return MAX_RESULTS; 186 | } else { 187 | return 1; 188 | } 189 | } 190 | return maxResults; 191 | } 192 | 193 | 194 | /** 195 | *We choose the input language, preferring the language specified in EXTRA_LANGUAGE, 196 | * if this is unspecified then we look into the bundle to see if "selectedLanguage" is set 197 | * (by an IME). If this is also unspecified then we return the current locale as required 198 | * by the Android specification: 199 | * {@link RecognizerIntent#EXTRA_LANGUAGE}
200 | * 201 | *202 | *206 | */ 207 | private String makeLang(Bundle extras) { 208 | String lang = extras.getString(RecognizerIntent.EXTRA_LANGUAGE); 209 | if (lang != null) { 210 | return lang; 211 | } 212 | 213 | // If EXTRA_LANGUAGE is not set but the bundle contains "selectedLanguage" (as is the case with some IMEs) 214 | // then use a value from the latter. 215 | Object selectedLanguage = BundleUtils.getBundleValue(extras, "selectedLanguage"); 216 | if (selectedLanguage != null) { 217 | return selectedLanguage.toString(); 218 | } 219 | 220 | return null; 221 | } 222 | } -------------------------------------------------------------------------------- /app/src/main/java/ee/ioc/phon/android/k6neleservice/activity/PreferencesRecognitionServiceWs.java: -------------------------------------------------------------------------------- 1 | package ee.ioc.phon.android.k6neleservice.activity; 2 | 3 | /* 4 | * Copyright 2011-2020, Institute of Cybernetics at Tallinn University of Technology 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | import android.Manifest; 20 | import android.app.Activity; 21 | import android.content.Intent; 22 | import android.content.SharedPreferences; 23 | import android.content.pm.PackageManager; 24 | import android.content.res.Resources; 25 | import android.net.Uri; 26 | import android.os.Bundle; 27 | import android.view.Menu; 28 | import android.view.MenuInflater; 29 | import android.view.MenuItem; 30 | import android.widget.Toast; 31 | 32 | import androidx.appcompat.app.AppCompatActivity; 33 | import androidx.core.app.ActivityCompat; 34 | import androidx.preference.EditTextPreference; 35 | import androidx.preference.Preference; 36 | import androidx.preference.PreferenceFragmentCompat; 37 | import androidx.preference.PreferenceManager; 38 | 39 | import ee.ioc.phon.android.k6neleservice.R; 40 | import ee.ioc.phon.android.speechutils.utils.PreferenceUtils; 41 | 42 | public class PreferencesRecognitionServiceWs extends AppCompatActivity { 43 | 44 | private static final int ACTIVITY_SELECT_SERVER_URL = 1; 45 | private static final int PERMISSION_REQUEST_RECORD_AUDIO = 1; 46 | 47 | private SettingsFragment mSettings; 48 | 49 | @Override 50 | protected void onCreate(Bundle savedInstanceState) { 51 | super.onCreate(savedInstanceState); 52 | mSettings = new SettingsFragment(); 53 | getSupportFragmentManager().beginTransaction() 54 | .replace(android.R.id.content, mSettings) 55 | .commit(); 56 | } 57 | 58 | @Override 59 | public void onStart() { 60 | super.onStart(); 61 | ActivityCompat.requestPermissions(PreferencesRecognitionServiceWs.this, 62 | new String[]{Manifest.permission.RECORD_AUDIO}, 63 | PERMISSION_REQUEST_RECORD_AUDIO); 64 | } 65 | 66 | @Override 67 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 68 | super.onActivityResult(requestCode, resultCode, data); 69 | if (resultCode != Activity.RESULT_OK) { 70 | return; 71 | } 72 | switch (requestCode) { 73 | case ACTIVITY_SELECT_SERVER_URL: 74 | Uri serverUri = data.getData(); 75 | if (serverUri == null) { 76 | toast(getString(R.string.errorFailedGetServerUrl)); 77 | } else { 78 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 79 | PreferenceUtils.putPrefString(prefs, getResources(), R.string.keyWsServer, serverUri.toString()); 80 | } 81 | break; 82 | default: 83 | break; 84 | } 85 | } 86 | 87 | @Override 88 | public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 89 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 90 | switch (requestCode) { 91 | case PERMISSION_REQUEST_RECORD_AUDIO: { 92 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 93 | mSettings.setSummary(R.string.keyAppInfo, getString(R.string.summaryAppInfo)); 94 | } else { 95 | // Permission not granted: explain the consequences and offer a link to the app settings 96 | mSettings.setSummary(R.string.keyAppInfo, getString(R.string.summaryAppInfo) + "\n\n" + getString(R.string.promptPermissionRationale)); 97 | } 98 | break; 99 | } 100 | default: { 101 | break; 102 | } 103 | } 104 | } 105 | 106 | @Override 107 | public boolean onCreateOptionsMenu(Menu menu) { 108 | // Inflate the menu items for use in the action bar 109 | MenuInflater inflater = getMenuInflater(); 110 | inflater.inflate(R.menu.preferences_header, menu); 111 | return super.onCreateOptionsMenu(menu); 112 | } 113 | 114 | @Override 115 | public boolean onOptionsItemSelected(MenuItem item) { 116 | switch (item.getItemId()) { 117 | case R.id.menuAbout: 118 | Intent searchIntent = new Intent(this, AboutActivity.class); 119 | startActivity(searchIntent); 120 | return true; 121 | case R.id.menuHelp: 122 | Intent view = new Intent(Intent.ACTION_VIEW); 123 | view.setData(Uri.parse(getString(R.string.urlDoc))); 124 | startActivity(view); 125 | return true; 126 | 127 | default: 128 | return super.onContextItemSelected(item); 129 | } 130 | } 131 | 132 | private void toast(String message) { 133 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); 134 | } 135 | 136 | public static class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { 137 | 138 | @Override 139 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 140 | setPreferencesFromResource(R.xml.preferences_server_ws, rootKey); 141 | } 142 | 143 | @Override 144 | public void onStart() { 145 | super.onStart(); 146 | setSummaries(getPreferenceScreen().getSharedPreferences(), getResources()); 147 | } 148 | 149 | @Override 150 | public void onResume() { 151 | super.onResume(); 152 | getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); 153 | Preference service = findPreference(getString(R.string.keyWsServer)); 154 | service.setOnPreferenceClickListener(preference -> { 155 | getActivity().startActivityForResult(preference.getIntent(), ACTIVITY_SELECT_SERVER_URL); 156 | return true; 157 | }); 158 | } 159 | 160 | @Override 161 | public void onPause() { 162 | super.onPause(); 163 | getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); 164 | } 165 | 166 | @Override 167 | public void onStop() { 168 | super.onStop(); 169 | } 170 | 171 | @Override 172 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 173 | Preference pref = findPreference(key); 174 | if (pref instanceof EditTextPreference) { 175 | EditTextPreference etp = (EditTextPreference) pref; 176 | pref.setSummary(etp.getText()); 177 | } 178 | } 179 | 180 | public void setSummary(int key, String text) { 181 | final Preference pref = findPreference(getString(key)); 182 | if (pref != null) { 183 | pref.setSummary(text); 184 | } 185 | } 186 | 187 | private void setSummaries(SharedPreferences prefs, Resources res) { 188 | int key = R.string.keyWsServer; 189 | Preference pref = findPreference(getString(key)); 190 | if (pref != null) { 191 | final String urlSpeech = PreferenceUtils.getPrefString(prefs, res, key, R.string.defaultWsServer); 192 | pref.setSummary(String.format(getString(R.string.summaryWsServer), urlSpeech)); 193 | } 194 | key = R.string.keyLocales; 195 | pref = findPreference(getString(key)); 196 | if (pref != null) { 197 | pref.setSummary(PreferenceUtils.getPrefString(prefs, res, key, R.string.defaultLocales)); 198 | } 199 | } 200 | } 201 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /app/src/main/java/ee/ioc/phon/android/k6neleservice/activity/RecognitionServiceWsUrlActivity.java: -------------------------------------------------------------------------------- 1 | package ee.ioc.phon.android.k6neleservice.activity; 2 | 3 | import android.content.Intent; 4 | import android.content.SharedPreferences; 5 | import android.net.Uri; 6 | import android.os.AsyncTask; 7 | import android.os.Bundle; 8 | import android.preference.PreferenceManager; 9 | import android.util.Pair; 10 | import android.view.LayoutInflater; 11 | import android.view.ViewGroup; 12 | import android.view.inputmethod.EditorInfo; 13 | import android.widget.Button; 14 | import android.widget.EditText; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import androidx.annotation.NonNull; 19 | import androidx.appcompat.app.AppCompatActivity; 20 | import androidx.recyclerview.widget.LinearLayoutManager; 21 | import androidx.recyclerview.widget.RecyclerView; 22 | 23 | import com.koushikdutta.async.http.AsyncHttpClient; 24 | import com.koushikdutta.async.http.WebSocket; 25 | 26 | import org.json.JSONException; 27 | import org.json.JSONObject; 28 | 29 | import java.io.IOException; 30 | import java.net.InetAddress; 31 | import java.net.NetworkInterface; 32 | import java.net.UnknownHostException; 33 | import java.util.ArrayList; 34 | import java.util.Collections; 35 | import java.util.List; 36 | 37 | import ee.ioc.phon.android.k6neleservice.Log; 38 | import ee.ioc.phon.android.k6neleservice.R; 39 | import ee.ioc.phon.android.speechutils.utils.PreferenceUtils; 40 | 41 | public class RecognitionServiceWsUrlActivity extends AppCompatActivity { 42 | 43 | private static final int TIMEOUT_PING = 100; 44 | private final ListOptional IETF language tag (as defined by BCP 47), for example "en-US". 203 | * This tag informs the recognizer to perform speech recognition in a 204 | * language different than the one set in the getDefault().
205 | *