Basic functionality.
Previous:
narrator.speak(text, options);Now you pass a unified object, e.g.:
narrator.speak({ text, ...options });
narrator.resolve({ text, ...options });Sound settings are now configured directly on the narrator instance and can be passed to the narrator methods. The Narration now only contains the metadata and the audio string. They were not configured properly before.
const narrator = createMockNarrator();
// set narrator default playback options
narrator.setDefaultPlaybackOptions({
gain: -5.2,
playbackRate: 1.2,
});
// or provide them per narration
narrator.speak({
text: "Hello, world!",
},
{
gain: -5.2, // Override default volume for this narration
}
);
// also available when using start()
narrator.start(narration,
{
gain: -5.2, // Override default volume for this narration
}
);Thanks to NeverOccurs for the contribution! See PR here.
A wrapper provider that deduplicates identical text requests to avoid generating the same audio multiple times when the same text is requested more than once.
The AudioCache and ViteCachePlugin have been replaced with the generic motion-canvas-cache package. This provides a cleaner separation of concerns:
Breaking Changes:
- Vite Plugin: Import
motionCanvasCachePlugindirectly frommotion-canvas-cacheinstead of the oldmotionCanvasNarratorPlugin - AudioUtils: The following methods have been moved to
CacheUtilsfrommotion-canvas-cache:AudioUtils.generateAudioId()→CacheUtils.generateCacheKey()AudioUtils.streamToArrayBuffer()→CacheUtils.streamToArrayBuffer()AudioUtils.blobToDataUrl()→CacheUtils.blobToDataUrl()
- AudioUtils now only contains audio-specific methods:
getAudioDuration()and its helpers
Migration Guide:
// Before
import { motionCanvasNarratorPlugin } from 'motion-canvas-narrator/vite-plugin';
// After
import { motionCanvasCachePlugin } from 'motion-canvas-cache/vite-plugin';The cache directory now defaults to motion-canvas-cache instead of narrator-cache.
This allows resolving multiple narrations in parallel, e.g.:
const narrations = yield narrator.resolveAll(["A", "B", "C"]);