RecognitionListener Samsung Galaxy Watch 4

81 views Asked by At

I faced with issue on samsung watch 4 with speech listener.

Listener Service

    class SpeechListener : LifecycleService(), RecognitionListener {
                    private lateinit var speechRecognizer: SpeechRecognizer
            
            override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
                  
                    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,         ComponentName.unflattenFromString("com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService")
                    )
                    speechRecognizer = SpeechRecognizer.createOnDeviceSpeechRecognizer(this)
                    speechRecognizer.setRecognitionListener(this)
            
                    val voice = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
                    voice.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
                    voice.putExtra(
                        RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
                    )
                    voice.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true)
            
                    speechRecognizer.startListening(voice)
            
                    startForeground(this)
            
                    return super.onStartCommand(intent, flags, startId)
                }
    
    override fun onResults(results: Bundle?) {
            val matches = results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
            Log.i(">>>>>>>>> SPOKEN TEXT ", matches!![0])
            
                }
}

Main Activity

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        val navController = findNavController(R.id.nav_host_fragment_content_main)

        val speechIntent = Intent(this, SpeechListener::class.java)
        startForegroundService(speechIntent)
    }
}

AndroidManifest.xml

<queries>
        <package android:name="com.google.android.googlequicksearchbox"/>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>

I get error:

E/SpeechRecognizer: no selected voice recognition service

Some suggestions, please)

0

There are 0 answers