Assets Module¶
The assets module provides functions for accessing and managing skill assets like files, images, and audio in your AviScript skills.
File Functions¶
assets.get(file)¶
Gets the full path to an asset file.
Parameter: - file: Relative path to the asset file
Returns: - String: Full path to the asset file
assets.exists(file)¶
Checks if an asset file exists.
Parameter: - file: Relative path to the asset file
Returns: - bool: True if the file exists, false otherwise
if assets.exists("data/user_preferences.json") {
// Use the file
} else {
// Create default preferences
}
assets.read_text(file)¶
Reads a text file and returns its contents as a string.
Parameter: - file: Relative path to the text file
Returns: - String: Contents of the file
assets.read_json(file)¶
Reads a JSON file and returns its parsed contents as a map.
Parameter: - file: Relative path to the JSON file
Returns: - Map: Parsed JSON content
Audio Submodule¶
The assets.audio submodule provides functions for playing and controlling audio files.
assets.audio.play(file)¶
Plays an audio file.
Parameter: - file: Relative path to the audio file
assets.audio.stop()¶
Stops the currently playing audio.
assets.audio.is_playing()¶
Checks if audio is currently playing.
Returns: - bool: True if audio is playing, false otherwise
assets.audio.volume(level)¶
Sets the audio volume level.
Parameter: - level: Volume level (0-100)
assets.audio.mute()¶
Mutes the audio.
assets.audio.unmute()¶
Unmutes the audio.
Example Usage¶
on_intent "play_tutorial" {
// Check if tutorial exists
if assets.exists("tutorials/beginner.mp3") {
speak.text("Playing the beginner tutorial now.");
// Set volume and play
assets.audio.volume(80);
assets.audio.play("tutorials/beginner.mp3");
// Display accompanying image
// Load supplementary text
let tips = assets.read_text("tutorials/beginner_tips.txt");
context.save("current_tips", tips);
} else {
speak.text("Sorry, the tutorial isn't available.");
}
}
Best Practices¶
- Always check if files exist before attempting to use them
- Use appropriate file formats for different asset types
- Keep audio files short and high-quality
- Organize assets in a logical directory structure
- Use volume controls responsibly to prevent jarring audio experiences