Samples

Two samples are provided in the Cochl.Sense Edge SDK : sense-file and sense-stream.

  • sense-file performs a prediction on an audio file (wav or mp3).
  • sense-stream performs a prediction on an audio buffer.

1. Check the Requirements

Follow our Getting started section to set up the environment.

2. C++ Requirements

Install the packages below to use our Cochl.Sense Edge SDK for C++.

sudo apt update
sudo apt install unzip
sudo apt install libpulse-dev pulseaudio pulseaudio-utils

3. Prepare the Sample

(1) The Samples can be Found Here.

git clone https://github.com/cochlearai/sense-sdk-cpp-tutorials.git

(2) Unzip the SDK

unzip path/to/sdk/sense-sdk-<version>-cpp.zip -d path/to/sample/sense-sdk-cpp-tutorials/

(3) Results

Your sample directory should now look like this.

└── sense-sdk-cpp-tutorials
    ├── audio_files          # audio samples
    ├── examples
    |   ├── sense-file.cc    # sense-file sample
    │   └── sense-stream.cc  # sense-stream sample
    └── sense                # Cochl.Sense Edge SDK
        ├── include
        ├── lib
        └── license

4. Install License Manager for SDK

Before installing the Cochl.Sense Edge SDK version 1.4.0, you should prepare the license manager. This manager is responsible for handling the Cochl.Sense Edge SDK license, whether the devices are connected to the network or not.

# folder tree in C++ SDK 1.4.0 for x86_64 Ubuntu Linux
└── sense-sdk-cpp-tutorials
    ├── audio_files          # audio samples
    ├── examples
    └── sense                # Cochl.Sense Edge SDK
          ├── include
          ├── lib
          └── license
                ├── bin
                ├── dinst
                ├── dunst
                ├── haspvlib_25011.so
                ├── haspvlib_arm64_25011.so
                ├── haspvlib_armhf_25011.so
                ├── haspvlib_x86_64_25011.so
                └── pkg

To install the license manager, run the following commands.

cd sense/license
sudo ./dinst

Uninstall license manager for SDK
(Warning) Uninstalling the license manager may affect other applications that rely on this service. If you want to proceed with the removal, please first check if your system uses the license manager. To uninstall the license manager, run the following commands.

# check the service
ps -aux | grep hasplmd

# remove the license manager
cd sense/license
sudo ./dunst

5. Parameters

There are several parameters available to configure the behavior of the Cochl.Sense Edge SDK.

// sense.hpp

...
struct Parameters {
  /// The name you want to set for this device in order to find it
  /// on your Dashboard.
  std::string device_name = "";
  
  // This list depends on your platform. Cf sense.hpp.
  ModelDelegate model_delegate = ModelDelegate::Default;
  
  /// Number of threads available to the tflite interpreter.
  int num_threads = 0;

  /// See below.
  Metrics metrics;

  /// Specify the desired log level for this device:
  /// 0: Debug
  /// 1: Information
  /// 2: Warning
  /// 3: Error
  /// The default log level is 1
  int log_level = 1;

  /// New features
  HopSizeControl hop_size_control;
  SensitivityControl sensitivity_control;
  ResultAbbreviation result_abbreviation;
  LabelHiding label_hiding;
...

Each time a frame (a unit of audio inference) is processed by the Edge SDK, a metric is generated. This metric represents the result of the frame’s inference and is intended to be sent to the server, where it can be viewed on your project dashboard. Only one device_name can be assigned per device. If you need to change the device_name you are currently using, it can be updated on the Edge SDK tab of the Project page of the dashboard.

(1) Possible Metrics options

// sense.hpp
struct Metrics {
  size_t retention_period = 0;   // range, 1 to 31 days
  size_t free_disk_space = 100;  // range, 0 to 1,000,000 MB
  size_t push_period = 30;       // range, 1 to 3,600 seconds
};

retention_period

  • The Cochl.Sense Edge SDK attempts to push metrics to our servers immediately after they are created. If the push fails, the SDK stores the data locally and retries later.
  • retention_period parameter determines the number of days the Cochl.Sense Edge SDK will keep the metrics data locally.
  • The default value is 0, meaning the data is not saved locally.
  • If an invalid value is provided (e.g., greater than 31 days), it will default to 31 days.
  • If a user sets this period, any metrics older than the retention period will be removed immediately.
  • This setting is project-specific; for example, project X can have a retention period of 7 days, while project Y can have a retention period of 14 days.

free_disk_space

