...
The following document is a guide for your app development. The below steps will provide you with detailed information for Enrollment of the user’s voice and saving it in shared preferences.
Import the following classes in your Activity/Fragment
Code Block | ||
---|---|---|
| ||
import com.sondeservices.passive.enrollment.EnrollmentCallback import com.sondeservices.sonde_passive.enrollment.EnrollmentHandler import com.sondeservices.passive.enrollment.IEnrollmentapplication_api.init.SondePassiveSdk |
Before starting the Enrollment, add the next check to make sure that the
RECORD_AUDIO
permission is enabled in your app:Declare the following code.
...
Then add the following check,
Code Block | ||
---|---|---|
| ||
if (ContextCompat.checkSelfPermission( requireContext(), android.Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED ) { val permissions = arrayOf(android.Manifest.permission.RECORD_AUDIO) ActivityCompat.requestPermissions( requireActivity(), permissions, REQUEST_CODE_RECORD_AUDIO ) } |
...
Code Block |
---|
override fun onRequestPermissionsResult( requestCode: Int, permissions: Array<String>, grantResults: IntArray ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) if (requestCode == REQUEST_CODE_RECORD_AUDIO && grantResults.isNotEmpty() && grantResults[0] != PackageManager.PERMISSION_GRANTED) { throw RuntimeException("Record Audio permission is required to start recording.") } } |
Declare IEnrollment in the declaration section of Activity/Fragment,
private var enrollmentHandler: IEnrollment? = null
...
Create
enrollmentHandler
and call thebeginEnrollment()
function to start Enrollment.
Code Block | ||
---|---|---|
| ||
SondePassiveSdk.createEnrollmentHandler(requireContext()) enrollmentHandler?SondePassiveSdk.beginEnrollment( object : EnrollmentCallback { override fun finishEnrollment() { //Get callback here when Enrollment gets finished. } override fun onEnrollmentSuccess() { Log.d(TAG, "onEnrollmentSuccess==>") Snackbar.make(requireView(), "Enrollment Successful", Snackbar.LENGTH_LONG) .setAction("Action", null).show() } override fun onSecondCaptured(seconds: Int) { //Get the callback to show user how much seconds of active voice enrolled out of 10 seconds. Log.d(TAG, "onSecondCaptured==>$seconds") } override fun onMessage(message: String) { //Get callback when there is any message like background noise in enrollment. } override fun finishEnrollment() { //Get callback here when Enrollment gets finished. } override fun onError(throwable: Throwable) { //Get callback for all type of errors throwable.printStackTrace() } } ) |
During enrollment, the following messages may be generated based on the enrollment audio analysis:
Background noise - The message will be generated if there is background noise in the first 10 20 seconds of the audio. The user must be informed, “High background noise detected; please move to a quieter location.”