app/src/main/java/com/example/jarvis_stts/MainActivity.kt aktualisiert
This commit is contained in:
@@ -43,10 +43,16 @@ class MainActivity : AppCompatActivity(), TextToSpeech.OnInitListener {
|
|||||||
if (result.resultCode == RESULT_OK && result.data != null) {
|
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||||
val spokenText = result.data!!.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.get(0) ?: ""
|
val spokenText = result.data!!.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.get(0) ?: ""
|
||||||
tvStatus.text = "Ich: $spokenText"
|
tvStatus.text = "Ich: $spokenText"
|
||||||
|
|
||||||
|
if (webSocket != null) {
|
||||||
webSocket?.send(spokenText)
|
webSocket?.send(spokenText)
|
||||||
// Hier warten wir auf den Server. Der Service bleibt pausiert.
|
Log.d("JARVIS", "Sende an Server: $spokenText")
|
||||||
|
} else {
|
||||||
|
tvStatus.text = "Fehler: Nicht verbunden!"
|
||||||
|
// Falls nicht verbunden, Dienst wieder starten
|
||||||
|
tellServiceTo(JarvisService.ACTION_RESUME)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Abbruch oder Fehler -> Service soll wieder zuhören
|
|
||||||
tellServiceTo(JarvisService.ACTION_RESUME)
|
tellServiceTo(JarvisService.ACTION_RESUME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,6 +84,13 @@ class MainActivity : AppCompatActivity(), TextToSpeech.OnInitListener {
|
|||||||
val btnSpeak = findViewById<Button>(R.id.btnSpeak)
|
val btnSpeak = findViewById<Button>(R.id.btnSpeak)
|
||||||
|
|
||||||
tts = TextToSpeech(this, this)
|
tts = TextToSpeech(this, this)
|
||||||
|
val savedUrl = prefs.getString("server_url", "")
|
||||||
|
etUrl.setText(savedUrl)
|
||||||
|
|
||||||
|
// AUTOMATISCH VERBINDEN, falls eine URL gespeichert ist
|
||||||
|
if (!savedUrl.isNullOrEmpty()) {
|
||||||
|
connectToServer(savedUrl)
|
||||||
|
}
|
||||||
|
|
||||||
val prefs = getSharedPreferences("JarvisPrefs", MODE_PRIVATE)
|
val prefs = getSharedPreferences("JarvisPrefs", MODE_PRIVATE)
|
||||||
etUrl.setText(prefs.getString("server_url", ""))
|
etUrl.setText(prefs.getString("server_url", ""))
|
||||||
|
|||||||
Reference in New Issue
Block a user