  • When the available disk space falls below the free_disk_space threshold (measured in MB), the Cochl.Sense Edge SDK will stop storing metrics locally. In this situation, the user-defined retention period will be overridden and set to 0 days.
  • If an invalid free_disk_space value is provided (e.g., greater than 100 MB), it will default to 100 MB.
  • If the retention period is set to 0 and there are metrics still stored locally, the Cochl.Sense Edge SDK will attempt to push them one last time before permanently deleting them.

push_period

  • push_period determines how often metrics are pushed to the server.
  • If an invalid value is provided (0 o r greater than 3,600 seconds), it will default to 30 seconds.

6. Build

Put your Project Key into the sample code. Note that it’s important to invoke the sense::Terminate() function at the end if sense::Init() was successful. Otherwise, an undefined behavior may occur while cleaning up the memory allocated by the sense during sense::init().

// examples/sense-file.cc

...
if (sense::Init("Your project key",
                sense_params) < 0) {
  return -1;
}
...
sense::Terminate();
...

We are now ready to build the sense-file.

g++ -fopenmp examples/sense-file.cc -I./sense/include/ -lsense-core -L./sense/lib -o sense-file -lm -std=c++11 -ldl -lstdc++ -Wl,-rpath -Wl,./sense/lib

Put your Project Key into the sample code. Note that it’s important to invoke the sense::Terminate() function at the end if sense::Init() was successful. Otherwise, an undefined behavior may occur while cleaning up the memory allocated by the sense during sense::init().

// examples/sense-stream.cc

...
if (sense::Init("Your project key",
                sense_params) < 0) {
  return -1;
}
...
sense::Terminate();
...

We are now ready to build the sense-stream.

g++ -fopenmp examples/sense-stream.cc -I./sense/include/ -lsense-core -L./sense/lib -o sense-stream -lm -std=c++11 -ldl -lstdc++ -lpulse -lpulse-simple -Wl,-rpath -Wl,./sense/lib

7. Run

LD_LIBRARY_PATH=. ./sense-file <PATH_TO_AUDIO_FILE>

The repository contains audio files that can be used as well.

LD_LIBRARY_PATH=. ./sense-file audio_files/babycry.wav

Make sure the input device is properly connected before you run sense-stream

LD_LIBRARY_PATH=. ./sense-stream

8. Additional notes

(1) CPU and memory usage in stream mode

Test environment specification:

  • Cochl.Sense Edge SDK v.1.2.0
    • Parameters:
    sense::Parameters sense_params;
    sense_params.metrics.retention_period = 0;
    sense_params.metrics.free_disk_space = 100;
    sense_params.metrics.push_period = 30;
    
  • Raspberry Pi 3 Model B with TensorFlow Lite
    • OS(Raspberry Pi OS)
      • Release date: April 4th 2022
      • System: 64-bit
      • Kernel version: 5.15
      • Debian version: 11 (bullseye)
    • Quad Core 1.2GHz BCM2837 64bit CPU (ARM Cortex A53)
    • 1GB RAM
    • BCM43438 wireless LAN
    • Storage(SanDisk 16GB Ultra Micro SD HC Class 10)

Result:

  • In idle, CPU usage: 2.2526(%), memorage usage: 229,578 (kB)

CPU usage (%):

Memory usage

Memory usage (kB):

Memory usage

1. Check the Requirements

Follow our Getting started section to set up the environment.

(1) Supported Python Versions

Cochl.Sense Edge SDK for Python currently supports.

