Sonde Health API Platform Documentation

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Overview

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

import com.sondeservices.passive.enrollment.EnrollmentCallback
import com.sondeservices.passive.enrollment.EnrollmentHandler
import com.sondeservices.passive.enrollment.IEnrollment
  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.

private val REQUEST_CODE_RECORD_AUDIO = 11111

Then add the following check,

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
    )
}
  1. Also, verify that the app user grants record audio permission—the recording functionality will not function without permission. To do this, override the onRequestPermissionsResult method in your app and check the permission result.

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. Initialize enrollmentHandler and call the beginEnrollment() function to start Enrollment.

enrollmentHandler = EnrollmentHandler.createEnrollment(requireContext())

enrollmentHandler?.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 onError(throwable: Throwable) {
              //Get callback for all type of errors
          }
      }
  )

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 seconds of the audio. The user must be informed, “High background noise detected; please move to a quieter location.”

  • No labels