diff --git a/addin_recognizer/Inf18/AddInNative.cpp b/addin_recognizer/Inf18/AddInNative.cpp
index 4a976b9..9daa45e 100644
--- a/addin_recognizer/Inf18/AddInNative.cpp
+++ b/addin_recognizer/Inf18/AddInNative.cpp
@@ -20,6 +20,7 @@ static const wchar_t *g_MethodNames[] =
{
L"Delay",
L"StartSpeechRecognition",
+ L"StartEndlessSpeechRecognition",
L"StopSpeechRecognition",
L"PlaySoundAlert",
L"RequestServiceStatus"
@@ -30,6 +31,7 @@ static const wchar_t *g_MethodNamesRu[] =
{
L"Пауза",
L"ЗапуститьРаспознаваниеРечи",
+ L"ЗапуститьПостоянноеРаспознаваниеРечи",
L"ОстановитьРаспознаваниеРечи",
L"ВоспроизвестиЗвуковоеОповещение",
L"ЗапроситьСтатусСервиса"
@@ -373,6 +375,10 @@ bool AddInNative::CallAsProc(const long lMethodNum, tVariant* paParams, const lo
javaMainApp.startSpeechRecognition();
return true;
}
+ case eMethStartEndlessSpeechRecognition: {
+ javaMainApp.startEndlessSpeechRecognition();
+ return true;
+ }
case eMethStopSpeechRecognition: {
javaMainApp.stopSpeechRecognition();
return true;
diff --git a/addin_recognizer/Inf18/AddInNative.h b/addin_recognizer/Inf18/AddInNative.h
index 84639c2..f8f58fb 100644
--- a/addin_recognizer/Inf18/AddInNative.h
+++ b/addin_recognizer/Inf18/AddInNative.h
@@ -34,6 +34,7 @@ public:
{
eMethDelay = 0,
eMethStartSpeechRecognition,
+ eMethStartEndlessSpeechRecognition,
eMethStopSpeechRecognition,
eMethPlaySoundAlert,
eMethRequestServiceStatus,
diff --git a/addin_recognizer/Inf18/Inf18.vcxproj b/addin_recognizer/Inf18/Inf18.vcxproj
index 9d6e66d..ddee47c 100644
--- a/addin_recognizer/Inf18/Inf18.vcxproj
+++ b/addin_recognizer/Inf18/Inf18.vcxproj
@@ -102,7 +102,7 @@
DynamicLibrary
false
Gcc_4_9
- android-27
+ android-28
DynamicLibrary
@@ -134,7 +134,8 @@
DynamicLibrary
false
Gcc_4_9
- android-27
+ android-28
+ c++_shared
DynamicLibrary
diff --git a/addin_recognizer/Inf18/MainApp.cpp b/addin_recognizer/Inf18/MainApp.cpp
index c881274..aa644d1 100644
--- a/addin_recognizer/Inf18/MainApp.cpp
+++ b/addin_recognizer/Inf18/MainApp.cpp
@@ -63,6 +63,16 @@ void MainApp::startSpeechRecognition() const
}
}
+void MainApp::startEndlessSpeechRecognition() const
+{
+ if (obj)
+ {
+ JNIEnv* env = getJniEnv();
+ jmethodID methID = env->GetMethodID(cc, "startEndlessSpeechRecognition", "()V");
+ env->CallVoidMethod(obj, methID);
+ }
+}
+
void MainApp::stopSpeechRecognition() const
{
if (obj)
diff --git a/addin_recognizer/Inf18/MainApp.h b/addin_recognizer/Inf18/MainApp.h
index 41749e9..7171cca 100644
--- a/addin_recognizer/Inf18/MainApp.h
+++ b/addin_recognizer/Inf18/MainApp.h
@@ -24,6 +24,7 @@ public:
void Initialize(IAddInDefBaseEx*);
void startSpeechRecognition() const;
+ void startEndlessSpeechRecognition() const;
void stopSpeechRecognition() const;
void playSoundAlert() const;
void requestServiceStatus() const;
diff --git a/addin_recognizer/android/app/.cxx/ndk_locator_record.json b/addin_recognizer/android/app/.cxx/ndk_locator_record.json
index f77bc8b..f2fe1ab 100644
--- a/addin_recognizer/android/app/.cxx/ndk_locator_record.json
+++ b/addin_recognizer/android/app/.cxx/ndk_locator_record.json
@@ -1,5 +1,5 @@
{
- "ndkFolder": "C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\21.0.6113669",
+ "ndkFolder": "C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\20.1.5948944",
"messages": [
{
"level": "INFO",
@@ -23,7 +23,15 @@
},
{
"level": "INFO",
- "message": "Considering C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\21.0.6113669 in SDK ndk folder"
+ "message": "Considering C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\20.1.5948944 in SDK ndk folder"
+ },
+ {
+ "level": "INFO",
+ "message": "Considering C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\24.0.8215888 in SDK ndk folder"
+ },
+ {
+ "level": "INFO",
+ "message": "Considering C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\25.2.9519653 in SDK ndk folder"
},
{
"level": "INFO",
@@ -31,7 +39,15 @@
},
{
"level": "INFO",
- "message": "No user requested version, choosing C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\21.0.6113669 which is version 21.0.6113669"
+ "message": "Rejected C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\24.0.8215888 in SDK ndk folder because that location has no source.properties"
+ },
+ {
+ "level": "INFO",
+ "message": "Rejected C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\25.2.9519653 in SDK ndk folder because that location has no source.properties"
+ },
+ {
+ "level": "INFO",
+ "message": "No user requested version, choosing C:\\Users\\SM\\AppData\\Local\\Android\\Sdk\\ndk\\20.1.5948944 which is version 20.1.5948944"
}
]
}
\ No newline at end of file
diff --git a/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/Intents.java b/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/Intents.java
index 0fefb14..c30af87 100644
--- a/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/Intents.java
+++ b/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/Intents.java
@@ -7,8 +7,11 @@ public final class Intents {
// Outgoing intents
public static final String START_RECOGNIZER = "com.github.salexdv.speechrecognizer.START";
+ public static final String START_ENDLESS_RECOGNIZER = "com.github.salexdv.speechrecognizer.START_ENDLESS_RECOGNIZER";
public static final String STOP_RECOGNIZER = "com.github.salexdv.speechrecognizer.STOP";
public static final String STATUS_RECOGNIZER = "com.github.salexdv.speechrecognizer.STATUS";
+ public static final String PLAY_BEEP = "com.github.salexdv.speechrecognizer.BEEP";
+
// Incoming intents
public static final String RECOGNIZER_ONREADY = "com.github.salexdv.speechrecognizer.ON_READY";
public static final String RECOGNIZER_ONBEGIN = "com.github.salexdv.speechrecognizer.ON_BEGININIG";
diff --git a/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/MainApp.java b/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/MainApp.java
index 23b1072..038cb21 100644
--- a/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/MainApp.java
+++ b/addin_recognizer/android/app/src/main/java/com/github/salexdv/speechrecognizer/addin/MainApp.java
@@ -57,9 +57,7 @@ public class MainApp implements Runnable {
public void playSoundAlert() {
- Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- MediaPlayer mp = MediaPlayer.create(m_Activity.getApplicationContext(), notification);
- mp.start();
+ recognizerRequest(Intents.PLAY_BEEP);
}
@@ -81,8 +79,7 @@ public class MainApp implements Runnable {
}
- public void startSpeechRecognition()
- {
+ private void startRecognition(String startIntent) {
if (m_Receiver == null)
{
@@ -129,12 +126,26 @@ public class MainApp implements Runnable {
m_Activity.registerReceiver(m_Receiver, filter);
- recognizerRequest(Intents.START_RECOGNIZER);
+ recognizerRequest(startIntent);
}
}
+ public void startSpeechRecognition()
+ {
+
+ this.startRecognition(Intents.START_RECOGNIZER);
+
+ }
+
+ public void startEndlessSpeechRecognition()
+ {
+
+ this.startRecognition(Intents.START_ENDLESS_RECOGNIZER);
+
+ }
+
public void stopSpeechRecognition()
{
diff --git a/android_service_app/app/build.gradle b/android_service_app/app/build.gradle
index 8e7f771..74ba1bd 100644
--- a/android_service_app/app/build.gradle
+++ b/android_service_app/app/build.gradle
@@ -11,7 +11,7 @@ android {
minSdkVersion 28
targetSdkVersion 30
versionCode 1
- versionName "1.0"
+ versionName "1.1"
ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
archivesBaseName = "mobile1c_speechrecognizer"
diff --git a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/AudioController.java b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/AudioController.java
index 336ace5..074c9d7 100644
--- a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/AudioController.java
+++ b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/AudioController.java
@@ -7,11 +7,13 @@ public class AudioController {
private Context context;
private AudioManager audioManager;
+ private int streamVolume;
public AudioController (Context applicationContext) {
context = applicationContext;
audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
+ this.streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
}
@@ -20,6 +22,7 @@ public class AudioController {
audioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_MUTE, 0);
audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0);
audioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
+ audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_PLAY_SOUND);
}
@@ -28,6 +31,7 @@ public class AudioController {
audioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_UNMUTE, 0);
audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_UNMUTE, 0);
audioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_UNMUTE, 0);
+ audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, this.streamVolume, AudioManager.FLAG_PLAY_SOUND);
}
diff --git a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Intents.java b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Intents.java
index af276a7..4531de9 100644
--- a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Intents.java
+++ b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Intents.java
@@ -7,8 +7,10 @@ public final class Intents {
// Incoming intents
public static final String START_RECOGNIZER = "com.github.salexdv.speechrecognizer.START";
+ public static final String START_ENDLESS_RECOGNIZER = "com.github.salexdv.speechrecognizer.START_ENDLESS_RECOGNIZER";
public static final String STOP_RECOGNIZER = "com.github.salexdv.speechrecognizer.STOP";
public static final String STATUS_RECOGNIZER = "com.github.salexdv.speechrecognizer.STATUS";
+ public static final String PLAY_BEEP = "com.github.salexdv.speechrecognizer.BEEP";
// Outgoing intents
public static final String RECOGNIZER_ONREADY = "com.github.salexdv.speechrecognizer.ON_READY";
public static final String RECOGNIZER_ONBEGIN = "com.github.salexdv.speechrecognizer.ON_BEGININIG";
diff --git a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/MainActivity.java b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/MainActivity.java
index fb8f67e..8f494f9 100644
--- a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/MainActivity.java
+++ b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/MainActivity.java
@@ -191,7 +191,7 @@ public class MainActivity extends AppCompatActivity {
((Button)findViewById(R.id.testService)).setText(R.string.stop_test);
- sendRequest(Intents.START_RECOGNIZER);
+ sendRequest(Intents.START_ENDLESS_RECOGNIZER);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
diff --git a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/RecService.java b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/RecService.java
index 8f8111e..54fb052 100644
--- a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/RecService.java
+++ b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/RecService.java
@@ -82,8 +82,13 @@ public class RecService extends Service {
switch (intent.getAction())
{
case Intents.START_RECOGNIZER:
+ case Intents.START_ENDLESS_RECOGNIZER:_RECOGNIZER:
try {
if (SpeechRecognizer.isRecognitionAvailable(context)) {
+ if (intent.getAction() == Intents.START_ENDLESS_RECOGNIZER)
+ recognizer.enableEndlessRecognition();
+ else
+ recognizer.disableEndlessRecognition();
recognizer.start();
}
else {
@@ -106,6 +111,8 @@ public class RecService extends Service {
Log.d(recognizerTAG, status);
sendResponce(Intents.RECOGNIZER_STATUS, status);
break;
+ case Intents.PLAY_BEEP:
+ recognizer.beep();
default:
break;
}
@@ -116,8 +123,10 @@ public class RecService extends Service {
IntentFilter filter = new IntentFilter();
filter.addAction(Intents.START_RECOGNIZER);
+ filter.addAction(Intents.START_ENDLESS_RECOGNIZER);
filter.addAction(Intents.STOP_RECOGNIZER);
filter.addAction(Intents.STATUS_RECOGNIZER);
+ filter.addAction(Intents.PLAY_BEEP);
registerReceiver(receiver, filter);
return START_NOT_STICKY;
diff --git a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Recognizer.java b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Recognizer.java
index 7acc0e0..0aa88a7 100644
--- a/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Recognizer.java
+++ b/android_service_app/app/src/main/java/com/github/salexdv/speechrecognizer/android_service/Recognizer.java
@@ -1,6 +1,7 @@
package com.github.salexdv.speechrecognizer.android_service;
import android.content.Intent;
+import android.media.MediaPlayer;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
@@ -15,6 +16,7 @@ public class Recognizer implements RecognitionListener {
private String recognizerTAG;
private SpeechRecognizer recognizer;
private boolean recStarted;
+ private boolean endlessRecognition;
private Intent speechRecognizerIntent;
private Context context;
private AudioController audioController;
@@ -28,6 +30,12 @@ public class Recognizer implements RecognitionListener {
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.EXTRA_LANGUAGE_MODEL);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
+ speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, true);
+
+ Long voiceTimeout = new Long(15000);
+ speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, voiceTimeout);
+ speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, voiceTimeout);
+ speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,voiceTimeout);
audioController = new AudioController(context);
@@ -68,7 +76,8 @@ public class Recognizer implements RecognitionListener {
Log.d(recognizerTAG, error);
recognizer.destroy();
sendResponse(Intents.RECOGNIZER_ERROR, error);
- start();
+ if (this.endlessRecognition)
+ start();
}
}
@@ -79,7 +88,8 @@ public class Recognizer implements RecognitionListener {
Log.d(recognizerTAG, "onResults (" + recognitionResult + ")");
sendResponse(Intents.RECOGNIZER_RESULT, recognitionResult);
recognizer.destroy();
- start();
+ if (this.endlessRecognition)
+ start();
}
@Override
@@ -105,6 +115,18 @@ public class Recognizer implements RecognitionListener {
}
+ public void enableEndlessRecognition() {
+
+ this.endlessRecognition = true;
+
+ }
+
+ public void disableEndlessRecognition() {
+
+ this.endlessRecognition = false;
+
+ }
+
public void start() {
audioController.mute();
@@ -119,7 +141,6 @@ public class Recognizer implements RecognitionListener {
public void stop() {
if (recStarted) {
- audioController.unmute();
recognizer.cancel();
recognizer.stopListening();
recognizer.destroy();
@@ -129,6 +150,16 @@ public class Recognizer implements RecognitionListener {
}
+ public void beep() {
+
+ audioController.unmute();
+ MediaPlayer.create(context, R.raw.beep).start();
+
+ if (recStarted)
+ audioController.mute();
+
+ }
+
public void destroy() {
recognizer.destroy();
diff --git a/android_service_app/app/src/main/res/raw/beep.wav b/android_service_app/app/src/main/res/raw/beep.wav
new file mode 100644
index 0000000..f224049
Binary files /dev/null and b/android_service_app/app/src/main/res/raw/beep.wav differ