How can I use speech recognition without the annoying dialog in android phones

前端 未结 4 2416
囚心锁ツ
囚心锁ツ 2020-11-22 14:47

Is this possible without modify the android APIs? I\'ve found a article about this. There\'s one a comment that I should do modifications to the android APIs. But it didn\'

4条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 15:39

    I end up making Github project to convert Text to speech and speech to text without annoying dialog,

    https://github.com/hiteshsahu/Android-TTS-STT/tree/master/app/src/main/java/com/hiteshsahu/stt_tts/translation_engine

     //SPEECH TO TEXT DEMO
        speechToText.setOnClickListener({ view ->
    
            Snackbar.make(view, "Speak now, App is listening", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show()
    
            TranslatorFactory
                    .instance
                    .with(TranslatorFactory.TRANSLATORS.SPEECH_TO_TEXT,
                            object : ConversionCallback {
                                override fun onSuccess(result: String) {
                                    sttOutput.text = result
                                }
    
                                override fun onCompletion() {
                                }
    
                                override fun onErrorOccurred(errorMessage: String) {
                                    erroConsole.text = "Speech2Text Error: $errorMessage"
                                }
    
                            }).initialize("Speak Now !!", this@HomeActivity)
    
        })
    
    
        //TEXT TO SPEECH DEMO
        textToSpeech.setOnClickListener({ view ->
    
            val stringToSpeak :String = ttsInput.text.toString()
    
            if (null!=stringToSpeak &&  stringToSpeak.isNotEmpty()) {
    
                TranslatorFactory
                        .instance
                        .with(TranslatorFactory.TRANSLATORS.TEXT_TO_SPEECH,
                                object : ConversionCallback {
                                    override fun onSuccess(result: String) {
                                    }
    
                                    override fun onCompletion() {
                                    }
    
                                    override fun onErrorOccurred(errorMessage: String) {
                                        erroConsole.text = "Text2Speech Error: $errorMessage"
                                    }
    
                                })
                        .initialize(stringToSpeak, this)
    
            } else {
                ttsInput.setText("Invalid input")
                Snackbar.make(view, "Please enter some text to speak", Snackbar.LENGTH_LONG).show()
            }
    
        })
    

提交回复
热议问题