commit 08eedd8596246f75de5e31fe2cabb1617302ca22 Author: Jimmie Matsson Date: Wed Jan 18 11:00:31 2017 +0100 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..384daf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml +.idea/workspace.xml +.idea/modules.xml +.idea/libraries +.idea/vcs.xml +.idea/codeStyleSettings.xml + +# Keystore files +*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cca2cda --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..df44218 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.1" + + defaultConfig { + applicationId "com.voixtreme.vocalengine" + minSdkVersion 15 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:24.2.1' + compile files('libs/vocalizerlib.jar') +} diff --git a/app/libs/vocalizerlib.jar b/app/libs/vocalizerlib.jar new file mode 100644 index 0000000..a830008 Binary files /dev/null and b/app/libs/vocalizerlib.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..d6113c1 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Android\android-sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/voixtreme/vocalengine/ApplicationTest.java b/app/src/androidTest/java/com/voixtreme/vocalengine/ApplicationTest.java new file mode 100644 index 0000000..b53527a --- /dev/null +++ b/app/src/androidTest/java/com/voixtreme/vocalengine/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.voixtreme.vocalengine; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..2e13c80 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/voixtreme/vocalengine/MainActivity.java b/app/src/main/java/com/voixtreme/vocalengine/MainActivity.java new file mode 100644 index 0000000..589c87e --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/MainActivity.java @@ -0,0 +1,37 @@ +package com.voixtreme.vocalengine; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; + +import com.voixtreme.vocalengine.service.VoiXtremeService; + +//============================================================================= +// This activity does nothing, and holds the service +public class MainActivity extends Activity { + + // Tag + private static final String TAG = MainActivity.class.getSimpleName(); + + //========================================================================= + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + startVoixtremeService(); + + // Please comment this if you are debugging to keep the activity alive + finish(); + } + + //========================================================================= + // Start the service by an intent (if not already started in boot) + private void startVoixtremeService() { + + Intent intentService = new Intent(this, VoiXtremeService.class); + startService(intentService); + } +} + + diff --git a/app/src/main/java/com/voixtreme/vocalengine/receivers/BootReceiver.java b/app/src/main/java/com/voixtreme/vocalengine/receivers/BootReceiver.java new file mode 100644 index 0000000..84530aa --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/receivers/BootReceiver.java @@ -0,0 +1,40 @@ +package com.voixtreme.vocalengine.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import com.voixtreme.vocalengine.service.VoiXtremeService; + +//============================================================================= +/** + * Created by JMA and CZon 17-Aug-16. + */ +public class BootReceiver extends BroadcastReceiver { + + // Tag + private static final String TAG = BootReceiver.class.getSimpleName(); + + // Methods + @Override + public void onReceive(Context context, Intent intent) { + + if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { + try { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putBoolean("initialized", true).commit(); + context.startService(new Intent(context, VoiXtremeService.class)); + } catch(Exception e) { + Log.e(TAG, e.toString()); + } + } + } +} + + + + diff --git a/app/src/main/java/com/voixtreme/vocalengine/receivers/VoiXtremeReceiver.java b/app/src/main/java/com/voixtreme/vocalengine/receivers/VoiXtremeReceiver.java new file mode 100644 index 0000000..5ff3977 --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/receivers/VoiXtremeReceiver.java @@ -0,0 +1,154 @@ +package com.voixtreme.vocalengine.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Message; +import android.util.Log; + +import com.voixtreme.vocalengine.service.VoiXtremeService; +import com.voixtreme.vocalengine.service.VxtCommandManager; +import com.voixtreme.vocalengine.service.VxtAsrStateManager; +import com.voixtreme.vocalengine.service.VxtTtsManager; + +//============================================================================= +/** + * Created by CZ + Jimmie + * This class will receive the intents form the App that is using the VoiXtreme service. + * It generates a broadcast message to handler on Service + */ +public class VoiXtremeReceiver extends BroadcastReceiver { + + // The data sent / received through intents + private VxtCommandManager commandManager; + + // ASR state + private VxtAsrStateManager asrStateManager; + + // The data for TTS engine + private VxtTtsManager ttsManager; + + // Handler to dispatch internally + private VoiXtremeService.IncomingHandler mHandler; + + // Tag + private static final String TAG = VoiXtremeReceiver.class.getSimpleName(); + + // Intent data ------ + + // To be received from Emulator App + public static final String BROADCAST_RECEIVE_INTENT_COMMAND = "com.voixtreme.vocalengine.COMMAND"; + + // Intent Data + public static final String EXTRAS_COMMAND = "COMMAND"; + public static final String EXTRAS_TEXT = "TEXT"; + public static final String EXTRAS_PACKAGE = "PACKAGE"; + public static final String EXTRAS_RELIABILITY = "RELIABILITY"; + public static final String EXTRAS_VOICES = "VOICES"; + public static final String EXTRAS_REGISTER = "REGISTER"; + public static final String EXTRAS_ASRSTATE = "ASRSTATE"; + + public static final int COMMAND_UNKNOWN = -1; + public static final int COMMAND_INITIALIZE_ALL = 0; + public static final int COMMAND_INITIALIZE_TTS = 1; + public static final int COMMAND_FINALIZE = 2; + public static final int COMMAND_SPEECH = 3; + public static final int COMMAND_STATE = 4; + public static final int COMMAND_TTS = 99; + + + //============================================================================= + // Intent receiver, performs a local message to handle + @Override + public void onReceive(Context context, Intent intent) { + + final String action = intent.getAction(); + + if ( action == BROADCAST_RECEIVE_INTENT_COMMAND) // Received from Emulator + { + if (commandManager == null) { + // TODO: exception + return; + } + + // The command + int command = intent.getExtras().getInt(EXTRAS_COMMAND, COMMAND_UNKNOWN); + // The response package + if ( intent.hasExtra( EXTRAS_PACKAGE)) { + String packageName= intent.getExtras().getString( EXTRAS_PACKAGE); + commandManager.setIntentPackage( packageName); + asrStateManager.setIntentPackage( packageName); + Log.i(TAG, "Intent PACKAGE =" + commandManager.intentPackage); + } + + // Following received command IN INTENT + switch(command) { + // This command will load ASR and TTS libraries + case COMMAND_INITIALIZE_ALL: + commandManager.setCommand(command, null); + mHandler.sendMessage( Message.obtain( mHandler, command)); + break; + + // This command will load the TTS selecteºd voice + case COMMAND_INITIALIZE_TTS: + if ( intent.hasExtra( EXTRAS_VOICES)) { + String selectedVoice= intent.getExtras().getString( EXTRAS_VOICES); + Log.i(TAG, "Intent COMMAND_INITIALIZE_TTS SelectedVoice="); + commandManager.setVoice(selectedVoice ); + } + else { + Log.i(TAG, "Intent COMMAND_INITIALIZE_TTS ERROR NO VOICE!!"); + } + commandManager.setCommand(command, null); + mHandler.sendMessage( Message.obtain( mHandler, command)); + break; + + case COMMAND_FINALIZE: + Log.i(TAG, "Intent COMMAND_FINALIZE"); + commandManager.setCommand(command, null); + mHandler.sendMessage( Message.obtain( mHandler, command)); + break; + + case COMMAND_SPEECH: + Log.i(TAG, "Intent COMMAND_SPEECH"); + String text = intent.getExtras().getString(EXTRAS_TEXT, "no text sent"); + commandManager.setCommand(command, text); + mHandler.sendMessage( Message.obtain( mHandler, command)); + break; + + case COMMAND_STATE: + Log.i(TAG, "Intent COMMAND_STATE"); + if ( intent.hasExtra( EXTRAS_REGISTER)) { + int registerEvent = intent.getExtras().getInt( EXTRAS_REGISTER); + Log.i(TAG, "Intent COMMAND_STATE REGISTER=" + registerEvent ); + asrStateManager.setRegisterState( registerEvent); + mHandler.sendMessage( Message.obtain( mHandler, command)); + } + break; + + default: + // TODO: exception + Log.e(TAG, "Intent ERROR command=" + command); + return; + } + } + } + + //============================================================================= + // Set the internal message cmd manager (incoming INTENTS) + // Set the TTS messages manager + // Set the internal Asr state manager + public void setDataManagers(VxtCommandManager commandManager, VxtTtsManager vxtTtsManager, VxtAsrStateManager asrStateManager) + { + this.commandManager = commandManager; + this.ttsManager= vxtTtsManager; + this.asrStateManager = asrStateManager; + } + + //============================================================================= + // Set the internal message handler + public void setIncomingHandler(VoiXtremeService.IncomingHandler mHandler) { + this.mHandler = mHandler; + } +} + diff --git a/app/src/main/java/com/voixtreme/vocalengine/service/VoiXtremeService.java b/app/src/main/java/com/voixtreme/vocalengine/service/VoiXtremeService.java new file mode 100644 index 0000000..0bebff8 --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/service/VoiXtremeService.java @@ -0,0 +1,881 @@ +package com.voixtreme.vocalengine.service; + +import android.app.Service; +//import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +//import android.os.Environment; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.support.annotation.Nullable; +import android.util.Log; +//import android.widget.Toast; + +import com.nuance.android.vocalizer.VocalizerEngine; +import com.nuance.android.vocalizer.VocalizerEngineListener; +import com.nuance.android.vocalizer.VocalizerVoice; +import com.voixtreme.vocalengine.R; +import com.voixtreme.vocalengine.receivers.VoiXtremeReceiver; +import com.voixtreme.vxtenginejni.VxtEngineApi; + + +//import java.io.File; +import java.io.File; +import java.io.FileInputStream; +import java.lang.ref.WeakReference; +import java.util.LinkedHashMap; +import java.util.Map; +//import java.util.Vector; + +// Import constants for intents +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_INITIALIZE_ALL; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_SPEECH; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_STATE; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_TTS; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.EXTRAS_ASRSTATE; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.EXTRAS_COMMAND; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.EXTRAS_RELIABILITY; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.EXTRAS_TEXT; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.EXTRAS_VOICES; + +//============================================================================= +/** + * Created by JMA + CZ on 7-Nov-16. + * The service holds + * - The VoiXtreme event Listener + * - The Nuance TtsEngine with jar and API + * - The VoiXtreme API + * - The Handler system with async messages + */ + +/** + * SERVICE + * Outbond intents with voice commands (TAGS) are received by VoiXtremeReceiver + */ +public class VoiXtremeService extends Service + implements VocalizerEngineListener { + + // Intents and messages ---------------------------------------- + + // The VoiXtreme intents receiver + private VoiXtremeReceiver voiXtremeReceiver= null; + + // The event message handler + private IncomingHandler mIncomingHandler= new IncomingHandler( this); + + // Engines ASR and TTS ----------------------------------------- + + // The VoiXtreme API + private VxtEngineApi mVxtEngineApi= null; + + // Tts Vocalizer Engine: the text to speech engine. + private VocalizerEngine ttsEngine = null; + + private static final String VOIXTREME_SERVICE_VERSION = "4.0.1"; + + // Tag + private static final String TAG = VoiXtremeService.class.getSimpleName(); + + // Data holders classes ------------------------------------ + // This object contains the command to VoiXtreme and ttsEngine + private VxtCommandManager mVxtCommandManager = null; + + // This object contains the command to ttsEngine + private VxtTtsManager mVxtTtsManager= null; + + // This object containts the ASR state data + private VxtAsrStateManager mVxtAsrStateManager= null; + + private boolean mIsVoiceLoaded= false; + private boolean mIsSepaking = false; + + // Available voices objects of tts engine + private VocalizerVoice[] mVoicesAvailable = null; + + // To save all tts engine voices NAMES (VocalizerVoice[].mVoiceName) from obb file into a MAP + private Map mVoiceNamesListMap = null; + + // comma separated list of voices names + private String mVoicesNames; + + // The ASR language configured (EN, FR, US) + private String mAsrLanguageConfigured; + + // These values holds the current TTS engine parameters + private class TtsParameters { + public String mVoiceConfigured; + public String mVoiceSelected; + public int mVolume; + public int mRate; + public int mPitch; + public long mRuleHandle= -1; + } + private TtsParameters mTtsCurParm = new TtsParameters(); + + // The current values for a say + private class TtsSayData { + public int mSayTtsId; + public int mSayAsrMode; + public int mSayTtsMode; + public String mSayPhrase; + } + private TtsSayData mSay = new TtsSayData(); + + private class TtsValuesAndSettings { + // Vocalizer Engine Parameters Range: + // Volume: + final int MIN_VOLUME = 0; + final int MAX_VOLUME = 100; + final int DEFAULT_VOLUME = 80; + + // Pitch: + final int MIN_PITCH = 50; + final int MAX_PITCH = 200; + final int DEFAULT_PITCH = 33; + + // Rate: + final int MIN_RATE = 50; + final int MAX_RATE = 400; + final int DEFAULT_RATE = 14; + + final int MIN_PROPERTY = 0; + final int MAX_PROPERTY = 100; + } + + private TtsValuesAndSettings mTtsConst = new TtsValuesAndSettings(); + + //========================================================================= + // Service Overrides + //========================================================================= + + //========================================================================= + // Service Overrides / Create the service + @Override + public void onCreate() { + super.onCreate(); + + Log.i(TAG, "onCreate"); + + // The initial TTS CURRENT SAY values + mSay.mSayTtsId= 0; + mSay.mSayAsrMode= 0; + mSay.mSayTtsMode= 0; + mSay.mSayPhrase= ""; + + // The VoiXtreme engine + mVxtEngineApi = new VxtEngineApi(this); + + // The command manager btw intent listener and service + mVxtCommandManager = new VxtCommandManager(); + + mVxtTtsManager= new VxtTtsManager(); + + mVxtAsrStateManager = new VxtAsrStateManager(); + + // The intent receiver + voiXtremeReceiver = new VoiXtremeReceiver(); + voiXtremeReceiver.setDataManagers(mVxtCommandManager,mVxtTtsManager,mVxtAsrStateManager); + voiXtremeReceiver.setIncomingHandler( mIncomingHandler ); + IntentFilter filter = new IntentFilter(VoiXtremeReceiver.BROADCAST_RECEIVE_INTENT_COMMAND); + registerReceiver(voiXtremeReceiver, filter); + + + } + + //========================================================================= + // Service Overrides / start command + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + super.onStartCommand(intent, flags, startId); + return START_STICKY; // We want to live forever + } + + //========================================================================= + // Service Overrides / destroy service + @Override + public void onDestroy() + { + // Executed Sometimes, when Android OS decides to execute it or not. + // GoodBye message: + + unregisterReceiver(voiXtremeReceiver); +// ttsEngine.speak(mGoodByeMessage, false, "GoodByeMessage"); + + ttsEngineFinalize(); + if (ttsEngine != null) + ttsEngine.release(); + + ttsEngine = null; + mVxtEngineApi = null; + mVxtCommandManager = null; + + mIsVoiceLoaded= false; + mIsSepaking = false; + + super.onDestroy(); + } + + + //========================================================================= + // Voixtreme callbacks to implement tts features + //========================================================================= + + + //========================================================================= + // This method is called from Vxt to set the loaded ASR language + public void ttsSetLanguage( String asrLanguageConfigured) + { + Log.i( TAG, "ttsSetLanguage LanguageConfigured=" + asrLanguageConfigured ); + mAsrLanguageConfigured= asrLanguageConfigured; + } + + //========================================================================= + // This method is called from Vxt to initialize the tts vocalizer engine + // and load the list of available voices + // issued from VxtEngine Api when receivent an inializeAll intent + public void ttsEngineIntialize(String voiceConfigured) + { + + Log.i( TAG, "ttsEngineIntialize VoiceConfigured=" + voiceConfigured ); + + mTtsCurParm.mVoiceConfigured= voiceConfigured; + mTtsCurParm.mVolume = mTtsConst.DEFAULT_VOLUME; + mTtsCurParm.mRate = mTtsConst.DEFAULT_RATE; + mTtsCurParm.mPitch = mTtsConst.DEFAULT_PITCH; + + + // Load the native vocalizer SO + vocalizerLoadNativeLibraries(); + + // Load list of available voices + vocalizerInitializeSpeechEngine(); + + // Once the speech engine is initialized, the voice list is aynchronously sent to emulator app + } + + //========================================================================= + // This method is called from Vxt to unload the voice + // Warning the voice is NOT really unloaded ... + public void ttsEngineUnloadVoice() + { + mIsVoiceLoaded= false; + ttsEngine.stop(); + } + + //========================================================================= + // This method is called from Vxt to load the tts vocalizer engine + // issued from VxtEngine Api when receivent an inializeTts intent + // using the configured voice + public void ttsEngineLoadVoice(String voiceSelected) + { + + Log.i( TAG, "ttsEngineLoadVoice VoiceSelected=" + voiceSelected ); + + mTtsCurParm.mVoiceSelected = voiceSelected; + + // Once the speech engine is initialized, and the vocie is selecterd by user, + // the -selected- voice can be loaded + vocalizerLoadVoiceAndConfigure(); + + // Also the rulset resources can be loaded + vocalizerLoadRules(); + + // Say the (harcoded) welcome message with version + mIsVoiceLoaded= true; + ttsEngine.speak( "VoiXtreme version " + VOIXTREME_SERVICE_VERSION, false, "0"); + } + + //========================================================================= + // This method is called from Vxt to terminate the tts vocalizer engine + public void ttsEngineFinalize () + { + + if( ttsEngine != null) { + + if( mTtsCurParm.mRuleHandle != -1) { + ttsEngine.unloadResource(mTtsCurParm.mRuleHandle); + mTtsCurParm.mRuleHandle = -1; + } + + ttsEngine.release(); + ttsEngine= null; + } + } + + //========================================================================= + // This method is called from Vxt to know if tts engine is currently speaking + public boolean ttsEngineIsSpeaking() + { + return mIsSepaking; + } + + //========================================================================= + // This method is called from Vxt to stop any currently speaking action + public boolean ttsEngineStopSpeaking() + { + Log.i( TAG, "ttsEngineStopSpeaking" ); + + boolean isOk= ttsEngine.stop(); + if( isOk== false) { + Log.e( TAG, "ttsEngineStopSpeaking ERROR" ); + } + // No more values (disable callbacks) + mSay.mSayTtsId = 0; + mSay.mSayAsrMode = 0; + mSay.mSayTtsMode = 0; + mSay.mSayPhrase = ""; + + return isOk; + } + + //============================================================================================= + // say a phrase by vocalizer that runs it by his own thread + public boolean ttsEngineSay( int ttsId, int asrMode, int ttsMode, String phrase) + { + Log.i( TAG, "ttsEngineSay ='" + phrase + "' Id=" + ttsId); + + if( mIsSepaking== false) { + + // We put the data on the shared object + // The local message handler will put it on tts engine + mVxtTtsManager.SetTtsValues( ttsId, asrMode, ttsMode, phrase); + //mVxtCommandManager.SetTtsValues( ttsId, asrMode, ttsMode, phrase); + mIncomingHandler.sendMessage( Message.obtain( mIncomingHandler, COMMAND_TTS)); + } + else { + // TODO ERROR + Log.e( TAG,"ttsEngineSay ERROR ENGINE IS SPEAKING =" + phrase); + } + + return true; + + } + + + //========================================================================= + // Binder + //========================================================================= + + //========================================================================= + // To comunicate with service from main activity + @Nullable + @Override + public IBinder onBind(Intent intent) { + + return null; + } + + + //========================================================================= + // Vocalizer engine management + //========================================================================= + + //========================================================================= + // Dynamically load the Nuance Vocalizer Expressive library at runtime + // Mandatory to call before calling any native method. + private void vocalizerLoadNativeLibraries() + { + System.loadLibrary("NuanceVocalizer"); + Log.i(TAG, "vocalizerLoadNativeLibraries libNuanceVocalizer.so loaded"); + } + + + //========================================================================= + /** + * Constructs and begins initialization of the Text-to-Speech engine. + * This method will be called once during the life time of the service + * The list of voices and names map is populated with existing ones + */ + private void vocalizerInitializeSpeechEngine() { + // Check if we have a Text-to-Speech engine object from the last session (activity recreation). + // because the service will be alive forever or starts when the device boot is completed and not controlled by user + //ttsEngine=(VocalizerEngine)getLastNonConfigurationInstance(); + + Log.i(TAG, "vocalizerInitializeSpeechEngine Beg"); + + if (ttsEngine == null) { + // Activity is first created, so create a new Text-to-Speech engine and configure it. + + // Use the application context to prevent memory leaks when re-using the + // Text-to-Speech engine accross activity recreations due to configuration + // changes. + ttsEngine = new VocalizerEngine(getApplicationContext()); + + // Register this service as the listener to receive state change events. + ttsEngine.setListener(this); + + // Begin the initialization of the Text-to-Speech engine. Note that the + // initialization process is asynchronous. onStateChanged will be invoked + // once the initialization process is completed. + // ////////// + // Then an intent will be sent to parent with voice list + ttsEngine.initialize(); + } else { + // Send back by intent the configured language and (comma separated) voices list + // As well as it was sent in initial load + sendIntentInitializeResult( mAsrLanguageConfigured, mVoicesNames); + } + + Log.i(TAG, "vocalizerInitializeSpeechEngine End"); + } + + //========================================================================= + // To populate mVoiceNamesListMap with all available voices within obb expansion file + // build comma separated list of voices into mVoicesNames + private void vocalizerLoadVoiceListMap( VocalizerVoice[] aVoicesList) + { + Log.i(TAG, "vocalizerLoadVoiceListMap"); + if (aVoicesList != null) { + mVoicesNames=""; + mVoiceNamesListMap = new LinkedHashMap(); // LinkedHashMap preserves insertion order! + for (int index = 0; index < aVoicesList.length; ++index) { + String voiceName= aVoicesList[index].getVoiceName(); + mVoiceNamesListMap.put(voiceName, aVoicesList[index]); + if( index == 0) + mVoicesNames= mVoicesNames + voiceName; + else + mVoicesNames= mVoicesNames + "," + voiceName; + Log.d(TAG, "Voice '" + voiceName + "' found"); + } + Log.d(TAG, "Total voices: " + mVoiceNamesListMap.size()); + Log.d(TAG, "Voices List: " + mVoicesNames ); + Log.d(TAG, "VoiceSelector map initialized correctly!"); + } else { + Log.e(TAG, "vocalizerLoadVoiceListMap Error, not available voices!"); + } + } + + //========================================================================= + // Returns null on error + // mVoiceNamesListMap (vocalizerLoadVoiceListMap) MUST be called before + // Returns the selected voice or the default one + private VocalizerVoice vocalizerVoiceFromVoiceName(String sVoiceSelected, String sVoiceConfigured) + { + Log.i(TAG, "vocalizerVoiceFromVoiceName VoiceSelected=" + sVoiceSelected); + + if( mVoiceNamesListMap == null) { + Log.e(TAG, "vocalizerVoiceFromVoiceName FATAL ERROR NO LIST "); + return null; + } + + // Try to get the selected voice + if( mVoiceNamesListMap.containsKey(sVoiceSelected)) { + Log.i(TAG, "vocalizerVoiceFromVoiceName FOUND " + sVoiceSelected); + return mVoiceNamesListMap.get(sVoiceSelected); + } + else { + Log.e(TAG, "Error, the selected voice '" + sVoiceSelected + "' is not available!"); + if( mVoiceNamesListMap.containsKey(sVoiceConfigured)) { + Log.i(TAG, "vocalizerVoiceFromVoiceName FOUND " + sVoiceConfigured); + return mVoiceNamesListMap.get(sVoiceConfigured); + } + else { + + Log.e(TAG, "Error, the configured voice '" + sVoiceConfigured + "' is not available!"); + Log.e(TAG, "Available voices are:"); + for (Map.Entry entry : mVoiceNamesListMap.entrySet()) { + Log.e(TAG, "Key : " + entry.getKey() + " Value : " + entry.getValue()); + } + // Select the first one + String defaultVoice = (String) mVoiceNamesListMap.keySet().toArray()[0]; + Log.e(TAG, "Selected voice by default: " + defaultVoice); + return mVoiceNamesListMap.get(defaultVoice); + } + } + } + + //========================================================================= + /* + * Load the Tts voice mVoiceSelected or mVoiceConfigured + * Configure the speech properties ( mVolume, mRate, mPitch) + * */ + private boolean vocalizerLoadVoiceAndConfigure() + { + Log.i(TAG, "vocalizerLoadVoiceAndConfigure " + mTtsCurParm.mVoiceSelected ); + // Load the voice + if( ttsEngine.loadVoice( vocalizerVoiceFromVoiceName( mTtsCurParm.mVoiceSelected, mTtsCurParm.mVoiceConfigured)) ) { + // Set initial parameters + vocalizerConfigureSpeechProperties( mTtsCurParm.mVolume, mTtsCurParm.mRate, mTtsCurParm.mPitch); + return true; + } + else { + Log.e(TAG, "vocalizerLoadVoiceAndConfigure UNABLE TO LOAD VOICE " + mTtsCurParm.mVoiceSelected ); + return false; + } + } + + //========================================================================= + /* + * Load the Tts rules _vxt_ttsrules.txt + * */ + private boolean vocalizerLoadRules() + { + String rulesFileName= System.getenv("EXTERNAL_STORAGE") + "/voixtreme/_vxt_ttsrules.txt"; + + Log.i(TAG, "vocalizerLoadRules " + rulesFileName); + + if( mTtsCurParm.mRuleHandle!= -1) { + ttsEngine.unloadResource( mTtsCurParm.mRuleHandle); + mTtsCurParm.mRuleHandle= -1; + } + + try { + File ruleFile = new File(rulesFileName); + int fileLen = (int) ruleFile.length(); + byte[] ruleData = new byte[fileLen]; + FileInputStream fis = new FileInputStream(ruleFile); + fis.read(ruleData); + mTtsCurParm.mRuleHandle= ttsEngine.loadRuleSet( ruleData); + return true; + } + catch (Exception e) { + Log.e(TAG, "vocalizerLoadRules UNABLE TO LOAD " + rulesFileName); + return false; + } + + } + + + //========================================================================= + /** + * Updates the Text-to-Speech engine properties (volume, rate and pitch) with + * the values currently selected in the UI. This method should be called whenever + * the selection of any of the properties spinners is changed, or when a new + * voice is loaded. + * All the parameters are from 0 to 100 and rescaled to tts values + */ + private void vocalizerConfigureSpeechProperties(int voiceVolume, int voiceRate, int voicePitch ) + { + + Log.i(TAG, "vocalizerConfigureSpeechProperties V=" + voiceVolume + " R=" + voiceRate + " P=" + voicePitch); + + // Rescaling values: + int rescaled; + + // Volume + float fRescaledVolume = (((voiceVolume * 1.0f)/mTtsConst.MAX_PROPERTY) * (mTtsConst.MAX_VOLUME - mTtsConst.MIN_VOLUME)) + mTtsConst.MIN_VOLUME; + rescaled= Math.round(fRescaledVolume); + Log.i(TAG, "Volume 0-100 Rescaled=" + rescaled ); + ttsEngine.setSpeechVolume(rescaled); + + // Rate + float fRescaledRate = (((voiceRate * 1.0f)/mTtsConst.MAX_PROPERTY) * (mTtsConst.MAX_RATE - mTtsConst.MIN_RATE)) + mTtsConst.MIN_RATE; + rescaled= Math.round(fRescaledRate); + Log.i(TAG, "Rate 50-400 Rescaled=" + rescaled ); + ttsEngine.setSpeechRate(rescaled); + + // Pitch + float fRescaledPitch = (((voicePitch * 1.0f)/mTtsConst.MAX_PROPERTY) * (mTtsConst.MAX_PITCH - mTtsConst.MIN_PITCH)) + mTtsConst.MIN_PITCH; + rescaled= Math.round(fRescaledPitch); + Log.i(TAG, "Pitch 50-200 Rescaled=" + rescaled ); + ttsEngine.setSpeechPitch(rescaled); + } + + //========================================================================= + // parameter is from 0 to 100 and rescaled to tts values + public void vocalizerConfigureVolume( int voiceVolume) + { + mTtsCurParm.mVolume= voiceVolume; + Log.i(TAG, "vocalizerConfigureVolume 0-100 =" + voiceVolume ); + + if (mIsVoiceLoaded) { + // Volume + float fRescaledVolume = (((voiceVolume * 1.0f) / mTtsConst.MAX_PROPERTY) * (mTtsConst.MAX_VOLUME - mTtsConst.MIN_VOLUME)) + mTtsConst.MIN_VOLUME; + int rescaled= Math.round(fRescaledVolume); + Log.i(TAG, "vocalizerConfigureVolume 0-100 Rescaled=" + rescaled ); + ttsEngine.setSpeechVolume( rescaled); + }else { + Log.e(TAG, "vocalizerConfigureVolume 0-100 ERROR" ); + } + + } + + //========================================================================= + // parameter is from 0 to 100 and rescaled to tts values + public void vocalizerConfigureRate( int voiceRate) + { + mTtsCurParm.mRate= voiceRate; + Log.i(TAG, "vocalizerConfigureRate 0-100 =" + voiceRate ); + + if (mIsVoiceLoaded) { + // Rate + float fRescaledRate = (((voiceRate * 1.0f) / mTtsConst.MAX_PROPERTY) * (mTtsConst.MAX_RATE - mTtsConst.MIN_RATE)) + mTtsConst.MIN_RATE; + int rescaled= Math.round(fRescaledRate); + Log.i(TAG, "vocalizerConfigureRate 50-400 Rescaled=" + rescaled ); + ttsEngine.setSpeechRate(rescaled); + }else { + + } + } + + //========================================================================= + // parameter is from 0 to 100 and rescaled to tts values + public void vocalizerConfigurePitch( int voicePitch) + { + mTtsCurParm.mPitch= voicePitch; + Log.i(TAG, "vocalizerConfigurePitch =" + voicePitch ); + + if (mIsVoiceLoaded) { + // Pitch + float fRescaledPitch = (((voicePitch * 1.0f) / mTtsConst.MAX_PROPERTY) * (mTtsConst.MAX_PITCH - mTtsConst.MIN_PITCH)) + mTtsConst.MIN_PITCH; + int rescaled= Math.round(fRescaledPitch); + Log.i(TAG, "vocalizerConfigurePitch 50-200 Rescaled=" + rescaled ); + ttsEngine.setSpeechPitch(rescaled); + }else { + + } + + } + + //========================================================================= + // Implementation of VocalizerEngineListener interface: + //========================================================================= + + /** + * This method will be called when the state of the Text-to-Speech engine changes. + * The main purpose of this method is to update the contents of the UI according + * to the current engine state. + *

