Class VoiceRecording

java.lang.Object
fr.dreamin.dreamvoice.api.recording.model.VoiceRecording

public final class VoiceRecording extends Object
Model representing a voice recording session. Stores timestamped Opus frames and supports slicing and duration calculations.
  • Constructor Details

    • VoiceRecording

      public VoiceRecording(@NotNull @NotNull UUID speakerUUID)
  • Method Details

    • getFrames

      @NotNull public @NotNull List<TimedAudioFrame> getFrames()
    • start

      public void start()
      Starts or restarts the recording session.
    • stop

      public void stop()
      Stops the active recording session and computes the total duration.
    • isRecording

      public boolean isRecording()
      Checks whether this recording is currently capturing audio.
      Returns:
      true if actively recording
    • isFinished

      public boolean isFinished()
      Checks whether this recording session has finished.
      Returns:
      true if completed
    • addAudio

      public void addAudio(byte[] opusData)
      Appends an Opus audio frame to this recording.
      Parameters:
      opusData - the raw Opus frame bytes
    • addAudio

      public void addAudio(@Nullable @Nullable UUID speakerUuid, byte[] opusData)
      Appends an Opus audio frame with a specific speaker UUID to this recording.
      Parameters:
      speakerUuid - the author speaker UUID, or null to default to this recording's speaker UUID
      opusData - the raw Opus frame bytes
    • getSpeakers

      @NotNull public Set<UUID> getSpeakers()
      Returns all unique speaker UUIDs present across all recorded audio frames.
      Returns:
      set of speaker UUIDs
    • getFramesOfSpeaker

      @NotNull public @NotNull List<TimedAudioFrame> getFramesOfSpeaker(@NotNull @NotNull UUID speakerUuid)
      Returns all audio frames produced by a specific speaker.
      Parameters:
      speakerUuid - the speaker UUID to filter by
      Returns:
      list of frames matching this speaker
    • extractSpeakerRecording

      @NotNull public @NotNull VoiceRecording extractSpeakerRecording(@NotNull @NotNull UUID speakerUuid)
      Creates a new recording containing only the audio frames of a specific speaker, retaining the original timing offsets and duration.
      Parameters:
      speakerUuid - the speaker UUID to extract
      Returns:
      new VoiceRecording containing only that speaker's track
    • getDurationSeconds

      public float getDurationSeconds()
      Calculates the total duration of the recording in seconds.
      Returns:
      duration in seconds
    • slice

      public VoiceRecording slice(@NotNull @NotNull Instant timestamp, @NotNull @NotNull Duration duration)
      Slices an audio segment starting from a specific Instant.
      Parameters:
      timestamp - the start timestamp
      duration - the length of the slice
      Returns:
      a new sliced VoiceRecording
    • slice

      public VoiceRecording slice(long startOffsetMs, long durationMs)
      Slices an audio segment from a start millisecond offset.
      Parameters:
      startOffsetMs - offset in milliseconds from recording start
      durationMs - slice duration in milliseconds
      Returns:
      a new sliced VoiceRecording
    • sliceLast

      public VoiceRecording sliceLast(@NotNull @NotNull Duration duration)
      Extracts the last duration segment of the recording.
      Parameters:
      duration - the duration to extract
      Returns:
      a new sliced VoiceRecording
    • sliceLast

      public VoiceRecording sliceLast(long durationMs)
      Extracts the last duration in milliseconds of the recording.
      Parameters:
      durationMs - milliseconds to extract
      Returns:
      a new sliced VoiceRecording
    • getCachedPcm

      @Nullable public @Nullable short[] getCachedPcm()
      Retrieves the cached decoded PCM audio samples, if available.
      Returns:
      cached PCM samples, or null if not yet decoded or invalidated
    • setCachedPcm

      public void setCachedPcm(short @Nullable [] cachedPcm)
      Caches decoded PCM audio samples for subsequent playback.
      Parameters:
      cachedPcm - decoded 16-bit 48kHz PCM samples
    • clearCachedPcm

      public void clearCachedPcm()
      Clears the cached decoded PCM samples.