Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add json comment-string metadata support #632

Merged
merged 1 commit into from
Jan 9, 2023
Merged

Conversation

sammlapp
Copy link
Collaborator

@sammlapp sammlapp commented Jan 8, 2023

Resolves #565
Audio save and load now supports (and uses by default) writing .metadata dictionary to a json string in the "comment" field of the standard WAV file metadata. We can add new versioned standards for the content of the "opso_metadata" JSON, I've named the current one "v0.1". It prepends the string "opso_metadata" to the json string. This v0.1 standard allows keys with any typical json values (numbers and strings) and one special value for the key "recording_start_time" which is saved to iso string format and loaded as a localized datetime.datetime object.

The maximum size of the metadata dictionary seems to be about 65 20-character strings or 160 integers. Trying to save more will result in fallback to default soundfile metadata. Soundfile doesn't give any complaint though, so this is a silent error.

The api for Audio has changed: .from_file boolean argument "metadata" is now "load_metadata" and .save() allows the user to choose "metadata_format" ("soundfile" reproduces previous behavior, "opso" chooses newest opso_metadata format, or user can specify exact format as "opso_metadata_v0.1"

I still use soundfile to update file metadata.

I have updated audio methods .trim(), .loop() and .extend() to update the relevant metadata - for instance, trim() will update "recording_start_time" to reflect the start time of the new audio object.

I have added tests to cover the new scenarios.

Audio save and load now supports (and uses by default) writing .metadata dictionary to a json string in the "comment" field of the standard WAV file metadata. We can add new versioned standards for the content of the "opso_metadata" JSON, I've named the current one "v0.1". It prepends the string "opso_metadata" to the json string. This v0.1 standard allows keys with any typical json values (numbers and strings) and one special value for the key "recording_start_time" which is saved to iso string format and loaded as a localized datetime.datetime object.

The maximum size of the metadata dictionary seems to be about 65 20-character strings or 160 integers. Trying to save more will result in fallback to default soundfile metadata. Soundfile doesn't give any complaint though, so this is a silent error.

The api for Audio has changed: .from_file boolean argument "metadata" is now "load_metadata" and .save() allows the user to choose "metadata_format" ("soundfile" reproduces previous behavior, "opso" chooses newest opso_metadata format, or user can specify exact format as "opso_metadata_v0.1"

I still use soundfile to update file metadata.

I have updated audio methods .trim(), .loop() and .extend() to update the relevant metadata - for instance, trim() will update "recording_start_time" to reflect the start time of the new audio object.

I have added tests to cover the new scenarios.
@sammlapp sammlapp merged commit 035decb into develop Jan 9, 2023
@sammlapp sammlapp deleted the feat_565_json_metadata branch May 6, 2023 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant