add json comment-string metadata support #632
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.