Skip to main content

Cochl Sense

Project description

cochl-sense-py

cochl-sense-py is a Python client library providing easy integration of Cochl.Sense API into any Python application. You can upload a file (MP3, WAV, OGG) or raw PCM audio stream.


Installation

cochl-sense-py can be installed and used in Python 3.9+.

pip install --upgrade cochl

Usage

This simple setup is enough to input your file. API project key can be retrieved from Cochl Dashboard.

import cochl.sense as sense

client = sense.Client("YOUR_API_PROJECT_KEY")

results = client.predict("your_file.wav")
print(results.to_dict())  # get results as a dict

You can adjust the custom settings like below. For more details please refer to Advanced Cconfigurations.

import cochl.sense as sense

api_config = sense.APIConfig(
    sensitivity=sense.SensitivityConfig(
        default=sense.SensitivityScale.LOW,
        by_tags={
            "Baby_cry": sense.SensitivityScale.VERY_LOW,
            "Gunshot":  sense.SensitivityScale.HIGH,
        },
    ),
)

client = sense.Client(
    "YOUR_API_PROJECT_KEY",
    api_config=api_config,
)

results = client.predict("your_file.wav")
print(results.to_dict())  # get results as a dict

The file prediction result can be displayed in a summarized format. More details at Summarized Result.

# print(results.to_dict())  # get results as a dict

print(results.to_summarized_result(
    interval_margin=2,
    by_tags={"Baby_cry": 5, "Gunshot": 3}
))  # get results in a simplified format

# At 0.0-1.0s, [Baby_cry] was detected

Cochl.Sense API supports three file formats: MP3, WAV, OGG.
If a file is not in a supported format, it has to be manually converted. More details here.


Advanced Configurations

Sensitivity

Detection sensitivity can be adjusted for all tags or each tag individually.
If you feel that tags are not detected well enough, increase sensitivities. If there are too many false detections, lower sensitivities.

The sensitivity is adjusted with SensitivityScale Enum.

  • VERY_HIGH
  • HIGH
  • MEDIUM (default)
  • LOW
  • VERY_LOW
import cochl.sense as sense

api_config = sense.APIConfig(
    sensitivity=sense.SensitivityConfig(
        # default sensitivity applied to all tags not specified in `by_tags`
        default=sense.SensitivityScale.LOW,
        by_tags={
            "Baby_cry": sense.SensitivityScale.VERY_LOW,
            "Gunshot":  sense.SensitivityScale.HIGH,
        },
    ),
)
client = sense.Client(
    "YOUR_API_PROJECT_KEY",
    api_config=api_config,
)


Other notes

Convert to supported file formats (WAV, MP3, OGG)

Pydub is one of the easy ways to convert audio file into a supported format (WAV, MP3, OGG).

First install Pydub refering to this link.
Then write a Python script converting your file into a supported format like below.

from pydub import AudioSegment

mp4_version = AudioSegment.from_file("sample.mp4", "mp4")
mp4_version.export("sample.mp3", format="mp3")

For more details of Pydub, please refer to this link.


Summarzied Result

You can summarize the file prediction result by aggregating consecutive windows, returning the time and length of the detected tag.
The 'interval margin' is a parameter that treats the unrecognized window between tags as part of the recognized ones and it affects all sound tags. If you want to specify a different interval margin for specific sound tags, you can use the 'by_tags' option.

print(results.to_summarized_result(
    interval_margin=2,
    by_tags={"Baby_cry": 5, "Gunshot": 3}
))

# At 0.0-1.0s, [Baby_cry] was detected

Links

Documentation: https://docs.cochl.ai/sense/api/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cochl-1.0.10.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

cochl-1.0.10-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file cochl-1.0.10.tar.gz.

File metadata

  • Download URL: cochl-1.0.10.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for cochl-1.0.10.tar.gz
Algorithm Hash digest
SHA256 d732b0d3db63ab5dd06ed0835d44c604aa9b250534eb67a410dbaf22f6d3b244
MD5 a5752eba194e3fefd86fde80a327616c
BLAKE2b-256 9fb3813dcd7fd42bd6bca3c763c106381ee5e3374ea371f7e24f0a41d4552c1c

See more details on using hashes here.

File details

Details for the file cochl-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: cochl-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for cochl-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ce26fbedd16fe6c773f6aed09cb766a665e6c6b72f486f878514f2c35b7e5a05
MD5 ca0dc6af5861bdbd442e2c7ee8367b5d
BLAKE2b-256 b14cea0f46018a1b3e56d9d03ba29a7cacac415b73b1aeb375d6fdbdbb955e86

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page