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
private fun releaseDetectionResources() { | |
if (analyzer != null) { | |
try { | |
analyzer!!.stop() | |
} catch (e: IOException) { | |
Log.e(TAG, "Exception is $e") | |
} | |
} | |
} |
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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
initializeAnalyzer() | |
binding?.selectImageButton?.setOnClickListener { askImageFromUser() } | |
binding?.analyzeButton?.setOnClickListener { | |
analyze(getMLFrame(selectedImageBitmap ?: return@setOnClickListener)) | |
} | |
} |
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
private fun initializeAnalyzer() { | |
analyzer = MLAnalyzerFactory.getInstance().imageSegmentationAnalyzer | |
} |
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
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 { |
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
override fun onCreate() { | |
super.onCreate() | |
MLApplication.getInstance().apiKey = BuildConfig.HMS_API_KEY | |
} |
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
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) |
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
private fun initializeUI() { | |
binding.apply { | |
withPickUpUIRadioButton.setOnClickListener { isPickUpUI = true } | |
withoutPickUpUIRadioButton.setOnClickListener { isPickUpUI = false } | |
asrButton.setOnClickListener { | |
if (isPickUpUI) startRecognizeWithSpeechPickupUI() | |
else startRecognizeWithoutSpeechPickupUI() | |
} | |
} | |
} |
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
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)}") |
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
private fun initializeASRRecognizer() { | |
asrRecognizer = MLAsrRecognizer.createAsrRecognizer(activity) | |
} |
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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
initializeASR() | |
initializeUI() | |
} |