Created
April 20, 2021 14:41
-
-
Save anshajkhare/f774db2485d8aabb4a618879accac4e1 to your computer and use it in GitHub Desktop.
Handle audio sessions when user clicks on trigger icon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainActivity : AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| // ... | |
| trigger.setOnClickListener { | |
| // Handle audio sessions here | |
| if (mIsListening) { | |
| handleSpeechEnd() | |
| } else { | |
| handleSpeechBegin() | |
| } | |
| } | |
| // ... | |
| } | |
| private fun handleSpeechBegin() { | |
| // start audio session | |
| mUserInfoText!!.setText(R.string.listening) | |
| mIsListening = true | |
| mSpeechRecognizer!!.startListening(createIntent()) | |
| } | |
| private fun handleSpeechEnd() { | |
| // end audio session | |
| mUserInfoText!!.setText(R.string.detected_speech) | |
| mIsListening = false | |
| mSpeechRecognizer!!.cancel() | |
| } | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment