Skip to content

Commit

Permalink
Movis al pako "dk.nordfalk.esperanto.parolrekono" kaj faris apartan b…
Browse files Browse the repository at this point in the history
…onvenigan ekranon
  • Loading branch information
nordfalk committed Jul 8, 2022
1 parent 8c74ea6 commit 1f31e23
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
}
compileSdkVersion 30
defaultConfig {
applicationId "cat.oreilly.localstt"
applicationId "dk.nordfalk.esperanto.parolrekono"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="cat.oreilly.localstt">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand All @@ -23,7 +24,7 @@
android:theme="@style/AppTheme">

<activity
android:name=".SpeechActivity"
android:name="dk.nordfalk.esperanto.parolrekono.SpeechActivity"
android:theme="@style/Theme.LocalSTT.Translucent">
<intent-filter>
<action android:name="android.speech.action.RECOGNIZE_SPEECH" />
Expand Down Expand Up @@ -87,19 +88,21 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
-->
</activity>
<activity
android:name="dk.nordfalk.esperanto.parolrekono.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

<service
android:name=".VoskRecognitionService"
android:process=":speechProcess"
android:icon="@drawable/ic_service_trigger"
android:label="@string/vosk_recognition_service"
android:label="@string/recognition_service_label"
android:description="@string/recognition_service_description"
android:permission="android.permission.RECORD_AUDIO">
<intent-filter>

Expand Down
155 changes: 155 additions & 0 deletions app/src/main/java/dk/nordfalk/esperanto/parolrekono/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright 2020 Ciaran O'Reilly
// Copyright 2011-2020, Institute of Cybernetics at Tallinn University of Technology
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package dk.nordfalk.esperanto.parolrekono;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import java.util.ArrayList;
import java.util.Locale;

import cat.oreilly.localstt.R;

public class MainActivity extends AppCompatActivity {
protected static final String TAG = MainActivity.class.getSimpleName();

public static final Integer RecordAudioRequestCode = 1;
private SpeechRecognizer speechRecognizer;
private EditText editText;

protected void toast(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.speech_activity);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
checkPermission();
}

editText = findViewById(R.id.editText);
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);

speechRecognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle bundle) {

}

@Override
public void onBeginningOfSpeech() {
editText.setText("");
editText.setHint(R.string.speaknow);
}

@Override
public void onRmsChanged(float v) {

}

@Override
public void onBufferReceived(byte[] bytes) {

}

@Override
public void onEndOfSpeech() {
speechRecognizer.stopListening();
}

@Override
public void onError(int error) {
Log.i(TAG, "onError "+error);
toast("Okazis eraro dum rekono ("+error+")");
}

@Override
public void onResults(Bundle bundle) {
Log.i(TAG, "onResults");
ArrayList<String> results = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
Log.i(TAG, results.toString());
editText.setText(results.get(0));
toast(String.format(getString(R.string.recognized), results.get(0)));
}

@Override
public void onPartialResults(Bundle bundle) {
Log.i(TAG, "onPartialResults");
ArrayList<String> results = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
Log.i(TAG, results.toString());
editText.setText(results.get(0));
}

@Override
public void onEvent(int i, Bundle bundle) {
Log.d(TAG, bundle.toString());
}
});

}

@Override
public void onStart() {
super.onStart();
Log.i(TAG, "onStart");
final Intent speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
speechRecognizer.startListening(speechRecognizerIntent);
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "onDestroy");
speechRecognizer.destroy();
}

private void checkPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO },
RecordAudioRequestCode);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == RecordAudioRequestCode && grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package cat.oreilly.localstt;
package dk.nordfalk.esperanto.parolrekono;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -42,6 +42,8 @@
import java.util.Locale;
import java.util.List;

import cat.oreilly.localstt.R;

public class SpeechActivity extends AppCompatActivity {
protected static final String TAG = SpeechActivity.class.getSimpleName();

Expand Down Expand Up @@ -104,7 +106,7 @@ protected void onCreate(final Bundle savedInstanceState) {
checkPermission();
}

editText = findViewById(R.id.text);
editText = findViewById(R.id.editText);
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);

speechRecognizer.setRecognitionListener(new RecognitionListener() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/speech_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SpeechActivity">
tools:context="dk.nordfalk.esperanto.parolrekono.SpeechActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_centerInParent="true"
Expand Down Expand Up @@ -34,7 +34,7 @@
android:hint="@string/loading"
android:textColorHint="@color/colorPrimaryDark"
android:textColor="@color/colorPrimary"
android:id="@+id/text"
android:id="@+id/editText"
android:layout_centerInParent="true"
/>
</LinearLayout>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Esperanto Parolrekono</string>
<string name="vosk_recognition_service">Esperanto parolrekona servo</string>
<string name="app_name">Esperanto parolrekono</string>
<string name="recognition_service_label">Esperanto parolrekona servo</string>
<string name="recognition_service_description">Parolrekono en Esperanto, bazita sur Vosk, farita de Jacob Nordfalk por la telegrama grupo \'Esperanto kaj Teĥniko\'</string>
<string name="recognized">Rekonis: %1$s</string>
<string name="loading">Pretiĝas...</string>
<string name="speaknow">Parolu nun!</string>
Expand Down

0 comments on commit 1f31e23

Please sign in to comment.