Audio files support annotation using classifications. Classifications are applied to a range (duration in milliseconds) on the audio file. Using the Encord SDK you can import classifications directly to audio files that already exist in an Annotate Project. You can also use the SDK to view classifications that exist on an audio file.

Critical Information

Using classifications on an audio file is smilar to using labels or classifications on a video file. There are some critical differences though:

  • Only classifications are supported for audio files. Object labels are not supported on audio files. This means that frame_view and frame_view_metadata are NOT supported.

  • 1 “frame” = 1 millisecond for audio files when importing classifications.

  • get_annotation only works when frame=0. This is because audio files do not have frames. This means ALL annotations made on the classification instance share the same annotation data.

  • When creating a classification for an audio file, the classification_instance uses the range_only=True argument.

For example, Classification.create_instance(range_only=True) or classification_instance = ClassificationInstance(range_only=True)

  • To view the classifications present on a particular range, you MUST use get_ranges to loop through the classifications.

ranges = []
for range in classification_instance.get_ranges():
   ranges.append([range.start, range.end])

View Classifications on Audio Files


# Import dependencies
from encord import EncordUserClient

# Instantiate client
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
)

# Specify Project
project = user_client.get_project("<project_id>")

# Downloads a local copy of all the labels
label_rows = project.list_label_rows_v2(include_all_label_branches=True) 

for label_row in label_rows:
    print(f"Title: {label_row.data_title}, branch: {label_row.branch_name}")

    # Download the label content
    label_row.initialise_labels()

    # Print all essential classification information
    for classification_instance in label_row.get_classification_instances():
        print(f"classificationHash: {classification_instance.classification_hash}")
        print(f"Classification name: {classification_instance.classification_name}")
        print(f"featureHash: {classification_instance.feature_hash}")
        print(f"Classification answer: {classification_instance.get_answer().value}")
        print(f"Classification answer hash: {classification_instance.get_answer().feature_node_hash}")

Export Classifications from Audio Files


# Import dependencies
from encord import EncordUserClient
import json

SSH_PATH = "<path-to-your-shh-private-key>"

PROJECT_ID = "<your-project-id>"

# Authenticate with Encord using the path to your private key
user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Specify Project
project = user_client.get_project(PROJECT_ID)



# Downloads a local copy of all the labels
label_rows = project.list_label_rows_v2(include_all_label_branches=True) 

for label_row in label_rows:
    print(f"Title: {label_row.data_title}, branch: {label_row.branch_name}")

    # Download the label content
    label_row.initialise_labels()

    # Export classifications
    classifications = []
    for classification_instance in label_row.get_classification_instances():
        classification_data = {
            "classificationHash": classification_instance.classification_hash,
            "name": classification_instance.classification_name,
            "featureHash": classification_instance.feature_hash,
            "answer": classification_instance.get_answer().value,
            "answerHash": classification_instance.get_answer().feature_node_hash,
        }
        classifications.append(classification_data)
    
    # Print or save the exported classifications
    print(json.dumps(classifications, indent=2))
    # Alternatively, you can save to a file:
    # with open(f"{label_row.data_title}_classifications.json", "w") as f:
    #     json.dump(classifications, f, indent=2)

Import Classifications to Audio Files