  • Python3.6
  • Python3.7
  • Python3.8

If you wish to use a different version, please contact support@cochl.ai.

2. Python Requirements

Install the packages below to use our Cochl.Sense Edge SDK for Python.

sudo apt update
sudo apt install curl
sudo apt install ffmpeg sox virtualenv portaudio19-dev python3-pyaudio libffi-dev

Install additional packages if you installed Python using a package manager instead of building if from source.

# for python3.6
sudo apt install python3.6-dev

# for python3.7
sudo apt install python3.7-dev

# for python3.8
sudo apt install python3.8-dev

3. Python Virtual Environment

Create a new virtual environment by selecting a Python interpreter and creating a ‘./venv’ directory to hold it.

virtualenv -p python3.6 --no-site-packages ./venv

# NOTE
# - If there's an error with `--no-site-packages`, then remove it and try again with 
virtualenv -p python3.6 ./venv
virtualenv -p python3.7 --no-site-packages ./venv

# NOTE
# - If there's an error with `--no-site-packages`, then remove it and try again with 
virtualenv -p python3.7 ./venv
virtualenv -p python3.8 --no-site-packages ./venv

# NOTE
# - If there's an error with `--no-site-packages`, then remove it and try again with 
virtualenv -p python3.8 ./venv

Activate the virtual environment using the appropriate shell-specific command.

source ./venv/bin/activate

When the virtualenv is active, your shell prompt will be prefixed with (venv). Installing packages within this virtual environment will not affect the host system’s setup.

Let’s start by upgrading ‘pip’:

# (venv)
curl https://bootstrap.pypa.io/pip/3.6/get-pip.py -o get-pip.py
python get-pip.py
pip3 install --upgrade pip
# (venv)
curl https://bootstrap.pypa.io/pip/get-pip.py -o get-pip.py
python get-pip.py
pip3 install --upgrade pip
# (venv)
curl https://bootstrap.pypa.io/pip/get-pip.py -o get-pip.py
python get-pip.py
pip3 install --upgrade pip

4. Install License Manager for SDK

Before installing the Cochl.Sense Edge SDK version 1.4.0, you should prepare the license manager. This manager is responsible for handling the Cochl.Sense Edge SDK license, whether the devices are connected to the network or not.

# e.g., folder tree in Python 3.8 SDK 1.4.0 for x86_64 Ubuntu Linux 
sense
  ├── sense-1.4-py38-none-linux_x86_64.whl
  └── license
        ├── bin
        ├── dinst
        ├── dunst
        ├── haspvlib_25011.so
        ├── haspvlib_arm64_25011.so
        ├── haspvlib_armhf_25011.so
        ├── haspvlib_x86_64_25011.so
        └── pkg

To install the license manager, run the following commands.

cd sense/license
sudo ./dinst

Uninstalling the license manager for SDK
(Warning) Uninstalling the license manager may affect other applications that rely on this service. If you want to proceed with the removal, please first check if your system uses the license manager. To uninstall the license manager, run the following commands.

# check the service
ps -aux | grep hasplmd

# remove the license manager
cd sense/license
sudo ./dunst

5. Launch Examples

(1) Install Some Python Packages

# (venv)
pip3 install numpy==1.21.4 || pip3 install numpy==1.19.4
pip3 install pyaudio sox pydub

(2) Install the Cochl.Sense Edge SDK

You can now install the Cochl.Sense wheel file that you have downloaded.

# (venv)
pip3 install path/to/sdk/sense-1.x-xxx-xxx.whl

(3) Retrieve the Samples

git clone https://github.com/cochlearai/sense-sdk-python-tutorials

(4) Parameters

You can refer to the c++ sample page for more information about those parameters.

Open audio_file_example.py in the sample directory, and set parameters.

# audio_file_example.py

...
# if <= 0. will use all the threads available on the machine
sense_params.num_threads = -1

# Metrics
sense_params.metrics.retention_period = 0   # range, 1 to 31 days
sense_params.metrics.free_disk_space = 100  # range, 0 to 1,000,000 MB
sense_params.metrics.push_period = 30       # range, 1 to 3,600 seconds
sense_params.log_level = 0

sense_params.device_name = "Testing device"

sense_params.hop_size_control.enable = True
sense_params.sensitivity_control.enable = True
sense_params.result_abbreviation.enable = True
sense_params.label_hiding.enable = False  # stream mode only
...

Put your Project Key into the sample code. Note that it’s important to invoke the SenseTerminate() function at the end if SenseInit() was successful. Otherwise, an undefined behavior may occur while cleaning up the memory allocated by the sense during SenseInit().

# audio_file_example.py

...
if SenseInit("Your project key",
             sense_params) < 0:
...
SenseTerminate()
...

Open audio_stream_example.py in the sample directory, and set parameters.

# audio_stream_example.py

...
# if <= 0. will use all the threads available on the machine
sense_params.num_threads = -1

# Metrics
sense_params.metrics.retention_period = 0   # range, 1 to 31 days
sense_params.metrics.free_disk_space = 100  # range, 0 to 1,000,000 MB
sense_params.metrics.push_period = 30       # range, 1 to 3,600 seconds
sense_params.log_level = 0

sense_params.device_name = "Testing device"

sense_params.hop_size_control.enable = True
sense_params.sensitivity_control.enable = True
sense_params.result_abbreviation.enable = True
sense_params.label_hiding.enable = True
...

Put your Project Key into the sample code. Note that it’s important to invoke the SenseTerminate() function at the end if SenseInit() was successful. Otherwise, an undefined behavior may occur while cleaning up the memory allocated by the sense during SenseInit().

# audio_stream_example.py

...
if SenseInit("Your project key",
             sense_params) < 0:
...
SenseTerminate()
...

(5) Run

# (venv)
python3 audio_file_example.py <PATH_TO_AUDIO_FILE>

The repository contains audio files that can be used as well.

# (venv)
python3 audio_file_example.py audio_files/babycry.wav
# (venv)
python3 audio_stream_example.py

(6) Troubleshooting

If the process ends with an error message like Illegal instruction (core dumped), try using a different version of numpy.

# (venv)
pip3 uninstall numpy
pip3 install numpy==1.19.4

1. Check the Requirements

Follow our Getting started section to set up the environment.

(1) Android Requirements

Cochl.Sense Edge SDK for Android supports Android API 26 (Version 8.0 ‘Oreo’), or later.

2. Prepare the Sample

(1) The Samples can be Found Here.

git clone https://github.com/cochlearai/sense-sdk-android-tutorials.git

(2) Unzip the SDK

# sense-file
unzip path/to/sdk/sense-sdk-<version>-android.zip \
  -d path/to/sample/sense-sdk-android-tutorials/sense-file/app

# sense-stream
unzip path/to/sdk/sense-sdk-<version>-android.zip \
  -d path/to/sample/sense-sdk-android-tutorials/sense-stream/app

(3) Android Studio Setup

Edit app/build.gradle file

dependencies {
    implementation files('libs/sense-sdk-v<version>.aar')  // Cochl.Sense Edge SDK
}

Edit app/src/main/AndroidManifest.xml file

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

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

<!-- sense-file -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

3. How to Use Cochl.Sense Edge SDK for Android

(1) Cochl.Sense Edge SDK Initialization

You can initialize the Cochl.Sense Edge SDK by calling init(projectKey, senseParams) in the ai.cochl.sensesdk.Sense package. Initialization may take some time if the process involves downloading a model. The Cochl.Sense Edge SDK will download a model if none is found on the device or if a newer version is available.

Parameters
For more information about these parameters, refer to the C++ sample page.

public static class Parameters {
    /// The name that will be shown on your Cochl.Sense dashboard for this device.
    public String deviceName = "";

