Skip to content

Commit

Permalink
Fix bug in recognize settings realization, upgrade to sdk 30, disable…
Browse files Browse the repository at this point in the history
… unnecessary permissions
  • Loading branch information
uvlad7 committed Jun 5, 2021
1 parent 422082f commit 64efa22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import java.nio.file.Paths
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "by.surdoteam.surdo"
minSdkVersion 24
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "0.4.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="by.surdoteam.surdo">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- is't required since API 19 for app dirs like-->
<!-- Context.getExternalCacheDir() -> /storage/emulated/0/Android/data/by.surdoteam.surdo/cache -->
<!-- Context.getExternalFilesDir(String) /storage/emulated/0/Android/data/by.surdoteam.surdo/files/String -->
<!-- and our case-->
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:requestLegacyExternalStorage="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class RecognizeFragment extends Fragment implements RecognitionListener {
private static final String KEYPHRASE = "активировать";
/* Named searches allow to quickly reconfigure the decoder */
private static final String PHRASE_SEARCH = "phrase";
private static String grammar_name;
private SpeechRecognizer recognizer;
private Pattern splitter;
private int permissionCheck;
Expand Down Expand Up @@ -112,10 +113,10 @@ private void setupRecognizer(File assetsDir) throws IOException {
// of different kind and switch between them
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
int threshold = sharedPref.getInt("sensitivity_of_the_activation_phrase", 6);
String dict = sharedPref.getString("grammar_name", getString(R.string.grammar_name_default_value));
grammar_name = sharedPref.getString("grammar_name", getString(R.string.grammar_name_default_value));
SpeechRecognizerSetup setup = SpeechRecognizerSetup.defaultSetup()
.setAcousticModel(new File(assetsDir, "ru-ru-ptm"))
.setDictionary(new File(assetsDir, dict))
.setDictionary(new File(assetsDir, "car.dict"))
.setBoolean("-remove_noise", true)
.setSampleRate(8000)
.setKeywordThreshold((float) Math.pow(10, -threshold));
Expand All @@ -134,8 +135,7 @@ private void setupRecognizer(File assetsDir) throws IOException {

// Create keyword-activation search.
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);

File menuGrammar = new File(assetsDir, "car.gram");
File menuGrammar = new File(assetsDir, grammar_name);
Log.d("File", menuGrammar.getAbsolutePath());
StringBuilder sb = new StringBuilder("((?<=^| )(?:(?:");
for (int i = 0; i < arguments.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<string name="sensitivity_of_the_activation_phrase">Чувствительность</string>
<string name="sensitivity_of_the_activation_phrase_summary">Чувствительность распознавания активационной фразы</string>
<string name="grammar_name">Грамматика</string>
<string name="grammar_name_summary">Выбор грамматики, используемой для распознавания</string>
<string name="grammar_name_summary">Выбор грамматики, используемой для распознавания. "Long" означает возможность распознавания нескольких фраз подряд</string>
<string name="save_logs">Сохранять логи</string>
<string name="save_logs_summary">Активировать сохранение логов распознавания. Занимает много места на устройстве!</string>

Expand Down

0 comments on commit 64efa22

Please sign in to comment.