Skip to main content

Recognize strumming

Learn how to create requests to recognize strumming direction in audio.

1. Request via API

Example python snippet: (also see step 1 in Basic Job Workflow)


import requests

API_KEY = 'YOUR_KLANGIO_API_KEY'

audio_file = open('{YOUR_FILE_NAME}', 'rb')

query_parameters = {
'webhook_url': '{YOUR_WEBHOOK_ENDPOINT_URL}' # optional, but recommended
}

multipart_params = {
'file': audio_file
}

resp = requests.post(
'https://api.klang.io/strum-recognition',
headers={
'kl-api-key': API_KEY
},
params=query_parameters,
files=multipart_params
)

if resp.status_code == 200:
print(resp.json())
# {
# 'job_id': 'SOME_JOB_ID',
# 'creation_date': '2023-01-01',
# 'deletion_date': '2023-02-01',
# 'status_endpoint_url': 'https://api.klang.io/job/{SOME_JOB_ID}/status'
# }

2. Check Job Status

See step 2 in Basic Job Workflow

3. Get the Output Data

Once the strum recognition job is in state COMPLETED or the webhook notification is received, you can fetch the output results from the job/{job_id}/json endpoint.

Here is an example python code snippet to fetch the json of the strum recognition job: (also see step 3 in Basic Job Workflow)

  import requests

API_KEY = 'YOUR_KLANGIO_API_KEY'

resp = requests.get(
'https://api.klang.io/job/{YOUR_JOB_ID}/json',
headers={
'kl-api-key': API_KEY
})

if resp.status_code == 200:
print(resp.json())

4. Result format

The strum recognition detects the direction and timing of each strum of the audio file.

The job result is an array of the strumming directions with timings. It is stored as json with the key strums and has the format: [<time_stamp_in_seconds>, <strum_direction>] with the type [float, string]. The <strum_direction> are the two values "U" for up- and "D" for down-strokes.

Example:

{
"strums": [
[
0.6461865848302841,
"D"
],
...
[
1.0264313435554504,
"U"
],
],
}