AyuSynkSdk (V2.0.1)

The AyuSynkSdk is a library for the Android platform.

AyuSynkSdk is an easy-to-use compact Android library consisting of a single library file which has to be added to your project (one single aar file) containing a simple high-level API (one single class).

With the AyuSynkSdk you have a compact but consists of all the major functionality featured in the AyuShare app which is easy to integrate with any Android application.
It can be used to develop a custom application or to integrate ayusynk device into any existing Android application.

## Get Sdk Access

 

Please fill out this google form. Once filled we will review that data and based on that get in touch for SDK integration.

Link for form: shorturl.at/uAO13

For any further queries. Write an email to ayuanalytics@ayudevices.com specifying the subject as " <YOUR_COMPANY_NAME> - Query for Android SDK "

## Requirements

 

Every website has a story, and your visitors want to hear yours. This space is a great opportunity to give a full background on who you are, what your team does and what your site has to offer. Double click on the text box to start editing your content and make sure to add all the relevant details you want site visitors to know.

If you’re a business, talk about how you started and share your professional journey. Explain your core values, your commitment to customers and how you stand out from the crowd. Add a photo, gallery or video for even more engagement.

## Required Permission

 For Connecting Device via Bluetooth

 

 

 

1. ACCESS_FINE_LOCATION (Android requires this permission for scanning nearby Bluetooth device. We never use this permission for fetching location )
2. BLUETOOTH_CONNECT (For app targetting android 12 and above android requires this permission)
3. BLUETOOTH_SCAN (For app targetting android 12 and above android requires this permission)

<b>Required android features:</b>
You can set these in your AndroidManifest.xml as uses-feature elements:
The only important feature is the android.hardware.bluetooth_le (but this is also not enforced by default by the library because you might use it for other purposes when AyuSynk is not used).
If you want to make sure this feature is present you should add the following line to your manifest:
```
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
```

For Connecting Device via Charging port

 

1. RECORD_AUDIO (Android requires this permission for reading audio from attached device. We use this permission only to read audio data from the device)

All these permission must be also asked at runtime. AyuSynkSdk will require this on first start scan / connect or will throw SecurityException if not granted, but it is better if you ask it also from your app at a more appropriate time (for example at startup or before the first device scan / connect).

###For Connecting Device via Charging port

 

1. RECORD_AUDIO (Android requires this permission for reading audio from attached device. We use this permission only to read audio data from device)

All these permission must be also asked at runtime. AyuSynkSdk will require this on first start scan / connect or will throw SecurityException if not granted, but it is better if you ask it also from your app at a more appropriate time (for example at startup or before the first device scan / connect).

## Usage

 