+ * Note that when the engine is done initializing the first voice in the list + * will automatically be loaded by a call to loadSelectedVoice. It is not + * the default behavior of the Text-to-Speech engine to load any voice upon + * initialization. + */ + @Override + public void onStateChanged(int newState) { + String stateStr = ""; + + switch (newState) { + + // The tts engine was correctly initialized, we can load the voice list and send + // to the calibrate for user choice + case VocalizerEngine.STATE_INITIALIZED: + stateStr = getString(R.string.state_initialized); + Log.i( TAG, "onStateChanged STATE_INITIALIZED"); + vocalizerLoadVoiceListMap( ttsEngine.getVoiceList()); + mIsSepaking = false; + mSay.mSayTtsId = 0; + // Send back by intent the configured language and (comma separated) voices list + sendIntentInitializeResult( mAsrLanguageConfigured, mVoicesNames); + break; + + case VocalizerEngine.STATE_INIT_ERROR: // Initialization has failed. + stateStr = getString(R.string.state_init_error); + Log.i( TAG, "onStateChanged STATE_INIT_ERROR"); + mIsVoiceLoaded= false; + break; + + case VocalizerEngine.STATE_READY: + stateStr = getString(R.string.state_ready); + Log.i( TAG, "onStateChanged STATE_READY Id=" + mSay.mSayTtsId); + mIsSepaking = false; + // CALL THE TTS API INDICATING THE SPEECH IS FINISHED + if( mSay.mSayTtsId == 0) { + Log.e( TAG, "onStateChanged STATE_READY NO SAY ID"); + } else { + mVxtEngineApi.TtsCallback( 2, mSay.mSayTtsId, mSay.mSayAsrMode, mSay.mSayTtsMode); + mSay.mSayTtsId = 0; + } + break; + + case VocalizerEngine.STATE_SPEAKING: + stateStr = getString(R.string.state_speaking); + Log.i( TAG, "onStateChanged STATE_SPEAKING"); + mIsSepaking = true; + if( mSay.mSayTtsId == 0) { + Log.e( TAG, "onStateChanged STATE_SPEAKING NO SAY ID"); + } else { + // CALL THE TTS API INDICATING THE SPEECH IS BEGINNING + mVxtEngineApi.TtsCallback(1, mSay.mSayTtsId, mSay.mSayAsrMode, mSay.mSayTtsMode); + } + break; + + case VocalizerEngine.STATE_PAUSED: + stateStr = getString(R.string.state_paused); + Log.i( TAG, "onStateChanged STATE_PAUSED"); + break; + + case VocalizerEngine.STATE_UNINITIALIZED: + stateStr = getString(R.string.state_uninitialized); + Log.i( TAG, "onStateChanged STATE_UNINITIALIZED"); + break; + + default: + stateStr = "Unknown state!"; + Log.i( TAG, "onStateChanged STATE_UNINITIALIZED"); + break; + } + + Log.i(TAG, stateStr); + } + + + /** + * This method will be called by the Text-to-Speech engine when + * it begins speaking. Note that in order to be notified one must pass + * a text id to the speak method. + */ + @Override + public void onSpeakElementStarted(String id) { + Log.v(TAG, "Started text with id: " + id); + } + + /** + * This method will be called by the Text-to-Speech engine when + * it has completed speaking the text. Note that in order to be notified + * one must pass a text id to the speak method. + */ + @Override + public void onSpeakElementCompleted(String id) { + Log.v(TAG, "Completed text with id: " + id); + } + + /** + * This method will be called by the Text-to-Speech engine when the list + * of available voices changes. This is due to a voice package being + * installed or removed in the system. + */ + @Override + public void onVoiceListChanged() { + mVoicesAvailable = ttsEngine.getVoiceList(); + } + + + //========================================================================= + // send back by intent the init result to emulator COMMAND_INITIALIZE_ALL + public boolean sendIntentInitializeResult( String configuredLanguage, String voiceList ) + { + Log.i( TAG, "sendIntentInitializeResult Language=" + configuredLanguage + " Voices=" + voiceList + " To=" + mVxtCommandManager.intentPackage ); + + // send back by intent the initialize response to emulator (language and voices) + Intent intent = new Intent(mVxtCommandManager.intentPackage); + intent.putExtra(EXTRAS_COMMAND, COMMAND_INITIALIZE_ALL); + intent.putExtra(EXTRAS_TEXT, configuredLanguage); + intent.putExtra(EXTRAS_VOICES, voiceList); + sendBroadcast(intent); + + return true; + } + + + //========================================================================= + // send back by intent the recognition result to emulator + public boolean sendIntentRecognitionResult(int reliability, String result ) + { + Log.i( TAG, "sendIntentRecognitionResult =" + result + " To=" + mVxtCommandManager.intentPackage ); + + // send back by intent the recognition result to emulator + //String action = "com.voixtreme.calibrate.RESPONSE"; + Intent intent = new Intent(mVxtCommandManager.intentPackage); + intent.putExtra(EXTRAS_COMMAND, COMMAND_SPEECH); + intent.putExtra(EXTRAS_TEXT, result); + intent.putExtra(EXTRAS_RELIABILITY, reliability); + sendBroadcast(intent); + + return true; + } + + //========================================================================= + // send back by intent the ASR engine state to emulator + public void sendIntentAsrStateChanges( int asrState ) + { + Log.i( TAG, "sendIntentAsrStateChanges =" + asrState + " To=" + mVxtAsrStateManager.intentPackage ); + + // send back by intent the recognition result to emulator + Intent intent = new Intent( mVxtAsrStateManager.intentPackage); + intent.putExtra(EXTRAS_COMMAND, COMMAND_STATE); + intent.putExtra(EXTRAS_ASRSTATE, asrState); + sendBroadcast(intent); + } + + + //========================================================================= + // Asynchronously process the + // Handler, will receive the commands + // * From the intents + // * From The Vxt component + //========================================================================= + + + //========================================================================= + // This method is invoked when an intent from Tnx Emulator arrives with a command + public void updateFromHandler( int command) { + + Log.i( TAG, "updateFromHandler Thread=" + Thread.currentThread().getId()); + switch ( command) { + // From intent + case VoiXtremeReceiver.COMMAND_INITIALIZE_ALL: + Log.i(TAG, "update COMMAND_INITIALIZE_ALL" ); + mVxtEngineApi.vxtInitialize(); + break; + + // From intent + case VoiXtremeReceiver.COMMAND_INITIALIZE_TTS: + Log.i(TAG, "update COMMAND_INITIALIZE_TTS Voice=" + mVxtCommandManager.ttsVoice); + mVxtEngineApi.TtsLoadVoice( mVxtCommandManager.ttsVoice); + break; + + // From intent + case VoiXtremeReceiver.COMMAND_FINALIZE: + Log.i(TAG, "update COMMAND_FINALIZE" ); + mVxtEngineApi.vxtFinalize(); + break; + + // From intent + case VoiXtremeReceiver.COMMAND_SPEECH: + Log.i(TAG, "update COMMAND_SPEECH Commands=" + mVxtCommandManager.text ); + mVxtEngineApi.nativecommand( mVxtCommandManager.text ); + break; + + // From intent + case VoiXtremeReceiver.COMMAND_STATE: + Log.i(TAG, "update COMMAND_STATE Register " ); + mVxtEngineApi.nativeregisterasrevent( mVxtAsrStateManager.mRegisteredForState, mVxtAsrStateManager.mRegisteredEnergy ); + break; + + // (From native) Make it run the TTS + case COMMAND_TTS: + Log.i(TAG, "update COMMAND_TTS Phrase=" + mVxtTtsManager.sayPhrase ); + mSay.mSayTtsId = mVxtTtsManager.sayTtsId; + mSay.mSayAsrMode = mVxtTtsManager.sayAsrMode; + mSay.mSayTtsMode = mVxtTtsManager.sayTtsMode; + mSay.mSayPhrase = mVxtTtsManager.sayPhrase; + + String textId = Integer.toString(mSay.mSayTtsId); + ttsEngine.speak( mVxtTtsManager.sayPhrase, false, textId); + break; + + } + + } + + //========================================================================= + public static class IncomingHandler extends Handler { + private final WeakReference mService; + + IncomingHandler(VoiXtremeService service) { + + mService = new WeakReference<>(service); + } + + @Override + public void handleMessage(Message msg) { + + VoiXtremeService service = mService.get(); + if (service != null) { + service.handleMessage(msg); + } + } + + } + + //========================================================================= + // the command messages from emulator or Asr + public void handleMessage(final Message msg) { + + updateFromHandler(msg.what ); + } + + +} diff --git a/app/src/main/java/com/voixtreme/vocalengine/service/VxtAsrStateManager.java b/app/src/main/java/com/voixtreme/vocalengine/service/VxtAsrStateManager.java new file mode 100644 index 0000000..7c19c25 --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/service/VxtAsrStateManager.java @@ -0,0 +1,66 @@ +package com.voixtreme.vocalengine.service; + +//============================================================================= + +import static com.voixtreme.vocalengine.service.VxtCommandManager.BROADCAST_SEND_INTENT_COMMAND; +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_STATE; + +/** + * Created by c_zorrilla on 25/11/2016. + * This class holds the ASR engine state + */ + +public class VxtAsrStateManager +{ + + // The command is always COMMAND_STATE + public static final int command= COMMAND_STATE; + + // The package to send the response + public String intentPackage= BROADCAST_SEND_INTENT_COMMAND; + + // 0=NOL No Listen-red, 1=NOS (NO Speech), 2=BOS (Begin Of Speech), EOR=End Of Recognition-green. + public int mState=0; + + // The energy of input sound 0-100 + public int mEnergy=0; + + // Id if this sequence (counter) + public int mId=0; + + public boolean mRegisteredForState= false; + + public boolean mRegisteredEnergy= false; + + //========================================================================= + // to emulator or calibrate state + public void setState( int state) + { + mState= state; + ++mId; + } + + //========================================================================= + // Set the registration state from intent intent.register + public void setRegisterState(int register) + { + if( (register== 1) || (register== 3) ) + mRegisteredForState= true; + else + mRegisteredForState= false; + + if( (register== 2) || (register== 3) ) + mRegisteredEnergy= true; + else + mRegisteredEnergy= false; + + } + + //========================================================================= + // For package + public void setIntentPackage( String intentPackage_) + { + this.intentPackage= intentPackage_; + } + +} diff --git a/app/src/main/java/com/voixtreme/vocalengine/service/VxtCommandManager.java b/app/src/main/java/com/voixtreme/vocalengine/service/VxtCommandManager.java new file mode 100644 index 0000000..a4a3b40 --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/service/VxtCommandManager.java @@ -0,0 +1,80 @@ +package com.voixtreme.vocalengine.service; + +import java.util.Observable; // To allow to monitor by observers if the queue is empty or not. + +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_TTS; + +//============================================================================= +/** + * Created by JMA + CZ 7-11-16. + * This class holds + * 1) the command sent by the Tnx Emulator to VoiXtreme + * - Is modified by the intent + * - Is consommed by the service + * 2) the command sent by VxtEngine to TTS + * - Is modified by the TtsEngine + * - Is consommed by the service (tts) + */ +public class VxtCommandManager +{ + + public static final String BROADCAST_SEND_INTENT_COMMAND = "com.voixtreme.calibrate.RESPONSE"; + + // The package to send the response + public String intentPackage= BROADCAST_SEND_INTENT_COMMAND; + + public String ttsVoice; // List of voices, or selected voice.. + public String asrLanguage; // The configured ASR language + + // Members set by the intent + public int command; + public String text; + + // The values for a TTS say + //public int sayTtsId=0; + //public int sayAsrMode=0; + //public int sayTtsMode=0; + //public String sayPhrase=""; + + //========================================================================= + // For emulator commands (intent InitializeALL) + public void setLanguaqe( String asrLanguage_) { + asrLanguage= asrLanguage_; + } + + //========================================================================= + // For emulator commands (intent nitializeTTS) + public void setVoice( String ttsVoice_) { + ttsVoice= ttsVoice_; + } + + //========================================================================= + // For emulator commands (intent SPEECH) + public void setCommand(int command_, String text_) { + + this.command= command_; + this.text= text_; + } + + //========================================================================= + // For Tts Values (TtsEngine) + //public void SetTtsValues( int sayTtsId_, int sayAsrMode_, int sayTtsMode_, String sayPhrase_) + //{ + // this.command= COMMAND_TTS; + // this.text= ""; + + // sayTtsId= sayTtsId_; + // sayAsrMode= sayAsrMode_; + // sayTtsMode= sayTtsMode_; + // sayPhrase= sayPhrase_; + //} + + //========================================================================= + // For package + public void setIntentPackage( String intentPackage_) + { + this.intentPackage= intentPackage_; + } + +} + diff --git a/app/src/main/java/com/voixtreme/vocalengine/service/VxtTtsManager.java b/app/src/main/java/com/voixtreme/vocalengine/service/VxtTtsManager.java new file mode 100644 index 0000000..bd235f9 --- /dev/null +++ b/app/src/main/java/com/voixtreme/vocalengine/service/VxtTtsManager.java @@ -0,0 +1,33 @@ +package com.voixtreme.vocalengine.service; + +import static com.voixtreme.vocalengine.receivers.VoiXtremeReceiver.COMMAND_TTS; + +/** + * Created by c_zorrilla on 25/11/2016. + * This class will hold the TTS data to / from vocalizer <=> TtsEngineApi (native) + * Only for internal dispatch message handlers (NOT for intents) + */ + +public class VxtTtsManager +{ + + // The command is always COMMAND_TTS + public static final int command= COMMAND_TTS; + + // The values for a TTS say + public int sayTtsId=0; + public int sayAsrMode=0; + public int sayTtsMode=0; + public String sayPhrase=""; + + //========================================================================= + // For Tts Values (TtsEngine) + public void SetTtsValues( int sayTtsId_, int sayAsrMode_, int sayTtsMode_, String sayPhrase_) + { + sayTtsId= sayTtsId_; + sayAsrMode= sayAsrMode_; + sayTtsMode= sayTtsMode_; + sayPhrase= sayPhrase_; + } + +} diff --git a/app/src/main/java/com/voixtreme/vxtenginejni/TtsEngineApi.java b/app/src/main/java/com/voixtreme/vxtenginejni/TtsEngineApi.java new file mode 100644 index 0000000..9986f61 --- /dev/null +++ b/app/src/main/java/com/voixtreme/vxtenginejni/TtsEngineApi.java @@ -0,0 +1,175 @@ +// This class is managed in the AndroidStudio environment + +package com.voixtreme.vxtenginejni; + +import android.util.Log; + +import com.voixtreme.vocalengine.service.VoiXtremeService; + +//============================================================================================= +// This class is the parent of the VxtEngineApi +// Will expose the functions to manage the TTS engine from the VxtApi +class TtsEngineApi +{ + + // Tag + private static final String TAG = TtsEngineApi.class.getSimpleName(); + + protected VoiXtremeService mService; + + + //============================================================================================= + public TtsEngineApi(VoiXtremeService service) { + + Log.i(TAG, "Constructor with service"); + mService = service; + } + + //============================================================================================= + // 0 Set the language of ASR Engine from initializeAll intent + protected boolean TtsSetLanguage( String languageConfigured) + { + Log.i(TAG, "TtsSetLanguage LanguageConfigured=" + languageConfigured); + + mService.ttsSetLanguage( languageConfigured); + + return true; + } + + //============================================================================================= + // 1 Initialize The TTs Engine from initializeAll intent + protected boolean TtsInitialize( String voiceConfigured) + { + Log.i(TAG, "TtsInitialize VoiceConfigured=" + voiceConfigured); + // TODO check if already + mService.ttsEngineIntialize( voiceConfigured); + + return true; + } + + //============================================================================================= + // Load the selected voice from initializeTts intent + public boolean TtsLoadVoice( String voiceSelected) + { + Log.i(TAG, "TtsLoadVoice VoiceSelected=" + voiceSelected); + mService.ttsEngineLoadVoice( voiceSelected); + + return true; + } + + + //============================================================================================= + // 2 Finalize The TTs Engine + protected boolean TtsFinalize() + { + Log.i(TAG, "TtsFinalize" ); + mService.ttsEngineFinalize(); + + return true; + } + + //============================================================================================= + // 3 The TTS State + public boolean TtsIsSpeaking( ) + { + return mService.ttsEngineIsSpeaking(); + } + + //============================================================================================= + // 4=StopSpeaking (while speaking ...) + public boolean TtsStopSpeaking( ) + { + Log.i(TAG, "TtsStopSpeaking" ); + return mService.ttsEngineIsSpeaking(); + } + + //============================================================================================= + // say a phrase, call the service say method + protected boolean TtsSay( int id, int asrMode, int ttsMode, String phraseToSay) + { + + if( mService.ttsEngineIsSpeaking()== false) { + mService.ttsEngineSay(id, asrMode, ttsMode, phraseToSay); + return true; + } + else { + Log.e(TAG, "TtsSay ERROR, say while speaking Phrase=" + phraseToSay); + } + return false; + } + + + //============================================================================================= + // Phrase processing should be overwrite by child class + // 1=Speech begins, 2=Speech ends + // TODO improve this + public boolean TtsCallback( int action, int id, int asrMode, int ttsMode) + { + + + return true; + } + + //============================================================================================= + // Set the TTS engine property + protected boolean TtsSetVolume( int voiceVolume) + { + + Log.i(TAG, "TtsSetVolume =" + voiceVolume ); + mService.vocalizerConfigureVolume( voiceVolume); + return true; + } + + //============================================================================================= + // Set the TTS engine property + protected boolean TtsSetRate( int voiceRate) + { + + Log.i(TAG, "TtsSetRate =" + voiceRate ); + mService.vocalizerConfigureRate( voiceRate); + return true; + } + + //============================================================================================= + // Set the TTS engine property + protected boolean TtsSetPitch( int voicePitch) + { + + Log.i(TAG, "TtsSetPitch =" + voicePitch ); + mService.vocalizerConfigurePitch( voicePitch); + return true; + } + + + + + //============================================================================================= + // an ASR is finished, send back to emulator the result through the service + protected boolean onRecognitionFinished( int reliability, String result) + { + + Log.i(TAG, "onRecognitionFinished reliability=" + reliability + " Result=" + result); + mService.sendIntentRecognitionResult( reliability, result ); + return true; + } + + //============================================================================================= + // The ASR recognizer engine state has changes, send back to emulator the current state through the service + protected void onAsrStateChanges( int asrState) + { + Log.i(TAG, "onAsrStateChanges State=" + asrState); + mService.sendIntentAsrStateChanges(asrState); + } + + //============================================================================================= + // An Asr state event should be sent backward to APP through onAsrStateChanges + public boolean onAsrEvent( int event, int value ) + { + if( event == 0) + onAsrStateChanges( value); + + return true; + } + + +} diff --git a/app/src/main/java/com/voixtreme/vxtenginejni/VxtEngineApi.java b/app/src/main/java/com/voixtreme/vxtenginejni/VxtEngineApi.java new file mode 100644 index 0000000..1ef1e3a --- /dev/null +++ b/app/src/main/java/com/voixtreme/vxtenginejni/VxtEngineApi.java @@ -0,0 +1,327 @@ + +// This class is mantained in the VisaulStudio2015 environment and copied to the AS prpject + +package com.voixtreme.vxtenginejni; + +// Comment / uncomment +import com.voixtreme.vocalengine.service.VoiXtremeService; +import com.voixtreme.vxtenginejni.TtsEngineApi; + +import android.media.MediaPlayer; +import android.media.MediaPlayer.OnCompletionListener; + +public class VxtEngineApi extends TtsEngineApi +{ + + + // The constructor should be renamed in each environment + // Comment / uncomment the proper constructor + // + // Constructor for real AS project + public VxtEngineApi(VoiXtremeService service) { + // + // Constructor for testing VS2015 project + //public VxtEngineApi( int service) { + super(service); + } + + //============================================================================================= + //============================================================================================= + // Sub classes - Listeners + //============================================================================================= + //============================================================================================= + + //============================================================================================= + public interface OnPrintListener + { + void OnPrintListenerResult( String strLabel_); + } + + //============================================================================================= + //============================================================================================= + // Private members + //============================================================================================= + //============================================================================================= + + static private VxtEngineApi mTheInstance = null; + + private OnPrintListener mOnPrintListener; + + //============================================================================================= + // Phrase processing (override of TtsEngineApi) + // 1=Speech begins, 2=Speech ends + @Override + public boolean TtsCallback( int action, int id, int asrMode, int ttsMode) + { + // call the native function TtsCallback + nativettscallback( action, id, asrMode, ttsMode); + return true; + } + + //============================================================================================= + //============================================================================================= + // Public methods + //============================================================================================= + //============================================================================================= + + //============================================================================================= + // non native CALLS (public) + //============================================================================================= + + //============================================================================================= + // For legacy nuance logs + public void setOnPrintListener( OnPrintListener listener_ ) + { + mOnPrintListener = listener_; + } + + //============================================================================================= + // Initialize jni and voixtreme + public boolean vxtInitialize() + { + mTheInstance = this; + + InitializeAsr(); + + return true; + } + + //============================================================================================= + // Just test + public boolean vxtTest() + { + mTheInstance = this; + return true; + } + + //============================================================================================= + // Finalize jni and voixtreme + public boolean vxtFinalize() + { + nativefinalize(); + return true; + } + + //============================================================================================= + // Perform a native command from intent or TCP/IP + // This is the tagged command string "xxxx" + public boolean vxtCommand( String voiceCommand) + { + return nativecommand( voiceCommand ); + } + + //============================================================================================= + //============================================================================================= + // Private functions + //============================================================================================= + //============================================================================================= + + //============================================================================================= + // Initialize ASR jni + private boolean InitializeAsr() + { + System.loadLibrary("vocon3200_platform"); + System.loadLibrary("vocon3200_base"); + System.loadLibrary("genericdca"); + System.loadLibrary("vocon3200_asr"); + System.loadLibrary("vocon3200_pron"); + System.loadLibrary("vocon3200_sem"); + System.loadLibrary("vocon3200_sem3"); + System.loadLibrary("vocon3200_gram2"); + System.loadLibrary("pal_core"); + System.loadLibrary("pal_audio"); + System.loadLibrary("vocon_ext_stream"); + System.loadLibrary("vocon_ext_heap"); + System.loadLibrary("asr-jni"); + + String serialNumber="1234567890"; + String rootDirectory= System.getenv("EXTERNAL_STORAGE"); + nativeinitializeasr( rootDirectory, serialNumber); + + return true; + } + + + //============================================================================================= + // Play a beep + private void playBeep(String audioFile) + { + final String myFinalAudio = audioFile; + new Thread() { + public void run() { + + try { + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(myFinalAudio); + mp.prepare(); + mp.start(); + + mp.setOnCompletionListener(new OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + mp.release(); + mp = null; + } + }); + } catch (Exception e) { } + ;} + }.start(); + } + + //============================================================================================= + // native CALLS (public) + //============================================================================================= + + /* A native method that is implemented by the + * 'asr-jni' native library, which is packaged + * with this application. + */ + public native String nativestringFromJNI( int step); + + // ONLY FOR TESTS get the asr result + public native String nativegetresult(); + + // Native to run threaded ASR in a loop TEST ONLY + public native int nativeasr(); + + // Native to perform voice input called by vxtCommand + public native boolean nativecommand( String voiceCommand); + + // Called by tts engine when a TTS event occurs + // 1=Speech begins, 2=Speech ends + public native void nativettscallback( int action, int id, int asr, int tts); + + // Call this method to register the application about ASR events (state, energy) + public native void nativeregisterasrevent( boolean eventState, boolean eventEnergy); + + //============================================================================================= + //============================================================================================= + // CALLBACKS FROM NATIVE + //============================================================================================= + //============================================================================================= + + //============================================================================================= + public static boolean from_native_recogfinished( int reliability, String result) + { + if (null != mTheInstance) + { + mTheInstance.onRecognitionFinished( reliability, result); + return true; + } + return false; + } + + //============================================================================================= + public static boolean from_native_print(String scText) + { + // Log.i(TAG, "In MainActivity.print()! "+s.length); + if (null != mTheInstance) + { + // theInstance.print(new String(s)); + return true; + } + return false; + } + + //============================================================================================= + // to perform a beep by Java + public static boolean from_native_playbeep(String scBeepFullPath) + { + if (null != mTheInstance) + { + mTheInstance.playBeep( scBeepFullPath); + return true; + } + return false; + } + + //============================================================================================= + // to send an intent about ASR engine state + public static boolean from_native_asrevent(int event, int value) + { + if (null != mTheInstance) + { + // here call the method + mTheInstance.onAsrEvent( event, value ); + return true; + } + return false; + } + + //============================================================================================= + // Call the parent function in Tts + // asrMode is ListenOnTts, Nested, TtsOnAsr + // ttsMode is break or append + public static boolean from_native_say( int iId, int asrMode, int ttsMode, String phraseToSay) + { + if (null != mTheInstance) + { + // connected to TTS JAVA parent class + return mTheInstance.TtsSay( iId, asrMode, ttsMode, phraseToSay); + } + return false; + } + + //============================================================================================= + // Call the parent function in Tts + // 0=Keep ASR language configured + // 1=Initialize tts with voice + // 2=Finalize Tts + // 3=isSpeaking + // 4=StopSpeaking + // 5=Set volume + // 6=Set rate + // 7=set pitch + public static boolean from_native_tts_engine_cmd( int action, int iParam, String sParam) + { + if (null != mTheInstance) + { + boolean bRes= false; + // 0=Keep ASR language configured + if( action == 0) + bRes= mTheInstance.TtsSetLanguage( sParam); + // 1=Initialize tts with voice (this command should send an intent) + if( action == 1) + bRes= mTheInstance.TtsInitialize( sParam); + // 2=Finalize Tts + if( action == 2) + bRes= mTheInstance.TtsFinalize(); + // 3=isSpeaking + if( action == 3) + bRes= mTheInstance.TtsIsSpeaking(); + // 4=StopSpeaking + if( action == 4) + bRes= mTheInstance.TtsStopSpeaking(); + // 5=Set volume + if( action == 5) + bRes= mTheInstance.TtsSetVolume( iParam); + // 6=Set rate + if( action == 6) + bRes= mTheInstance.TtsSetRate( iParam); + // 7=set pitch + if( action == 7) + bRes= mTheInstance.TtsSetPitch( iParam); + + + return bRes; + } + return false; + } + + + + + + //============================================================================================= + //============================================================================================= + // native CALLS (private) + //============================================================================================= //--------------------------------------------------------------------------- + //============================================================================================= + + // Init the native lib with root storage path + private native void nativeinitializeasr( String fullPath, String serialNumber ); + + // Finalize the ASR + private native void nativefinalize(); + +} diff --git a/app/src/main/jniLibs/armeabi-v7a/libNuanceVocalizer.so b/app/src/main/jniLibs/armeabi-v7a/libNuanceVocalizer.so new file mode 100644 index 0000000..212eae4 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libNuanceVocalizer.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libasr-jni.so b/app/src/main/jniLibs/armeabi-v7a/libasr-jni.so new file mode 100644 index 0000000..1b19d95 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libasr-jni.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libgenericdca.so b/app/src/main/jniLibs/armeabi-v7a/libgenericdca.so new file mode 100644 index 0000000..3445d99 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libgenericdca.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libpal_audio.so b/app/src/main/jniLibs/armeabi-v7a/libpal_audio.so new file mode 100644 index 0000000..e3d47e4 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libpal_audio.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libpal_core.so b/app/src/main/jniLibs/armeabi-v7a/libpal_core.so new file mode 100644 index 0000000..694f968 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libpal_core.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_asr.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_asr.so new file mode 100644 index 0000000..f20419f Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_asr.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_base.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_base.so new file mode 100644 index 0000000..b3e2aaf Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_base.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_gram2.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_gram2.so new file mode 100644 index 0000000..faa1d8e Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_gram2.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_platform.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_platform.so new file mode 100644 index 0000000..3353589 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_platform.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_pron.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_pron.so new file mode 100644 index 0000000..ed9f541 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_pron.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_sem.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_sem.so new file mode 100644 index 0000000..2312d67 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_sem.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon3200_sem3.so b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_sem3.so new file mode 100644 index 0000000..abadcd5 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon3200_sem3.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_asr2sem.so b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_asr2sem.so new file mode 100644 index 0000000..f7162b0 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_asr2sem.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_audioin.so b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_audioin.so new file mode 100644 index 0000000..ddb5374 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_audioin.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_heap.so b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_heap.so new file mode 100644 index 0000000..456ceb4 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_heap.so differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_stream.so b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_stream.so new file mode 100644 index 0000000..bb52cf9 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libvocon_ext_stream.so differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e6c6ada --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/mipmap-hdpi/Thumbs.db b/app/src/main/res/mipmap-hdpi/Thumbs.db new file mode 100644 index 0000000..1aec9e8 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/Thumbs.db differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..164a647 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/Thumbs.db b/app/src/main/res/mipmap-mdpi/Thumbs.db new file mode 100644 index 0000000..8d74605 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/Thumbs.db differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..7bb0f30 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/Thumbs.db b/app/src/main/res/mipmap-xhdpi/Thumbs.db new file mode 100644 index 0000000..aa10624 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/Thumbs.db differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..45b9a93 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/Thumbs.db b/app/src/main/res/mipmap-xxhdpi/Thumbs.db new file mode 100644 index 0000000..7ed6cdb Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/Thumbs.db differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..c93687a Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/Thumbs.db b/app/src/main/res/mipmap-xxxhdpi/Thumbs.db new file mode 100644 index 0000000..244ef97 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/Thumbs.db differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..cd00a47 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ea04e7 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,2 @@ + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..ba17619 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,13 @@ + + VoiXtreme + + Engine initialized + Engine is ready + Engine is speaking + Engine is paused + Engine is uninitialized + Engine is in init error + + + VoxPrinter boot Receiver + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..8ea9057 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/app/src/test/java/com/voixtreme/vocalengine/ExampleUnitTest.java b/app/src/test/java/com/voixtreme/vocalengine/ExampleUnitTest.java new file mode 100644 index 0000000..3b6062b --- /dev/null +++ b/app/src/test/java/com/voixtreme/vocalengine/ExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.voixtreme.vocalengine; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * To work on unit tests, switch the Test Artifact in the Build Variants view. + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..74b2ab0 --- /dev/null +++ b/build.gradle @@ -0,0 +1,23 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.3' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1d3591c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2bc4644 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Aug 26 08:01:56 CEST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app'