    public ModelDelegate modelDelegate = ModelDelegate.Default;
    /// Number of threads available to the tflite interpreter.
    /// NOTE: num_threads should be >= 0
    /// You may pass 0 to let the sense select all the processors available.
    public int numThreads = 0;

    public Metrics metrics = new Metrics();

    /// Specify the desired log level for this device:
    /// 0: Debug
    /// 1: Information
    /// 2: Warning
    /// 3: Error
    /// The default log level is 1(Information)
    public int logLevel = 1;

    /// Path to the directory which holds the
    /// shared libraries for the Hexagon NN libraries on the device.
    /// Must be set if you use the Hexagon Model delegate.
    public String hexagonSharedLibsFolderPath = "";

    /// New features
    public HopSizeControl hopSizeControl = new HopSizeControl();
    public SensitivityControl sensitivityControl = new SensitivityControl();
    public ResultAbbreviation resultAbbreviation = new ResultAbbreviation();
    public LabelHiding labelHiding = new LabelHiding();
}

Possible ModelDelegate options

enum ModelDelegate {
    Default(0), Hexagon(1), NnApi(2), Gpu(3);

    public final int value;

    ModelDelegate(int value) {
        this.value = value;
    }
}

Put your Project Key into the sample code. Note that it’s important to invoke the sense::Terminate() function at the end if sense::Init() was successful. Otherwise, an undefined behavior may occur while cleaning up the memory allocated by the sense during sense::init().

// examples/sense-file.cc

...
if (sense::Init("Your project key",
                sense_params) < 0) {
  return -1;
}
...
sense::Terminate();
...

We are now ready to build the sense-file.

g++ -fopenmp examples/sense-file.cc -I./sense/include/ -lsense-core -L./sense/lib -o sense-file -lm -std=c++11 -ldl -lstdc++ -Wl,-rpath -Wl,./sense/lib

Put your Project Key into the sample code. Note that it’s important to invoke the sense::Terminate() function at the end if sense::Init() was successful. Otherwise, an undefined behavior may occur while cleaning up the memory allocated by the sense during sense::init().

// examples/sense-stream.cc

...
if (sense::Init("Your project key",
                sense_params) < 0) {
  return -1;
}
...
sense::Terminate();
...

We are now ready to build the sense-stream.

g++ -fopenmp examples/sense-stream.cc -I./sense/include/ -lsense-core -L./sense/lib -o sense-stream -lm -std=c++11 -ldl -lstdc++ -lpulse -lpulse-simple -Wl,-rpath -Wl,./sense/lib

(2) Audio Input

Cochl.Sense Edge SDK receives audio data and returns a list of detected sound tags in JSON format. It supports two types of audio input: stream and file.

Read a file and pass it to the Cochl.Sense Edge SDK.

import java.io.File;

(...)

// Storage which contains the audio file
File sdcard;
if (android.os.Build.VERSION.SDK_INT < 29)
    sdcard = Environment.getExternalStorageDirectory();
else  // android.os.Build.VERSION.SDK_INT >= 29
    sdcard = this.getExternalFilesDir(null);

// Create a File object and add it as an input to the Sense
sense.addInput(new File(sdcard, "some_audio_file.wav"));

android.media.AudioRecord is used to receive an audio stream from the device.

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

(...)

private final int AUDIO_SOURCE = MediaRecorder.AudioSource.UNPROCESSED;
private final int SAMPLE_RATE = 22050;
private final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;
// Supported audio formats: PCM_8BIT, PCM_16BIT, PCM_FLOAT;
private final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_FLOAT;
private final int RECORD_BUF_SIZE = AudioRecord.getMinBufferSize(SAMPLE_RATE,
                                                                 CHANNEL_CONFIG,
                                                                 AUDIO_FORMAT);

// Create an AudioRecord object and add it as an input to the Sense
sense.addInput(new AudioRecord(AUDIO_SOURCE,
                               SAMPLE_RATE,
                               CHANNEL_CONFIG,
                               AUDIO_FORMAT,
                               RECORD_BUF_SIZE));

4. Predict on Device

(1) NOTE

The sample rate of the input audio must be 22,050,Hz or higher. Audio with a sample rate lower than 22,050 Hz cannot be used. If the sample rate is higher than 22.050 Hz, the Cochl.Sense Edge SDK will downsample the audio internally.

Do not change the SAMPLE_RATE parameter for audio stream prediction.

private static final int SAMPLE_RATE = 22050;

(2) JSON result format

{
  "tags": [
    {
      "name"        : <string>, The name of the predicted tag (e.g. "Siren")
      "probability" : <float>,  Probability of the predicted tag
    }
  ],
  "start_time"      : <float>,  Starting time of this prediction window
  "end_time"        : <float>,  Ending time of this prediction window
  "prediction_time" : <double>, The amount of time it took to process this window
                                (in milliseconds)
}

LIMITATIONS: Audio file length must be at least 1 second.

import ai.cochl.sensesdk.Sense;
import ai.cochl.sensesdk.CochlException;

(...)

private final String projectKey = "Your project key";

// Get the Sense singleton class
sense = Sense.getInstance();

// Set the project key and parameters
Sense.Parameters senseParams = new Sense.Parameters();
senseParams.metrics.retentionPeriod = 0;  // days
senseParams.metrics.freeDiskSpace = 100;  // MB
senseParams.metrics.pushPeriod = 30;      // seconds

senseParams.deviceName = "Android device.";

senseParams.logLevel = 0;

senseParams.hopSizeControl.enable = true;
senseParams.sensitivityControl.enable = true;
senseParams.resultAbbreviation.enable = true;
senseParams.labelHiding.enable = false;  // stream mode only

sense.init(projectKey, senseParams);

// Storage which contains the audio file
File sdcard;
if (android.os.Build.VERSION.SDK_INT < 29) {
    sdcard = Environment.getExternalStorageDirectory();
} else {  /* android.os.Build.VERSION.SDK_INT >= 29 */
    sdcard = this.getExternalFilesDir(null);
}

// Create a File object and add it as an input to the Sense
sense.addInput(new File(sdcard, "some_audio_file.wav"));

// Set the callback function that is called after the prediction is done
sense.predict(new Sense.OnPredictListener() {
    @Override
    public void onReceivedResult(JSONObject json) {
        try {
            String result = json.getJSONObject("result").toString(2);
        } catch (JSONException e) {
            e.printStackTrace();
        } finally {
            runOnUiThread(() -> progressBar.setStop());
        }
    }

    @Override
    public void onError(CochlException e) {
        runOnUiThread(() -> {
            sense.stopPredict();
        });
    }
});
import ai.cochl.sensesdk.Sense;
import ai.cochl.sensesdk.CochlException;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

(...)

private final String projectKey = "Your project key";

// Set the parameters for the AudioRecord object
private final int AUDIO_SOURCE = MediaRecorder.AudioSource.UNPROCESSED;
private final int SAMPLE_RATE = 22050;
private final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;
// Supported audio formats: PCM_8BIT, PCM_16BIT, PCM_FLOAT;
private final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_FLOAT;
private final int RECORD_BUF_SIZE = AudioRecord.getMinBufferSize(SAMPLE_RATE,
                                                                 CHANNEL_CONFIG,
                                                                 AUDIO_FORMAT);

(...)

// Get the Sense singleton class
sense = Sense.getInstance();

// Set the project key and parameters
Sense.Parameters senseParams = new Sense.Parameters();
senseParams.metrics.retentionPeriod = 0;  // days
senseParams.metrics.freeDiskSpace = 100;  // MB
senseParams.metrics.pushPeriod = 30;      // seconds

senseParams.deviceName = "Android device.";

senseParams.logLevel = 0;

senseParams.hopSizeControl.enable = true;
senseParams.sensitivityControl.enable = true;
senseParams.resultAbbreviation.enable = true;
senseParams.labelHiding.enable = true;

sense.init(projectKey, senseParams);

// Create an AudioRecord object and add it as an input to the Sense
sense.addInput(new AudioRecord(AUDIO_SOURCE,
                               SAMPLE_RATE,
                               CHANNEL_CONFIG,
                               AUDIO_FORMAT,
                               RECORD_BUF_SIZE));

// Set the callback function that is called after the prediction is done
sense.predict(new Sense.OnPredictListener() {
    @Override
    public void onReceivedResult(JSONObject json) {
        try {
            String frame_result = json.getJSONObject("frame_result").toString(2);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onError(CochlException e) {
        runOnUiThread(() -> {
            sense.stopPredict();
        });
    }
});

5. Pause & Resume (Stream only)

While processing a stream, you can pause and resume the inference as needed.

(1) Pause & Resume

pauseBtn = findViewById(R.id.pauseBtn);
pauseBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        sense.pause();
    }
});

