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 Summary

    Constructors
    Constructor
    Description
    VoiceRecording(@NotNull UUID speakerUUID)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAudio(byte[] opusData)
    Appends an Opus audio frame to this recording.
    void
    Clears the cached decoded PCM samples.
    @Nullable short[]
    Retrieves the cached decoded PCM audio samples, if available.
    float
    Calculates the total duration of the recording in seconds.
    boolean
    Checks whether this recording session has finished.
    boolean
    Checks whether this recording is currently capturing audio.
    void
    setCachedPcm(short @Nullable [] cachedPcm)
    Caches decoded PCM audio samples for subsequent playback.
    slice(long startOffsetMs, long durationMs)
    Slices an audio segment from a start millisecond offset.
    slice(@NotNull Instant timestamp, @NotNull Duration duration)
    Slices an audio segment starting from a specific Instant.
    sliceLast(long durationMs)
    Extracts the last duration in milliseconds of the recording.
    sliceLast(@NotNull Duration duration)
    Extracts the last duration segment of the recording.
    void
    Starts or restarts the recording session.
    void
    Stops the active recording session and computes the total duration.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VoiceRecording

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

    • 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
    • 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.