Samples - REST
These samples of code can be used to begin using our API quickly.
All clients are generated automatically using openapi generator. Check the openapi specification
Installation
Install dependencies : add in your gradle file
dependencies {
...
implementation "ai.cochl:sense-api:v1.4.0"
}
For file upload, you will need an audio file. You can download one here
wget https://docs.cochl.ai/audio/siren.wav
For microphone upload, the sample of code assumes that audio stream is being taken from android microphone
This sample of code is working with node. The library is also compatible with browser.
Install dependencies
npm install @cochl/sense-api
For file upload, you will need an audio file. You can download one here
wget https://docs.cochl.ai/audio/siren.wav
For microphone upload, you will need to install one more dependency
npm install mic
Install coch-sense-api
pip install --upgrade cochl-sense-api
For file upload, you will need an audio file. You can download one here
wget https://docs.cochl.ai/audio/siren.wav
For microphone upload, you will need to install one more dependency
pip install pyaudio
Features
New features introduced starting from v1.4.0
Default Hop Size
- The inference interval can be set to either 0.5 seconds or 1 second.
- By default, the system uses overlapping 0.5-second intervals for inferring from 1-second audio data.
- Setting the hop size to 1 second eliminates overlapping intervals during the inference process.
static WindowHop HOP_SIZE = WindowHop._0_5S;
Sensitivity Control
- Once enabled, this feature allows for the adjustment of tag detection sensitivity.
- You can adjust the sensitivity of all tags with
DEFAULT_SENSITIVITY
and adjust the sensitivity of specific tag(s) withTAGS_SENSITIVITY
- High sensitivity ensures more true positives but also more false positives, while low sensitivity may result in fewer false positives but also fewer true positives.
// You have 5 options:
// - Very high sensitivity (-2)
// - High sensitivity (-1)
// - Normal (default) ( 0)
// - Low sensitivity ( 1)
// - Very low sensitivity ( 2)
static int DEFAULT_SENSITIVITY = 0;
// You can set the sensitivity for specific tags.
HashMap<String, Integer> TAGS_SENSITIVITY = new HashMap<>();
TAGS_SENSITIVITY.put("Male_speech", 1);
Result Summary
- Cochl.Sense provides comprehensive results for each inference unit.
- When activated, this feature abbreviate consecutive results to provide a summary, returning the time and length of the detected tag.
- The ‘interval margin’(
IM
) is a parameter that treats the unrecognized window between tags as part of the recognized ones.DEFAULT_IM
controls the margin for all tags, andTAGS_IM
controls the margin of specific tags. - This feature operates differently in file mode and stream mode.
- In file mode, you can modify the
IM
. - In stream mode, the
IM
cannot be changed and is set to 0.
- In file mode, you can modify the
// Enable Result Summary
static boolean USE_RESULT_ABBREVIATION = true;
// The unit of the im is seconds, there is no limitation.
static int DEFAULT_IM = 1;
// Set the im for specific tags.
HashMap<String, Integer> TAGS_IM = new HashMap<>();
TAGS_IM.put("Male_speech", 1);
Default Hop Size
- The inference interval can be set to either 0.5 seconds or 1 second.
- By default, the system uses overlapping 0.5-second intervals for inferring from 1-second audio data.
- Setting the hop size to 1 second eliminates overlapping intervals during the inference process.
// Hop size's default value is 500ms and can be set to "1s"
const HOP_SIZE = 0.5,
Sensitivity Control
- Once enabled, this feature allows for the adjustment of tag detection sensitivity.
- You can adjust the sensitivity of all tags with
DEFAULT_SENSITIVITY
and adjust the sensitivity of specific tag(s) withTAGS_SENSITIVITY
- High sensitivity ensures more true positives but also more false positives, while low sensitivity may result in fewer false positives but also fewer true positives.
/// You have 5 options:
/// - Very high sensitivity (-2)
/// - High sensitivity (-1)
/// - Normal (default) ( 0)
/// - Low sensitivity ( 1)
/// - Very low sensitivity ( 2)
const DEFAULT_SENSITIVITY = 0
/// You can set the sensitivity for specific tags.
const TAGS_SENSITIVITY = {
Male_speech: 1
}
Result Summary
- Cochl.Sense provides comprehensive results for each inference unit.
- When activated, this feature abbreviate consecutive results to provide a summary, returning the time and length of the detected tag.
- The ‘interval margin’(
IM
) is a parameter that treats the unrecognized window between tags as part of the recognized ones.DEFAULT_IM
controls the margin for all tags, andTAGS_IM
controls the margin of specific tags. - This feature operates differently in file mode and stream mode.
- In file mode, you can modify the
IM
. - In stream mode, the
IM
cannot be changed and is set to 0.
- In file mode, you can modify the
// Enable Result Summary
const RESULT_ABBREVIATION = true
/// The unit of the im is seconds, there is no limitation.
const DEFAULT_IM = 1
/// Set the im for specific tags.
const TAGS_IM = {
Male_speech: 1
}
Default Hop Size
- The inference interval can be set to either 0.5 seconds or 1 second.
- By default, the system uses overlapping 0.5-second intervals for inferring from 1-second audio data.
- Setting the hop size to 1 second eliminates overlapping intervals during the inference process.
# Hop size's default value is 0.5s and can be set to "1s"
HOP_SIZE = WindowHop("0.5s")
Sensitivity Control
- Once enabled, this feature allows for the adjustment of tag detection sensitivity.
- You can adjust the sensitivity of all tags with
DEFAULT_SENSITIVITY
and adjust the sensitivity of specific tag(s) withTAGS_SENSITIVITY
- High sensitivity ensures more true positives but also more false positives, while low sensitivity may result in fewer false positives but also fewer true positives.
# You have 5 options:
# - Very high sensitivity (-2)
# - High sensitivity (-1)
# - Normal (default) ( 0)
# - Low sensitivity ( 1)
# - Very low sensitivity ( 2)
DEFAULT_SENSITIVITY = DefaultSensitivity(0)
# You can set the sensitivity for specific tags.
TAGS_SENSITIVITY = TagsSensitivity(Male_speech=1)
Result Summary
- Cochl.Sense provides comprehensive results for each inference unit.
- When activated, this feature abbreviate consecutive results to provide a summary, returning the time and length of the detected tag.
- The ‘interval margin’(
IM
) is a parameter that treats the unrecognized window between tags as part of the recognized ones.DEFAULT_IM
controls the margin for all tags, andTAGS_IM
controls the margin of specific tags. - This feature operates differently in file mode and stream mode.
- In file mode, you can modify the
IM
. - In stream mode, the
IM
cannot be changed and is set to 0.
- In file mode, you can modify the
# Enable Result Summary
RESULT_ABBREVIATION = True
# The unit of the im is seconds, there is no limitation.
DEFAULT_IM = 1
# Set the im for specific tags.
TAGS_IM = {"Male_speech": 1}
Sample Codes
You can find the sample codes for Java, Javascript and Python language in the following github repository :
https://github.com/cochlearai/sense-api-samples
For Javascript samples, Node version should be at least 14
For Python samples, Python3.8+ is compatible
Mind that you have to change the PROJECT_KEY variable and insert your personal API key of your Cochl Sense project
PROJECT_KEY = "YOUR_API_PROJECT_KEY"