diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioclassifier/AudioClassifierResult.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioclassifier/AudioClassifierResult.java index 3102aa8cd..258e5725b 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioclassifier/AudioClassifierResult.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioclassifier/AudioClassifierResult.java @@ -20,7 +20,6 @@ import com.google.mediapipe.tasks.components.containers.proto.ClassificationsPro import com.google.mediapipe.tasks.core.TaskResult; import java.util.ArrayList; import java.util.List; -import java.util.Optional; /** Represents the classification results generated by {@link AudioClassifier}. */ @AutoValue @@ -40,8 +39,7 @@ public abstract class AudioClassifierResult implements TaskResult { for (ClassificationsProto.ClassificationResult proto : protoList) { classificationResultList.add(ClassificationResult.createFromProto(proto)); } - return new AutoValue_AudioClassifierResult( - Optional.of(classificationResultList), Optional.empty(), timestampMs); + return new AutoValue_AudioClassifierResult(classificationResultList, timestampMs); } /** @@ -53,23 +51,22 @@ public abstract class AudioClassifierResult implements TaskResult { */ static AudioClassifierResult createFromProto( ClassificationsProto.ClassificationResult proto, long timestampMs) { - return new AutoValue_AudioClassifierResult( - Optional.empty(), Optional.of(ClassificationResult.createFromProto(proto)), timestampMs); + List classificationResultList = new ArrayList<>(); + classificationResultList.add(ClassificationResult.createFromProto(proto)); + return new AutoValue_AudioClassifierResult(classificationResultList, timestampMs); } /** * A list of of timestamped {@link ClassificationResult} objects, each contains one set of results - * per classifier head. The list represents the audio classification result of an audio clip, and - * is only available when running with the audio clips mode. + * per classifier head. + * + *

In the "audio stream" mode, the list only contains one element, representing the + * classification result of the audio block that starts at {@link + * ClassificationResult.timestampMs} in the audio stream. Otherwise, in the "audio clips" mode, + * the list may include multiple {@link ClassificationResult} objects, each classifying an + * interval of the entire audio clip that starts at {@link ClassificationResult.timestampMs}. */ - public abstract Optional> classificationResultList(); - - /** - * Contains one set of results per classifier head. A {@link ClassificationResult} usually - * represents one audio classification result in an audio stream, and s only available when - * running with the audio stream mode. - */ - public abstract Optional classificationResult(); + public abstract List classificationResults(); @Override public abstract long timestampMs(); diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java index a986048f0..0cfd2297c 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/audio/audioembedder/AudioEmbedderResult.java @@ -20,7 +20,6 @@ import com.google.mediapipe.tasks.components.containers.proto.EmbeddingsProto; import com.google.mediapipe.tasks.core.TaskResult; import java.util.ArrayList; import java.util.List; -import java.util.Optional; /** Represents the embedding results generated by {@link AudioEmbedder}. */ @AutoValue @@ -35,12 +34,11 @@ public abstract class AudioEmbedderResult implements TaskResult { */ static AudioEmbedderResult createFromProtoList( List protoList, long timestampMs) { - List classificationResultList = new ArrayList<>(); + List embeddingResultList = new ArrayList<>(); for (EmbeddingsProto.EmbeddingResult proto : protoList) { - classificationResultList.add(EmbeddingResult.createFromProto(proto)); + embeddingResultList.add(EmbeddingResult.createFromProto(proto)); } - return new AutoValue_AudioEmbedderResult( - Optional.of(classificationResultList), Optional.empty(), timestampMs); + return new AutoValue_AudioEmbedderResult(embeddingResultList, timestampMs); } /** @@ -52,23 +50,22 @@ public abstract class AudioEmbedderResult implements TaskResult { */ static AudioEmbedderResult createFromProto( EmbeddingsProto.EmbeddingResult proto, long timestampMs) { - return new AutoValue_AudioEmbedderResult( - Optional.empty(), Optional.of(EmbeddingResult.createFromProto(proto)), timestampMs); + List embeddingResultList = new ArrayList<>(); + embeddingResultList.add(EmbeddingResult.createFromProto(proto)); + return new AutoValue_AudioEmbedderResult(embeddingResultList, timestampMs); } /** * A list of of timpstamped {@link EmbeddingResult} objects, each contains one set of results per - * embedder head. The list represents the audio embedding result of an audio clip, and is only - * available when running with the audio clips mode. + * embedder head. + * + *

In the "audio stream" mode, the list only contains one element, representing the embedding + * result of the audio block that starts at {@link EmbeddingResult.timestampMs} in the audio + * stream. Otherwise, in the "audio clips" mode, the list may include multiple {@link + * EmbeddingResult} objects, each contains the embedding of an interval of the entire audio clip + * that starts at {@link EmbeddingResult.timestampMs}. */ - public abstract Optional> embeddingResultList(); - - /** - * Contains one set of results per classifier head. A {@link EmbeddingResult} usually represents - * one audio embedding result in an audio stream, and is only available when running with the - * audio stream mode. - */ - public abstract Optional embeddingResult(); + public abstract List embeddingResults(); @Override public abstract long timestampMs();