Sonde Health API Platform Documentation

Functionality code snippets

Overview

High level sequence diagram is shown below for How you can integrate your AppServer and App with SondePlatform

 

 

Server Side

Creating Token

Using java-sdk, access token can be generated as below:

  1. Replace <clientId> and <clientSecret> in below snippets by the actual values that you must have received

SondeCredentialsService cred = SondeHealthClientProvider.getClientCredentialsAuthProvider(<clientId>, <clientSecret>);
  1. Make a list of all the required scopes. Example below

List<Scopes> scopeList = Arrays.asList(Scopes.STORAGE_WRITE, Scopes.SCORES_WRITE, Scopes.MEASURES_READ, Scopes.MEASURES_LIST);
  1. Now, generate access token using the SondeCredentialsService

AccessToken token = null; try{ token = cred.generateAccessToken(scopeList); String accessToken = token.getAccessToken(); //This line will get the accessToken with the requested scopes } catch(SondeServiceException | SDKClientException | SDKUnauthorizedException ex){ //Exception handling code }

Creating User

  1. Instantiate the SondeCredentialsService using your clientId and clientSecret

  1. Create a subject client

  1. Build the UserCreationRequest using the user attributes.

  1. Create user using sujectclient created in step 2

Request For Score

  1. Instantiate the SondeCredentialsService using your clientId and clientSecret

  1. Upload the file using Storage Client

  1. Create a Scoring client and get Score for a measure

App Side

iOS

Recording Wav File

Wave file should be recorded in sampling rate of 44100 Hz

  • Adding the audio recording permission description into plist file

  • Ask recording permission from the user

  • To record the audio file follow the code snippet given below

  • Stop Audio Recording

Uploading Wav File

– Parameters

– countryCode:

– subjectIdentifier:

  • To upload the audio file you need to first get the pre-signed URL where you need to upload the file.

  • Upload the file from the path where your audio file is created.

  • Upload the audio file

– Parameters:

– signedURL: You get this value from the response of getSignedURL.

– audioFileURL: URL path where you recorded your audio file.

Request For Score

– Parameters:

– fileLocation: You can get the file location from the response of getSignedURL.

– measureName: The value of a measure for which you want to calculate the score.

Android

Recording Wav File

Wave file should be recorded in sampling rate of 44100 Hz

You can record a audio file in following steps :

i). Request for microphone permission :

To record an audio, you must request for microphone permission on android 6 and above.

Add the permission in manifest

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

Below code snippet you can refer to request for microphone permission.

ii). Start recording of audio :

Below snippet you can refer to start recording of audio and writing it to a file.

The expected file is .WAV file, you should convert your PCM file to .WAV file by using method WaveUtils.pcmToWave() (You can find implementation of this method in GitHub sample project here: https://github.com/sondehealth-samples/score/blob/master/client/android/app/src/main/java/com/sonde/sample/utils/WaveUtils.java ) This method adds required headers in the file.

Uploading Wav File

  1. Get pre-signed url from server to upload file, give details like location, userIdentifier, and fileType

  1. Once you got the S3 signed url, next step is to upload wav file to S3 bucket.

You can refer below code snippet to upload file to S3 bucket

Request For Score

After successfully uploading the wav file, the last step requires you to request for measure score.

You can refer below code snippet to request for measure score.

For more information, please contact Sonde at support@sondehealth.com.

Sonde Health