-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public final class Avatar implements AutoCloseable
High-level Essence avatar facade.
Owns a single fixture + a single runtime. For multi-conversation scenarios (one shared fixture, N independent histories), use Fixture and Runtime directly.
Typical use:
Avatar.load("/sdcard/Android/data/.../files/sample-avatar.imx").use { a -> a.composeAsBitmaps(pcm).forEach { bmp -> imageView.setImageBitmap(bmp) } }Not thread-safe: confine calls (and the Sequence iteration) to one thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumAvatar.EncoderQualityABI v5: encoder quality preset for recordMp4.
public classAvatar.Companion
-
Field Summary
Fields Modifier and Type Field Description private final IntegerframeWidthprivate final IntegerframeHeightprivate final IntegersampleRateprivate final IntegersamplesPerTick
-
Method Summary
Modifier and Type Method Description final IntegergetFrameWidth()final IntegergetFrameHeight()final IntegergetSampleRate()PCM input sample rate the runtime expects (always 16000 Hz). final IntegergetSamplesPerTick()final Sequence<ComposedFrame>compose(FloatArray audio)Synchronously composes BGR frames from audio. final Sequence<Bitmap>composeAsBitmaps(FloatArray audio)Convenience: maps compose through bgrToBitmap so the caller can drop the result straight into an ImageView/Imagecomposable.final Sequence<ComposedFrame>composeFromFile(String audioPath)Decodes audioPath (WAV or anything MediaExtractorunderstands — MP3, M4A, OGG, FLAC) to 16 kHz mono PCM and streams composed frames.Unitclose()final UnitrecordMp4(String audioPath, String outputPath, Integer targetWidth, Integer targetHeight, Avatar.EncoderQuality quality)One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence. final UnitrecordMp4(String audioPath, String outputPath, Integer targetWidth, Integer targetHeight)One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence. final UnitrecordMp4(String audioPath, String outputPath, Integer targetWidth)One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence. final UnitrecordMp4(String audioPath, String outputPath)One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence. -
-
Method Detail
-
getFrameWidth
final Integer getFrameWidth()
-
getFrameHeight
final Integer getFrameHeight()
-
getSampleRate
final Integer getSampleRate()
PCM input sample rate the runtime expects (always 16000 Hz).
-
getSamplesPerTick
final Integer getSamplesPerTick()
-
compose
final Sequence<ComposedFrame> compose(FloatArray audio)
Synchronously composes BGR frames from audio. The sequence is lazy and single-pass — collect it on one thread.
audio.sizemust be a multiple of samplesPerTick; any tail samples are dropped.Each emitted frame allocates its own backing ByteArray. If you need zero-allocation, call Runtime.tickCompose directly.
-
composeAsBitmaps
final Sequence<Bitmap> composeAsBitmaps(FloatArray audio)
Convenience: maps compose through bgrToBitmap so the caller can drop the result straight into an
ImageView/Imagecomposable.
-
composeFromFile
final Sequence<ComposedFrame> composeFromFile(String audioPath)
Decodes audioPath (WAV or anything
MediaExtractorunderstands — MP3, M4A, OGG, FLAC) to 16 kHz mono PCM and streams composed frames.Uses platform
MediaExtractor+MediaCodec. Channel-mix and resample are handled by the codec via output-format reconfiguration where supported; otherwise we resample with a naive linear pass — fine for voice but not music.
-
recordMp4
@JvmOverloads() final Unit recordMp4(String audioPath, String outputPath, Integer targetWidth, Integer targetHeight, Avatar.EncoderQuality quality)
One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence.
Replaces the per-binding decodeToMono16k + manual frame loop orchestration. Encoder dispatch is automatic: h264_mediacodec on Android (hardware), libx264 as fallback.
- Parameters:
audioPath- any libavformat-supported audio source.outputPath- destination .mp4 path.targetWidth- target canvas width (0 = native fixture frame size).targetHeight- target canvas height (0 = native).quality- encoder preset.
-
recordMp4
@JvmOverloads() final Unit recordMp4(String audioPath, String outputPath, Integer targetWidth, Integer targetHeight)
One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence.
Replaces the per-binding decodeToMono16k + manual frame loop orchestration. Encoder dispatch is automatic: h264_mediacodec on Android (hardware), libx264 as fallback.
- Parameters:
audioPath- any libavformat-supported audio source.outputPath- destination .mp4 path.targetWidth- target canvas width (0 = native fixture frame size).targetHeight- target canvas height (0 = native).
-
recordMp4
@JvmOverloads() final Unit recordMp4(String audioPath, String outputPath, Integer targetWidth)
One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence.
Replaces the per-binding decodeToMono16k + manual frame loop orchestration. Encoder dispatch is automatic: h264_mediacodec on Android (hardware), libx264 as fallback.
- Parameters:
audioPath- any libavformat-supported audio source.outputPath- destination .mp4 path.targetWidth- target canvas width (0 = native fixture frame size).
-
recordMp4
@JvmOverloads() final Unit recordMp4(String audioPath, String outputPath)
One-shot session record: decode the audio file, drive the compose loop, encode H.264 + AAC, mux into an MP4 — all inside libessence.
Replaces the per-binding decodeToMono16k + manual frame loop orchestration. Encoder dispatch is automatic: h264_mediacodec on Android (hardware), libx264 as fallback.
- Parameters:
audioPath- any libavformat-supported audio source.outputPath- destination .mp4 path.
-
-
-
-