You can use the AyuSynkSdk library in any Android project. Just add the library to your project and call its public API functions.For Online Live Streaming and Diagnosis Report Generation you will need specific clientId given from AyuDevices, for more details refer [below](#online-live-streaming)

## Instructions

 

Step-by-step instruction for using AyuSynkSdk:

1. You might load the sample project first and check its MainBleFragment.java / MainUsbFragment.java file for a complete usage example
2. Add the ayusynksdk.aar library to your project
  * For Android Studio 4.2 or later you can add it to your project this way:
       - Create a new folder in the same directory where your 'app' module is located and name it same as your .aar for example 'ayusynksdk' for 'ayusynksdk.aar'
       - Paste the ayusynksdk.aar file in that directory.
       - Open notepad and type the following:
           ```
           configurations.maybeCreate("default")
           artifacts.add("default", file('ayusynksdk.aar'))
           ```
       and save the file as build.gradle in the 'ayusynksdk' folder.

  * For Android Studio you can add it to your project this way:
       - Click File > New > New Module.
       - Click Import .JAR/.AAR Package then click Next.
       - Enter the location of the ayusynksdk.aar file then click Finish.
3. Make sure the library is listed at the top of your settings.gradle file:
  ```
  include ':app', ':ayusynksdk'
  ```
4. Open the app module's build.gradle file and add a new line to the dependencies block:
  ```
  dependencies {
  ...
  implementation project(":ayusynksdk")
  }
  ```
5. Click Sync Project with Gradle Files.

## Sample Project

 

You can find a working example in ayusynksdkdemo folder.

Usage:
1. Download and unzip the AyuSynkSdk.zip file
2. Open the project folder "ayusynksdkdemo" in Android Studio
3. You might also need to adjust the SDK version and location in the following files:
  - local.properties
  - \app\build.gradle
4. From Android Studio select Rebuild Project from the Build menu. Once the rebuild is ready, you can Run it on your device

Relevant code of implementation:
1. For connecting device via bluetooth can be found in /app/src/main/java/com/ayudevice/ayusynksdkdemo/MainBleFragment.java
2. For connecting device via charging port can be found in /app/src/main/java/com/ayudevice/ayusynksdkdemo/MainUsbFragment.java
This is an Android Studio example project. If you are using Eclipse or other environment, then just inspect the above file or convert the project to your environment.

For a full demonstration of the SDK capabilities you might check the AyuShare app which is also based on this SDK.


 

## Features

 

AyuSynkSdk library consist of below features:
1. Show list of available AyuSynk devices (Only for BLE device)
2. Connection to AyuSynk device
3. Stream audio
4. Waveform UI
5. Record audio
6. Save audio
7. Get AyuSynk Battery (Only for BLE device)
8. Battery indicator UI
9. Get AyuSynk signal strength (Only for BLE device)
10. Share audio
11. Denoising audio
12. Online streaming
13. Diagnosis Report Generation

### Online Live Streaming

 

To get online live streaming you need to contact AyuDevices and request for clientId to use this feature.
If you already have clientId add it in your app. Refer [this](#add-client-id) section for how to get access using client id

### Diagnosis Report Generation
To generate diagnosis report you need to contact AyuDevices and request for clientId to use this feature.
If you already have clientId add it in your app. Refer [this](#add-client-id) section for how to get access using client id

1. For report generation you need to upload the recorded wav files on any cloud storage and make in public accessible.
2. Set listener by calling this function setDiagnosisReportUpdateListener() to get diagnosis report once generated.
3. Then pass the wav file cloud url to the generateDiagnosisReport() function as passed here. Refer /app/src/main/java/com/ayudevice/ayusynksdkdemo/MainFragment.java#L273

NOTE
1. it is recommended to send proper location with file url if known.
2. You can pass up to max 16 files for generating report. If files exceeds 16 reports won't be generated.
3. Based on our research in past years we recommend to record sound for 10 sec which is enough for doctor to diagnose properly
4. Report generation can take up to ~15-20 secs for 10 sec audio. More time will be taken if the size of recording exceeds then recommended 10 sec audio.


 

### Add client id

 

1. Open AndroidManifest.xml
2. Replace xxxx with clientId provided
```
  <application>
       <meta-data android:name="com.ayudevice.ayusynksdk.clientId" android:value="****" />
  </application>
```
3. From Android Studio select Rebuild Project from the Build menu. Once the rebuild is ready, you can Run it on your device

## API

 

You can use AyuSynkSdk as an SDK by embedding into your Android application and calling its public API functions described below.

The whole API is defined in the AyuSynk class, thus you will need to import only this single class once you added ayusynksdk.aar to your project:

```
import com.ayudevice.ayusynksdk.AyuSynk;

/* Call this from your Application class onCreate() */
AyuSynk.init(getApplicationContext());

### Api for Bluetooth Implementation

 

For Bluetooth implementation to can get all available api's via
```
AyuSynk.getBleInstance()

No.
return type
function
description
01
boolean
isAllUSBPermissionGranted()
Used to check if all necessary usb permission is granted for connection to AyuSynk device
02
void
requestRecordAudioPermission(Activity activity, int requestCode)
Used to request record audio permission required for connection to AyuSynk device
03
DeviceConnectionState
isDeviceConnected()
Returns DEVICE_CONNECTED if device is attached to mobile else DEVICE_DISCONNECTED
04
void
requestLocation(Activity activity)
Navigate to location enable option in android settings
05
void
setConnectToAvailableDevice(boolean enabled)
If enabled; On startScan() connection is made to first available device. Recommended to enable only if one device is available
06
void
setAutoConnect(boolean autoConnect)
If enabled; On disconnect an attempt is made to connect to the device again
07
DeviceConnectionState
isDeviceConnected()
Returns DEVICE_CONNECTED if device is connected else DEVICE_DISCONNECTED
08
DeviceStrength
getDeviceStrength()
Returns current signal strength. Recommended to always refer values returned via AyuDeviceListener
09
void
setAyuDeviceListener(AyuDeviceListener ayuDeviceListener)
Set this listener to get callbacks for device connection, strength and battery value changes
10
void
setDeviceScanListener(DeviceScanListener deviceScanListener)
Set this listener to get callbacks when using startScan()/stopScan() methods
11
boolean
| startScan()
Starts scanning for nearby device
12
boolean
stopScan()
Stops scanning for nearby device. Recommended to always call this method once you find the device because scanning continously will drain phones battery
13
boolean
connect(String device_address)
Connect to device by passing the address of the device. device_address is obtained in Device object of DeviceScanListener method
14
int
getCurrentBatteryLevel()
Returns current battery level. Recommended to always refer values returned via AyuDeviceListener
15
void
disconnect()
Disconnect all existing connections

 

Refer [Common API](#common-api) section for exploring more available api and their usage.

### Api for Usb implementation

 

For Usb implementation to can get all available api's via
```
AyuSynk.getUsbInstance()

No.
ReturnType
function
Description
01
boolean
isAllUSBPermissionGranted()
Used to check if all necessary usb permission is granted for connection to AyuSynk device
02
void
requestRecordAudioPermission(Activity activity, int requestCode)
Used to request record audio permission required for connection to AyuSynk device
03
DeviceConnectionState
isDeviceConnected()
Returns DEVICE_CONNECTED if device is attached to mobile else DEVICE_DISCONNECTED
04
void
setAyuDeviceListener(AyuDeviceListener ayuDeviceListener)
Set this listener to get callbacks for device connection and connection error
05
void
registerUsbDeviceConnectionReceiver()
Register broadcast receiver to detect usb attach/detach event
06
void
unRegisterUsbDeviceConnectionReceiver()
Un-Register usb attach/detach broadcast receiver
07
boolean
connect()
Connect to attached device
08
void
disconnect
Disconnect connection

 

Refer [Common API](#common-api) section for exploring more available api and their usage.

### Common Api

No.
Return Type
Function
Description
01
void
changeFilter(FilterType filterType)
Used to apply different denoising on audio stream
02
void
setRecorderListener(RecorderListener recorderListener)
Used to get various recording callback when using record or stream features
03
void
getAudioData(int recordID)
Get recorded data
04
short[]
getAudioData(int recordID)
Get recorded data
05
void
changePlaybackSpeed(PlayBackSpeeds speed)
Change playback speed to VERY_SLOW, SLOW and NORMAL
06
void
resetSpeed()
Resets speed to NORMAL
07
void
startRecording()
Starts recording the current audio stream
08
void
pauseRecording()
Used to pause recording
09
void
clearRecordedData()
Used to discard any recorded audio before it is completed.
10
void
setRecordingTimeLimit(int recordingTimeLimit)
Used to set the recording time limit
11
void
resumePlayback()
Resume playback
12
void
pausePlayback()
Pause playback
13
void
stopPlayback()
Stop playback
14
void
muteAudio(boolean mute)
Mute audio
15
void
setAyuVisualizerView(AyuVisualizerView ayuVisualizerView)
Set AyuVisualizer for plotting audio waveform
16
boolean
startOnlineStreaming()
Starts online streaming. You need to have valid clientId to start online streaming
17
boolean
stopOnlineStreaming()
Stop online streaming
18
boolean
isStreamingOnline()
Returns true if is streaming online
19
void
setOnlineStreamerListener(OnlineLiveStreamListener onlineStreamerListener)
Set listener to get callback when online streaming is started
20
string
getLiveStreamUrl()
Get live streaming url
21
void
generateDiagnosisReport(SoundFile soundFile)
To generate diagnosis reports from recorded sound file. You need to have valid clientId to generate reports. Refer MainFragment.java#L268
22
void
setDiagnosisReportUpdateListener(DiagnosisReportUpdateListener diagnosisReportUpdateListener)
Listener to check updates on diagnosis report generation
23
void
close()
Releases all the allocated memory by AyuSynkSdk. Should call before closing app

## CHANGELOG

 

To view change log please