Overview
The verification module is responsible for verifying the user’s audio against the voice used for enrollment, which was explained in Sonde Edge Passive SDK Architecture. Additionally, before starting with the steps mentioned here, please go through Android Sonde Edge Passive SDK Integration.
The following steps guide your app development and will provide detailed information for the verification of the user’s voice and describe collecting the audio sample and generating the score for Mental Fitness.
Import the following classes in your Activity/Fragment
Code Block |
---|
import com.sondeservices.common.RecordingDataType import com.sondeservices.passive.models.Score import com.sondeservices.passive.verification.IVerification import com.sondeservices.passive.verification.RecordingData import com.sondeservices.passive.verification.VerificationCallback import com.sondeservices.passive.verification.VerificationHandler |
Before starting the verification, add the next check to make sure that the
RECORD_AUDIO
permission is enabled in your app :Declare the following code.
private val REQUEST_CODE_RECORD_AUDIO = 11111
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 ) } |
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.
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
IVerification
in the declaration section of Activity/Fragment,
private var verificationHandler: IVerification? = null
Initialize
verificationHandler
and call thestartVerification()
function to start verification.
Code Block |
---|
verificationHandler = VerificationHandler.createVerification(requireContext()) verificationHandler?.startVerification(object : VerificationCallback { override fun onError(throwable: Throwable) { Log.d(TAG, "onError==>${throwable.message}") } override fun onScore(score: Score) { Log.d(TAG, "Score==>$score") //Get callback when score is ready. } override fun onSegmentFormed(recordingData: RecordingData) { //Get callback when 3 sec segment formed and you will get //recordingData as datatype in which you will be having following member //isUserVerified:Boolean, 3 sec segment is verified or not. //noOfSecond:Int, How much second user's verified voice is there. //recordingDataType:RecordingDataType, you will get enum as NO_VOICE,ACTIVE_VOICE,INSUFFICIENT_VOICE,RECORDING. //segmentNumber:Int, which segment is this from 10 segment of 3 sec each. } override fun onVerificationStopped() { //Get call back when recording stop. } }) |
Typecast the score to
VFFinalScore
to get the other voice feature's scores.
Code Block |
---|
val vfFinalScore = score as VFFinalScore |
Display the score to the user
The score value generated in the above step varies between 0-100. Once you get the score, display it to the user. You should always show the user the interpretation message on the score screen. For some applications, scores may be uploaded and not shown to the users. However, the scores can be uploaded for an individual user or in bulk for further analysis through API function calls.
Refer to Vocal Biomarkers - Health Checks for the interpretation message.
Below is the screenshot for your reference.