- Create
New Project - In
New Projectview. SelectEmpty Views Activityand pressNext - In
New Project,Empty Views Activityview.- Name: UnityPlugin
- Packagename: com.trenrod.unity.unityplugin <-- Use your own here
- Save location: X:\dev\UnityAndroidTTSPlugin\UnityPlugin
- Minimum SDK: API 23 ("Marshmallow"; Android 6.0) <-- This is required by Unity 6
- Select
Finish - Wait till project has been finally set up.
Notes:
- Using
Empty Activityshowed Errors after creation. Maybe this combination is not supported.
Alt+\->Run->Run app- Wait till emolator is opened
- Wait till app is started
- Check if
Hello worldis displayed
This module will then be exported as AAR file and used in unity.
Alt-\->File->New->New Module...- In
Create new Module. SelectAndroid librarby - On the right side configute:
- Module name: AndroidTTSPlugin
- Package name: com.trenrod.unity.AndroidTTSPlugin
- Language: Kotlin
- Minimum SDK: API 23 ("Marshmallow"; Android 6.0) <-- This is required by Unity 6
- Build Configuration Language: Kotlin DSL ...
- Select
Finish - Wait till project has been finally set up.
- Open Terminal (
Alt+F12) - Test if build is working type:
.\gradlew build -x testto run build without tests. - Test if module can be created type:
.\gradlew assembleDebug - Check if
AndroidTTSPlugin-debug.aarhas been created- Still in terminal execute
explorer . - Goto
AndroidTTSPlugin\build\outputs\aarlook forAndroidTTSPlugin-debug.aar
- Still in terminal execute
We will create a Class called AndroidTTSPlugin inside AndroidTTSPlugin which offers a function readText.
- As requested in the API reference TextToSpeech declare
android.speech.tts.TextToSpeech.Engine#INTENT_ACTION_TTS_SERVICEin the queries element ofUnityAndroidTTSPlugin\UnityPlugin\AndroidTTSPlugin\src\main\AndroidManifest.xml. - The result should look like this file: AndroidManifest.xml
- Create class to use TTS.
Right-ClickonAndroidTTSPlugin -> kotlin+java -> com.trenrod.unity.androidttspluginon the left side file explorer view. ThenNew->Kotlin class/file. - In
New Kotlin Class/File. SelectClassand name itTTSPlugin. - Checkout the detailed comments in TTSPlugin about the implementation.
We will adjust the initial Empty View Actity to use our created Module to test it.
This allows us to quickly test our Module before implementing the Unity part.
- Make the module available in our Main App (UnityPlugin/app)
- Open
Project structureview withAlt+\ -> File -> Project structure - Select
Dependencies. - Select
appunderModules. - Select
+underDeclared Dependencies - Select
3 Module Dependency - In the
Add Module DependencyView. SelectAndroidTTSPluginand pressOK - Back in
Project structureview pressApplyand once applied pressOK
- Open
- Checkout simple UI (logview and button) to allow testing our Module activity_main.xml
- Checkout the detailed comments in activity_main.xml on how to use the Module.