resumeBtn = findViewById(R.id.resumeBtn);
resumeBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        sense.resume();
    }
});

6. Stop Prediction

If an unexpected error occurs during a prediction, you can abort the prediction by calling the stopPredict() method. This method should also be called before changing the audio input for sense.

sense.stopPredict();

7. Terminate

Cochl.Sense Edges SDK allocates several resources during initialization. To ensure these resources are released safely, call the terminate() method before exiting.

@Override
protected void onDestroy() {
    if (sense != null) {
        sense.terminate();
        sense = null;
    }
    super.onDestroy();
}

8. (Note) Reference

(1) Sense

java.lang.Object
    ai.cochl.sensesdk.Sense;

The Cochl.Sense Edge SDK is available as a singleton class and operates with a project key. After successful initialization, you can add audio input to the Cochl.Sense Edge SDK for prediction.

Public Methods

public static Sense getInstance()

  • Returns an instance of the Sense singleton class.

public static String getSdkVersion()

  • Returns the version of the Cochl.Sense Edge SDK.

public void init(String projectKey, Parameters senseParams)

  • Authenticates the user with the project key. Throws an exception if authentication fails.

public void addInput(AudioRecord audioRecord)

  • Adds an AudioRecord object to perform prediction on an audio stream.

public void addInput(File file)

  • Adds a File object to perform prediction on an audio file.

public void predict(Sense.OnPredictListener listener)

  • Starts prediction with a callback function to be called after an audio frame is processed.

public void pause()

  • Pauses the prediction for the audio stream.

public void resume()

  • Resumes the prediction for the audio stream.

public void stopPredict()

  • Stops the prediction and allows you to add new audio input.

public Parameters getParameters()

  • Returns the parameters set during initialization.

public void terminate()

  • Releases the resources allocated by the Cochl.Sense Edge SDK after successful initialization. Custom exceptions may be thrown by the Cochl.Sense Edge SDK.

(2) CochlException

java.lang.Object
    java.lang.Throwable
        java.lang.Exception
            java.lang.RuntimeException
                ai.cochl.sensesdk.CochlException

A custom exception may be thrown by the Cochl.Sense Edge SDK.

(3) Public Constructors

Constructors for the CochlException class:

public CochlException()

public CochlException(String message)

public CochlException(String format, Object... args)

public CochlException(String message, Throwable throwable)

public CochlException(Throwable throwable)