Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/plugins/audio/metadata.py: 47%
17 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Internal information about the audio plugin."""
18from tensorboard.compat.proto import summary_pb2
19from tensorboard.plugins.audio import plugin_data_pb2
21PLUGIN_NAME = "audio"
23# The most recent value for the `version` field of the `AudioPluginData`
24# proto.
25PROTO_VERSION = 0
27# Expose the `Encoding` enum constants.
28Encoding = plugin_data_pb2.AudioPluginData.Encoding
31def create_summary_metadata(
32 display_name, description, encoding, *, converted_to_tensor=None
33):
34 """Create a `SummaryMetadata` proto for audio plugin data.
36 Returns:
37 A `SummaryMetadata` protobuf object.
38 """
39 content = plugin_data_pb2.AudioPluginData(
40 version=PROTO_VERSION,
41 encoding=encoding,
42 converted_to_tensor=converted_to_tensor,
43 )
44 metadata = summary_pb2.SummaryMetadata(
45 display_name=display_name,
46 summary_description=description,
47 plugin_data=summary_pb2.SummaryMetadata.PluginData(
48 plugin_name=PLUGIN_NAME, content=content.SerializeToString()
49 ),
50 )
51 return metadata
54def parse_plugin_metadata(content):
55 """Parse summary metadata to a Python object.
57 Arguments:
58 content: The `content` field of a `SummaryMetadata` proto
59 corresponding to the audio plugin.
61 Returns:
62 An `AudioPluginData` protobuf object.
63 """
64 if not isinstance(content, bytes):
65 raise TypeError("Content type must be bytes")
66 result = plugin_data_pb2.AudioPluginData.FromString(content)
67 if result.version == 0:
68 return result
69 # No other versions known at this time, so no migrations to do.
70 return result