Sonde Health API Platform Documentation
Functionality code snippets
- 1 Overview
- 2 Server Side
- 2.1 Creating Token
- 2.2 Creating User
- 2.3 Request For Score
- 3 App Side
- 3.1 iOS
- 3.1.1 Recording Wav File
- 3.1.2 Uploading Wav File
- 3.1.3 Request For Score
- 3.2 Android
- 3.2.1 Recording Wav File
- 3.2.2 Uploading Wav File
- 3.2.3 Request For Score
- 3.1 iOS
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:
Replace
<clientId>
and<clientSecret>
in below snippets by the actual values that you must have received
SondeCredentialsService cred = SondeHealthClientProvider.getClientCredentialsAuthProvider(<clientId>, <clientSecret>);
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);
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
Instantiate the SondeCredentialsService using your clientId and clientSecret
Create a subject client
Build the UserCreationRequest using the user attributes.
Create user using sujectclient created in step 2
Request For Score
Instantiate the SondeCredentialsService using your clientId and clientSecret
Upload the file using Storage Client
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
Get pre-signed url from server to upload file, give details like location, userIdentifier, and fileType
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