app/src/main/java/com/example/jarvis_stts/MainActivity.kt aktualisiert
This commit is contained in:
@@ -116,18 +116,34 @@ class MainActivity : AppCompatActivity(), RecognitionListener, TextToSpeech.OnIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Vosk RecognitionListener ---
|
// 1. Hilfsfunktion zum sauberen Filtern des Wortes
|
||||||
override fun onPartialResult(hypothesis: String) {
|
private fun extractText(json: String): String {
|
||||||
// Diese Zeile zeigt dir live im Logcat, was Vosk gerade verstanden hat:
|
return json.substringAfter(": \"").substringBefore("\"")
|
||||||
Log.d("JARVIS", "Vosk hört: $hypothesis")
|
}
|
||||||
|
|
||||||
// Testweise auf "computer" hören
|
override fun onPartialResult(hypothesis: String) {
|
||||||
if (hypothesis.contains("computer", ignoreCase = true)) {
|
val recognizedText = extractText(hypothesis)
|
||||||
voskService?.stop()
|
Log.d("JARVIS", "Vosk hört: $recognizedText")
|
||||||
|
|
||||||
|
if (recognizedText.contains("computer") || recognizedText.contains("jarvis")) {
|
||||||
|
voskService?.pause() // Pause statt Stop ist oft schneller
|
||||||
startVoiceInput()
|
startVoiceInput()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Im SpeechRecognizerLauncher
|
||||||
|
private val speechRecognizerLauncher = registerForActivityResult(
|
||||||
|
ActivityResultContracts.StartActivityForResult()
|
||||||
|
) { result ->
|
||||||
|
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||||
|
val spokenText = result.data!!.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.get(0) ?: ""
|
||||||
|
tvStatus.text = "Ich: $spokenText"
|
||||||
|
webSocket?.send(spokenText)
|
||||||
|
}
|
||||||
|
// WICHTIG: Warte kurz oder prüfe, ob TTS spricht, bevor du das hier machst:
|
||||||
|
voskService?.resume()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResult(hypothesis: String) {}
|
override fun onResult(hypothesis: String) {}
|
||||||
override fun onFinalResult(hypothesis: String) {}
|
override fun onFinalResult(hypothesis: String) {}
|
||||||
override fun onError(e: Exception) { Log.e("JARVIS", "Vosk Error: ${e.message}") }
|
override fun onError(e: Exception) { Log.e("JARVIS", "Vosk Error: ${e.message}") }
|
||||||
|
|||||||
Reference in New Issue
Block a user