Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

  1. Import the following classes in your Activity/Fragment

Code Block
languagekotlin
import com.sondeservices.passive.enrollment.EnrollmentCallback
import com.sondeservices.sonde_passive.enrollment.EnrollmentHandler
import com.sondeservices.passive.enrollment.IEnrollmentapplication_api.init.SondePassiveSdk
  1. Before starting the Enrollment, add the next check to make sure that the RECORD_AUDIO permission is enabled in your app:

  2. Declare the following code.

...

Then add the following check,

Code Block
languagekotlin
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.")
  }
}
  1. Declare IEnrollment in the declaration section of Activity/Fragment,

private var enrollmentHandler: IEnrollment? = null

...

  1. Create enrollmentHandler and call the beginEnrollment() function to start Enrollment.

enrollmentHandler = EnrollmentHandler.createEnrollment
Code Block
languagekotlin
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.”