ChivoxAI

/docs

Instructions for using VAD function in the evaluation sdk

Here is an example of the commonly used Android and iOS platforms.

1.Load vad resource

Put the vad resource package in the same directory as provision file, and configure vad field in the interface parameters of engine creation:

Vad field parameter description

Name Type Required Description
vad object false Voice activity detection
- enable int false Default 0.
1, means that the engine created this time loads the voice activity detection function module.
0, means that the engine created this time does not load the voice activity detection function.
- res string false Vad resource path
- sampleRate int false Audio sample rate in Hz
- strip int false Whether to filter the silent frames in the beginning and end, default value is 1, recommend 0

Sample code
Android platform: please refer to the sample code in Step 1 to create engine in the Android sdk documentation;
iOS platform: please refer to the sample code in Step 1 to create engine in the iOS sdk documentation;

2. Configuration parameters

Set the VAD function when making a request

Name Type Required Description
param object true Evaluation content
- vad object false Sound detection function
- - vadEnable int false Default 0
1: Enable VAD.
0: Disable the VAD.
- - refDuration int false Default 0
Set how long will the vad be disbaled after recording starts (unit: seconds)
- - speechLowSeek int false Silence sensitivity, 20ms per frame, set N means after N*20ms of silent audio, it would return 2(time to stop engine)

Sample code
Android platform: please refer to the sample code in Step 2 launch evaluation request in the Android sdk documentation;
iOS platform: Please refer to the sample code in Step 2 launch evaluation request in the iOS sdk documentation;

3. Process result

Add the processing of different states of vad_status in the callback function

@Override
   public void onVad(String s, final EvalResult evalResult) 
	{

       //Update main thread UI
       runOnUiThread(new Runnable() 
		{
           @Override
           public void run() 
			{
               jsonResultTextEditor.setText(evalResult.text());
           }
       });

       try 
		{
           JSONObject json = new JSONObject(evalResult.text());
           if (json.has("vad_status"))) 
			{
               int status = json.optInt("vad_status");
               final int sound_intensity = json.optInt("sound_intensity");
               if (status == 2) //Detect that the user has stopped speaking, call the aiengine.stop interface to stop sending audio data, 
			                    //and wait for the engine to feedback scoring result
				{
                   runOnWorkerThread(new Runnable() 
					{
                       public void run() 
						{
                           RetValue retstop = aiengine.stop();
                           runOnUiThread(new Runnable() 
							{
                               public void run() 
								{
                                   if (recordButton.getText().equals(getText(R.string.stop))) 
									{
                                       recordButton.setText(R.string.record);
                                   }
                               }
                           });
                       }
                   });
               }
           } 
			else 
			{
               if (recordButton.getText().equals(getText(R.string.stop))) 
				{
                   recordButton.setText(R.string.record);
               }
           }
       } catch (JSONException e) 
		{
           Log.d(TAG, "pare result error!");
       }

   }

SDK, API, MCP and Function Calling documentation on this site.