Skip to content

Instantly share code, notes, and snippets.

View yektasarioglu's full-sized avatar
🤓
Working on some interesting stuff

Yekta Sarioglu yektasarioglu

🤓
Working on some interesting stuff
View GitHub Profile
@yektasarioglu
yektasarioglu / StaticHumanBodySegmentationFragment.kt
Created November 30, 2020 12:03
Releasing Analyzer resources
private fun releaseDetectionResources() {
if (analyzer != null) {
try {
analyzer!!.stop()
} catch (e: IOException) {
Log.e(TAG, "Exception is $e")
}
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initializeAnalyzer()
binding?.selectImageButton?.setOnClickListener { askImageFromUser() }
binding?.analyzeButton?.setOnClickListener {
analyze(getMLFrame(selectedImageBitmap ?: return@setOnClickListener))
}
}
@yektasarioglu
yektasarioglu / StaticHumanBodySegmentationFragment.kt
Last active November 30, 2020 11:29
Initializing Analyzer In default mode
private fun initializeAnalyzer() {
analyzer = MLAnalyzerFactory.getInstance().imageSegmentationAnalyzer
}
private fun analyze(frame: MLFrame) {
// Create a task to process the result returned by the image segmentation analyzer.
val task: Task<MLImageSegmentation> = analyzer?.asyncAnalyseFrame(frame)!!
// Asynchronously process the result returned by the image segmentation analyzer.
task.addOnSuccessListener {
// Detection success.
Log.i(TAG, "Success - Result is $it")
configureAfterImage(it.foreground)
}.addOnFailureListener {
@yektasarioglu
yektasarioglu / MyApplication.kt
Created November 1, 2020 10:48
Set ML Kit API key
override fun onCreate() {
super.onCreate()
MLApplication.getInstance().apiKey = BuildConfig.HMS_API_KEY
}
@yektasarioglu
yektasarioglu / ASRFragment.kt
Created October 30, 2020 18:57
startRecognizeWithSpeechPickupUI() and startRecognizeWithoutSpeechPickupUI()
private fun startRecognizeWithSpeechPickupUI() {
val intent = Intent(activity, MLAsrCaptureActivity::class.java)
.putExtra(MLAsrCaptureConstants.LANGUAGE, ENGLISH_LANGUAGE_CODE)
.putExtra(MLAsrCaptureConstants.FEATURE, MLAsrCaptureConstants.FEATURE_WORDFLUX)
startActivityForResult(intent, ASR_RESULT_CODE)
}
private fun startRecognizeWithoutSpeechPickupUI() {
val intent = Intent(MLAsrConstants.ACTION_HMS_ASR_SPEECH)
.putExtra(MLAsrCaptureConstants.LANGUAGE, ENGLISH_LANGUAGE_CODE)
@yektasarioglu
yektasarioglu / ASRFragment.kt
Created October 30, 2020 18:56
initializeUI()
private fun initializeUI() {
binding.apply {
withPickUpUIRadioButton.setOnClickListener { isPickUpUI = true }
withoutPickUpUIRadioButton.setOnClickListener { isPickUpUI = false }
asrButton.setOnClickListener {
if (isPickUpUI) startRecognizeWithSpeechPickupUI()
else startRecognizeWithoutSpeechPickupUI()
}
}
}
@yektasarioglu
yektasarioglu / ASRFragment.kt
Created October 30, 2020 18:54
initializeCallback()
private fun initializeCallback() {
asrRecognizer.setAsrListener(object : MLAsrListener {
override fun onResults(result: Bundle?) {
MediaPlayer.create(activity, R.raw.stop_record).start()
Log.i("ASRFragment", "result is ${result?.getString(MLAsrRecognizer.RESULTS_RECOGNIZED)}")
showResult(result?.getString(MLAsrRecognizer.RESULTS_RECOGNIZED) ?: "")
}
override fun onRecognizingResults(partialResult: Bundle?) {
Log.i("ASRFragment", "partialResult is ${partialResult?.getString(MLAsrRecognizer.RESULTS_RECOGNIZED)}")
@yektasarioglu
yektasarioglu / ASRFragment.kt
Created October 30, 2020 18:50
initializeASRRecognizer()
private fun initializeASRRecognizer() {
asrRecognizer = MLAsrRecognizer.createAsrRecognizer(activity)
}
@yektasarioglu
yektasarioglu / ASRFragment.kt
Created October 30, 2020 18:48
onViewCreated(...)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initializeASR()
initializeUI()
}