Skip to content

Commit

Permalink
Merge branch 'desktop_tts'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombbird2001 committed Jan 30, 2021
2 parents 5ab2a57 + 43ec34b commit 6dff8e5
Show file tree
Hide file tree
Showing 53 changed files with 769 additions and 457 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ Thumbs.db
!/ios-moe/xcode/*.xcodeproj/xcshareddata
!/ios-moe/xcode/*.xcodeproj/project.pbxproj
/ios-moe/xcode/native/
/android/assetsLite/log/
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="com.bombbird.terminalcontrol.TextToSpeechManager"
android:name="com.bombbird.terminalcontrol.AndroidTextToSpeechManager"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize">
Expand Down
Binary file added android/assetsLite/tts/balcon.exe
Binary file not shown.
Binary file added android/assetsLite/tts/libsamplerate.dll
Binary file not shown.
1 change: 1 addition & 0 deletions android/assetsLite/tts/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.71
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {
assets.srcDirs = ['assetsFull']
res.srcDirs = ['resFull']
}
main.assets.filter.exclude '**/tts/*.*'
}

compileOptions {
Expand Down
16 changes: 16 additions & 0 deletions android/src/com/bombbird/terminalcontrol/AndroidBrowserOpener.kt
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)
}
}
4 changes: 2 additions & 2 deletions android/src/com/bombbird/terminalcontrol/AndroidLauncher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.io.IOException
const val OPEN_SAVE_FILE = 9
const val CREATE_SAVE_FILE = 10

class AndroidLauncher : TextToSpeechManager(), ExternalFileHandler {
class AndroidLauncher : AndroidTextToSpeechManager(), ExternalFileHandler {
private var loadGameScreen: LoadGameScreen? = null
private var save: JSONObject? = null
//private PlayGamesManager playGamesManager;
Expand All @@ -26,7 +26,7 @@ class AndroidLauncher : TextToSpeechManager(), ExternalFileHandler {
config.numSamples = 0
config.useAccelerometer = false
config.useCompass = false
initialize(TerminalControl(this, toastManager, object : DiscordManager {}, this), config)
initialize(TerminalControl(this, toastManager, object : DiscordManager {}, this, AndroidBrowserOpener(this)), config)
val ttsIntent = Intent()
ttsIntent.action = TextToSpeech.Engine.ACTION_CHECK_TTS_DATA
try {
Expand Down
112 changes: 112 additions & 0 deletions android/src/com/bombbird/terminalcontrol/AndroidTextToSpeechManager.kt
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)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException
import com.bombbird.terminalcontrol.utilities.ToastManager
import java.io.IOException

class ToastManager(private val androidLauncher: AndroidLauncher) : ToastManager {
class AndroidToastManager(private val androidLauncher: AndroidLauncher) : ToastManager {
override fun saveFail(e: GdxRuntimeException) {
var error = androidLauncher.resources.getString(R.string.Save_fail)
val nextE = e.cause
Expand Down
19 changes: 14 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.4.30-M1'
ext.kotlin_version = '1.4.30-RC'

repositories {
mavenLocal()
Expand All @@ -21,12 +21,12 @@ buildscript {
allprojects {
apply plugin: "idea"

version = '1.5.2014.2'
version = '1.5.2101.1'
ext {
appName = "Terminal Control"
gdxVersion = '1.9.12'
roboVMVersion = '2.3.11'
versionCode = 70
gdxVersion = '1.9.13'
roboVMVersion = '2.3.12'
versionCode = 71
}

repositories {
Expand All @@ -51,6 +51,15 @@ project(":desktop") {
implementation "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
implementation "club.minnced:java-discord-rpc:2.0.2"
implementation "club.minnced:discord-rpc-release:v3.4.0"
implementation "de.dfki.mary:marytts-runtime:5.2"
implementation "de.dfki.mary:marytts-lang-en:5.2"
implementation "de.dfki.mary:voice-cmu-slt-hsmm:5.2"
implementation "de.dfki.mary:voice-cmu-rms-hsmm:5.2"
implementation "de.dfki.mary:voice-cmu-bdl-hsmm:5.2"
implementation "de.dfki.mary:voice-dfki-prudence-hsmm:5.2"
implementation "de.dfki.mary:voice-dfki-poppy-hsmm:5.2"
implementation "de.dfki.mary:voice-dfki-spike-hsmm:5.2"
implementation "de.dfki.mary:voice-dfki-obadiah-hsmm:5.2"
}
}

Expand Down
24 changes: 14 additions & 10 deletions core/src/com/bombbird/terminalcontrol/TerminalControl.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bombbird.terminalcontrol

import com.badlogic.gdx.Application
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
Expand All @@ -12,7 +11,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Window
import com.bombbird.terminalcontrol.entities.aircrafts.Emergency
import com.bombbird.terminalcontrol.screens.MainMenuScreen
import com.bombbird.terminalcontrol.screens.gamescreen.RadarScreen
import com.bombbird.terminalcontrol.sounds.TextToSpeech
import com.bombbird.terminalcontrol.sounds.TextToSpeechInterface
import com.bombbird.terminalcontrol.sounds.TextToSpeechManager
import com.bombbird.terminalcontrol.utilities.BrowserInterface
import com.bombbird.terminalcontrol.utilities.DiscordManager
import com.bombbird.terminalcontrol.utilities.Fonts
import com.bombbird.terminalcontrol.utilities.RenameManager.loadMaps
Expand All @@ -21,7 +22,7 @@ import com.bombbird.terminalcontrol.utilities.files.ExternalFileHandler
import com.bombbird.terminalcontrol.utilities.files.FileLoader
import com.bombbird.terminalcontrol.utilities.files.GameSaver

class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordManager: DiscordManager, externalFileHandler: ExternalFileHandler) : Game() {
class TerminalControl(tts: TextToSpeechInterface, toastManager: ToastManager, discordManager: DiscordManager, externalFileHandler: ExternalFileHandler, browserInterface: BrowserInterface) : Game() {
companion object {
//Get screen size
var WIDTH = 0
Expand All @@ -42,8 +43,9 @@ class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordMana
private lateinit var buttonAtlas: TextureAtlas
lateinit var skin: Skin

//Text-to-speech (for Android only)
lateinit var tts: TextToSpeech
//Text-to-speech
lateinit var ttsManager: TextToSpeechManager
lateinit var tts: TextToSpeechInterface

//Toast (for Android only)
lateinit var toastManager: ToastManager
Expand All @@ -55,6 +57,9 @@ class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordMana
//External file loader
lateinit var externalFileHandler: ExternalFileHandler

//Browser interface
lateinit var browserInterface: BrowserInterface

//Default settings
var trajectorySel = 0
var pastTrajTime = 0
Expand Down Expand Up @@ -91,7 +96,7 @@ class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordMana
pastTrajTime = -1
weatherSel = RadarScreen.Weather.LIVE
stormNumber = 0
soundSel = defaultSoundSetting
soundSel = 2
sendAnonCrash = true
increaseZoom = false
saveInterval = 60
Expand Down Expand Up @@ -121,7 +126,7 @@ class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordMana
"false" -> RadarScreen.Weather.RANDOM //Old format
else -> RadarScreen.Weather.valueOf(settings.getString("weather")) //New format
}
soundSel = settings.optInt("sound", soundSel)
soundSel = settings.optInt("sound", 2)
stormNumber = settings.optInt("stormNumber", 0)
sendAnonCrash = settings.optBoolean("sendCrash", true)
emerChance = if (settings.isNull("emerChance")) {
Expand Down Expand Up @@ -151,9 +156,6 @@ class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordMana
GameSaver.saveSettings()
}

val defaultSoundSetting: Int
get() = if (Gdx.app.type == Application.ApplicationType.Android) 2 else 1

fun loadVersionInfo() {
val info = Gdx.files.internal("game/type.type").readString().split(" ".toRegex()).toTypedArray()
full = "lite" != info[0]
Expand All @@ -180,8 +182,10 @@ class TerminalControl(tts: TextToSpeech, toastManager: ToastManager, discordMana
Companion.toastManager = toastManager
Companion.discordManager = discordManager
Companion.externalFileHandler = externalFileHandler
Companion.browserInterface = browserInterface
loadedDiscord = false
useDiscord = false
ttsManager = TextToSpeechManager()
}

private fun loadDialogSkin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ abstract class Aircraft : Actor {
isSilenced = false
emergency = Emergency(this, radarScreen.emerChance)
radarScreen.wakeManager.addAircraft(callsign)
voice = TerminalControl.tts.getRandomVoice()
voice = TerminalControl.tts.checkAndUpdateVoice("")
trajectory = Trajectory(this)
isTrajectoryConflict = false
isTrajectoryTerrainConflict = false
Expand Down Expand Up @@ -427,7 +427,7 @@ abstract class Aircraft : Actor {
radarGs = save.getDouble("radarGs").toFloat()
radarAlt = save.getDouble("radarAlt").toFloat()
radarVs = save.getDouble("radarVs").toFloat()
voice = save.optString("voice", TerminalControl.tts.getRandomVoice())
voice = TerminalControl.tts.checkAndUpdateVoice(save.optString("voice", ""))
trajectory = Trajectory(this)
isTrajectoryConflict = false
isTrajectoryTerrainConflict = false
Expand Down
Loading

0 comments on commit 6dff8e5

Please sign in to comment.