app/src/main/java/com/example/jarvis_stts/MainActivity.kt aktualisiert
This commit is contained in:
@@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity(), RecognitionListener, TextToSpeech.OnIn
|
||||
private var voskModel: Model? = null
|
||||
private val client = OkHttpClient()
|
||||
private var webSocket: WebSocket? = null
|
||||
private var isInteracting = false
|
||||
|
||||
// TTS Stimmen
|
||||
private var availableVoices = mutableListOf<Voice>()
|
||||
@@ -53,6 +54,7 @@ class MainActivity : AppCompatActivity(), RecognitionListener, TextToSpeech.OnIn
|
||||
}
|
||||
|
||||
// Vosk wieder starten, nachdem Google fertig ist
|
||||
isInteracting = false
|
||||
startVosk()
|
||||
}
|
||||
|
||||
@@ -141,14 +143,16 @@ class MainActivity : AppCompatActivity(), RecognitionListener, TextToSpeech.OnIn
|
||||
|
||||
// --- Vosk RecognitionListener ---
|
||||
override fun onPartialResult(hypothesis: String) {
|
||||
val recognizedText = extractText(hypothesis)
|
||||
Log.d("JARVIS", "Vosk hört: $recognizedText")
|
||||
if (isInteracting) return // Wenn wir schon dabei sind, ignoriere weiteres
|
||||
|
||||
// Wake-Word Check
|
||||
if (recognizedText.contains("computer", true) || recognizedText.contains("jarvis", true)) {
|
||||
Log.d("JARVIS", "Wake-Word erkannt!")
|
||||
voskService?.stop() // Stoppen, um Mikrofon für Google freizugeben
|
||||
val recognizedText = extractText(hypothesis)
|
||||
if (recognizedText.contains("jarvis", true)) {
|
||||
isInteracting = true // Sperre setzen
|
||||
voskService?.stop()
|
||||
|
||||
tvStatus.postDelayed({
|
||||
startVoiceInput()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,13 +174,14 @@ class MainActivity : AppCompatActivity(), RecognitionListener, TextToSpeech.OnIn
|
||||
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
|
||||
putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
||||
putExtra(RecognizerIntent.EXTRA_LANGUAGE, "de-DE")
|
||||
putExtra(RecognizerIntent.EXTRA_PROMPT, "Ich höre...")
|
||||
putExtra(RecognizerIntent.EXTRA_PROMPT, "Ich höre dir zu...")
|
||||
// Diese Zeile hilft, dass Google nicht zu früh abbricht:
|
||||
putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_MILLIS, 2000L)
|
||||
}
|
||||
try {
|
||||
speechRecognizerLauncher.launch(intent)
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(this, "Google Spracheingabe nicht verfügbar", Toast.LENGTH_SHORT).show()
|
||||
startVosk() // Falls Google scheitert, Vosk wieder an
|
||||
startVosk()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user