app/src/main/java/com/example/jarvis_stts/JarviceService.kt aktualisiert
This commit is contained in:
@@ -122,11 +122,21 @@ class JarvisService : Service(), RecognitionListener {
|
|||||||
|
|
||||||
private fun resumeListening() {
|
private fun resumeListening() {
|
||||||
if (voskModel == null) return
|
if (voskModel == null) return
|
||||||
Log.d("JARVIS", "Service: Starte Zuhören")
|
|
||||||
voskService?.stop()
|
voskService?.stop()
|
||||||
|
|
||||||
// Die Liste klein halten ist gut, aber wir brauchen den exakten Treffer
|
// Wir fügen häufige deutsche Wörter und phonetische Ähnlichkeiten hinzu
|
||||||
val rec = Recognizer(voskModel, 16000.0f, "[\"jarvis\", \"[unk]\"]")
|
// Diese dienen als "Blitzableiter" für Fehlalarm
|
||||||
|
val grammar = "[" +
|
||||||
|
"\"jarvis\", " + // Wake-Words
|
||||||
|
"\"ja\", \"nein\", \"und\", \"der\", \"die\", \"das\", " + // Füllwörter
|
||||||
|
"\"service\", \"imbiss\", \"harnisch\", \"garvis\", \"fertig\", " + // Phonetische Fallen
|
||||||
|
"\"[unk]\"" +
|
||||||
|
"]"
|
||||||
|
|
||||||
|
val rec = Recognizer(voskModel, 16000.0f, grammar)
|
||||||
|
// Wir erlauben dem Recognizer, weniger "nervös" zu sein
|
||||||
|
// Ein höherer Wert für Small-Models kann helfen
|
||||||
|
rec.setThreshold(0.5) // Falls deine Vosk-Version das unterstützt
|
||||||
voskService = SpeechService(rec, 16000.0f)
|
voskService = SpeechService(rec, 16000.0f)
|
||||||
voskService?.startListening(this)
|
voskService?.startListening(this)
|
||||||
|
|
||||||
@@ -134,37 +144,37 @@ class JarvisService : Service(), RecognitionListener {
|
|||||||
updateNotification("Warte auf 'Jarvis'...")
|
updateNotification("Warte auf 'Jarvis'...")
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Vosk Listener ---
|
// In onPartialResult machen wir jetzt GAR NICHTS mehr, um Fehlalarme zu vermeiden
|
||||||
override fun onPartialResult(hypothesis: String) {
|
override fun onPartialResult(hypothesis: String) {}
|
||||||
|
|
||||||
|
// Wir nutzen nur noch onResult für den echten Check
|
||||||
|
override fun onResult(hypothesis: String) {
|
||||||
if (isInteracting) return
|
if (isInteracting) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val json = JSONObject(hypothesis)
|
val json = JSONObject(hypothesis)
|
||||||
// Bei onPartialResult heißt das Feld "partial"
|
val recognizedText = json.optString("text").lowercase().trim()
|
||||||
val partialText = json.optString("partial").lowercase().trim()
|
|
||||||
|
|
||||||
// Wir reagieren NUR, wenn das Wort exakt "jarvis" ist
|
// Nur wenn das erkannte Wort EXAKT Jarvis oder Computer ist
|
||||||
// Das verhindert, dass Wörter wie "Service" oder "Nachtisch" triggern
|
if (recognizedText == "jarvis") {
|
||||||
if (partialText == "jarvis" ) {
|
Log.d("JARVIS", "Sicheres Wake-Word erkannt: $recognizedText")
|
||||||
Log.d("JARVIS", "Service: WAKE WORD EXAKT ERKANNT: $partialText")
|
triggerJarvis()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("JARVIS", "Fehler: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun triggerJarvis() {
|
||||||
isInteracting = true
|
isInteracting = true
|
||||||
// Ein kurzer haptischer Feedback-Vibe wäre hier cool (optional)
|
|
||||||
|
|
||||||
pauseListening()
|
pauseListening()
|
||||||
|
|
||||||
val intent = Intent(this, MainActivity::class.java).apply {
|
val intent = Intent(this, MainActivity::class.java).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||||
putExtra("WAKE_WORD_TRIGGERED", true)
|
putExtra("WAKE_WORD_TRIGGERED", true)
|
||||||
}
|
}
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("JARVIS", "Fehler beim Parsen des PartialResults: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResult(hypothesis: String) {}
|
|
||||||
override fun onFinalResult(hypothesis: String) {}
|
override fun onFinalResult(hypothesis: String) {}
|
||||||
override fun onError(e: Exception) { Log.e("JARVIS", "Service Error: ${e.message}") }
|
override fun onError(e: Exception) { Log.e("JARVIS", "Service Error: ${e.message}") }
|
||||||
override fun onTimeout() {}
|
override fun onTimeout() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user