-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
769 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.71 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
android/src/com/bombbird/terminalcontrol/AndroidBrowserOpener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.bombbird.terminalcontrol | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.net.Uri | ||
import com.bombbird.terminalcontrol.utilities.BrowserInterface | ||
|
||
class AndroidBrowserOpener(private val activity: Activity): BrowserInterface { | ||
override fun openBrowser(link: String) { | ||
val intent = Intent(Intent.ACTION_VIEW).apply { | ||
data = Uri.parse(link) | ||
} | ||
|
||
activity.startActivity(intent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
android/src/com/bombbird/terminalcontrol/AndroidTextToSpeechManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.bombbird.terminalcontrol | ||
|
||
import android.content.ActivityNotFoundException | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.speech.tts.TextToSpeech.OnInitListener | ||
import android.speech.tts.Voice | ||
import com.badlogic.gdx.Gdx | ||
import com.badlogic.gdx.backends.android.AndroidApplication | ||
import com.badlogic.gdx.utils.Array | ||
import com.bombbird.terminalcontrol.sounds.TextToSpeechInterface | ||
import java.util.* | ||
|
||
open class AndroidTextToSpeechManager : AndroidApplication(), OnInitListener, TextToSpeechInterface { | ||
companion object { | ||
const val ACT_CHECK_TTS_DATA = 1000 | ||
const val ACT_INSTALL_TTS_DATA = 1001 | ||
} | ||
|
||
private var tts: android.speech.tts.TextToSpeech? = null | ||
lateinit var toastManager: AndroidToastManager | ||
|
||
private val voiceArray = Array<String>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
toastManager = AndroidToastManager(this as AndroidLauncher) | ||
} | ||
|
||
/** Performs relevant actions after receiving status for TTS data check */ | ||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
try { | ||
if (requestCode == ACT_CHECK_TTS_DATA) { | ||
if (resultCode == android.speech.tts.TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { | ||
//Data exists, so we instantiate the TTS engine | ||
tts = android.speech.tts.TextToSpeech(this, this) | ||
} else { | ||
//Data is missing, so we start the TTS installation process | ||
val installIntent = Intent() | ||
installIntent.action = android.speech.tts.TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA | ||
startActivityForResult(installIntent, ACT_INSTALL_TTS_DATA) | ||
} | ||
} else if (requestCode == ACT_INSTALL_TTS_DATA) { | ||
val ttsIntent = Intent() | ||
ttsIntent.action = android.speech.tts.TextToSpeech.Engine.ACTION_CHECK_TTS_DATA | ||
startActivityForResult(ttsIntent, ACT_CHECK_TTS_DATA) | ||
} | ||
} catch (e: ActivityNotFoundException) { | ||
toastManager.initTTSFail() | ||
} | ||
} | ||
|
||
/** Sets initial properties after initialisation of TTS is complete */ | ||
override fun onInit(status: Int) { | ||
if (status == android.speech.tts.TextToSpeech.SUCCESS) { | ||
if (tts != null) { | ||
val result = tts?.setLanguage(Locale.ENGLISH) | ||
if (result == android.speech.tts.TextToSpeech.LANG_MISSING_DATA || result == android.speech.tts.TextToSpeech.LANG_NOT_SUPPORTED) { | ||
toastManager.ttsLangNotSupported() | ||
} else { | ||
Gdx.app.log("Text to Speech", "TTS initialized successfully") | ||
tts?.setSpeechRate(1.7f) | ||
loadVoices() | ||
} | ||
} | ||
} else { | ||
toastManager.initTTSFail() | ||
Gdx.app.log("Text to Speech", "TTS initialization failed") | ||
} | ||
} | ||
|
||
/** Stops, destroys TTS instance */ | ||
override fun onDestroy() { | ||
tts?.stop() | ||
tts?.shutdown() | ||
super.onDestroy() | ||
} | ||
|
||
/** Says the text depending on API level */ | ||
override fun sayText(text: String, voice: String) { | ||
if (tts == null) return | ||
tts?.voice = Voice(voice, Locale.ENGLISH, Voice.QUALITY_HIGH, Voice.LATENCY_NORMAL, false, null) | ||
tts?.speak(text, android.speech.tts.TextToSpeech.QUEUE_ADD, null, null) | ||
} | ||
|
||
/** Stops all current and subsequent speeches */ | ||
override fun cancel() { | ||
tts?.stop() | ||
} | ||
|
||
/** Checks if the voice is available, returns original voice if it is, else returns a random voice from all available voices */ | ||
override fun checkAndUpdateVoice(voice: String): String { | ||
if (voiceArray.contains(voice)) return voice | ||
return voiceArray.random() ?: voice | ||
} | ||
|
||
/** Gets the names of all the applicable voices available on the device */ | ||
override fun loadVoices() { | ||
try { | ||
if (tts?.voices?.isEmpty() != false) return | ||
} catch (e: Exception) { | ||
return | ||
} | ||
tts?.voices?.let { | ||
for (available in it) { | ||
if ("en" == available.name.substring(0, 2)) { | ||
voiceArray.add(available.name) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.