app/src/main/java/com/example/jarvis_stts/JarvisService.kt aktualisiert

This commit is contained in:
2026-03-11 15:26:04 +00:00
parent be504a6135
commit 209571a5d1

View File

@@ -8,6 +8,7 @@ import org.vosk.Recognizer
import org.vosk.android.SpeechService import org.vosk.android.SpeechService
import org.vosk.android.RecognitionListener import org.vosk.android.RecognitionListener
import java.io.IOException import java.io.IOException
import java.io.File
class JarvisService : Service(), RecognitionListener { class JarvisService : Service(), RecognitionListener {
@@ -20,19 +21,21 @@ class JarvisService : Service(), RecognitionListener {
private fun setupVosk() { private fun setupVosk() {
try { try {
// Der Pfad muss zum Ordner zeigen, in den du das Modell entpackt hast // MainActivity entpackt nach "model", also greifen wir hier darauf zu:
val modelPath = getExternalFilesDir(null)?.absolutePath + "/model-de" val modelPath = File(filesDir, "model").absolutePath
val model = Model(modelPath) val model = Model(modelPath)
// WICHTIG: Wir limitieren den Recognizer auf das Wake-Word "jarvis" // WICHTIG: Nutze hier "computer" ODER "jarvis",
// Das erhöht die Erkennungsrate massiv! // je nachdem was du in der MainActivity definiert hast.
val recognizer = Recognizer(model, 16000f, "[\"jarvis\", \"[unk]\"]") val recognizer = Recognizer(model, 16000f, "[\"computer\", \"jarvis\", \"[unk]\"]")
speechService = SpeechService(recognizer, 16000f) speechService = SpeechService(recognizer, 16000f)
speechService?.startListening(this) speechService?.startListening(this)
Log.d("JARVIS", "Service: Vosk hört jetzt zu...")
} catch (e: IOException) { } catch (e: Exception) {
e.printStackTrace() Log.e("JARVIS", "Service: Fehler beim Laden des Modells: ${e.message}")
} }
} }