npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

als-math-audio-composer

v1.1.0

Published

A Node.js library to generate audible mathematical expressions in multiple languages. Ideal for educational tools, accessibility applications, and interactive web content.

Downloads

7

Readme

als-math-audio-composer

The als-math-audio-composer is a Node.js library designed to generate audio files from mathematical expressions. It supports expressions involving numbers (0-9) and basic arithmetic operators (+, -, *, /) in multiple languages. This library is useful for educational software, accessibility tools, or any application where you need to convert math expressions into audible format.

Installation

Install the package via npm:

npm install als-math-audio-composer

Usage

Here's how to use als-math-audio-composer to generate audio from a mathematical expression:

const MathAudioComposer = require('als-math-audio-composer');

// Create an instance of the MathAudioComposer
const audioComposer = new MathAudioComposer('eng'); // Supports 'eng', 'ru', and 'he'

// Generate audio for a given expression
const audioBuffer = audioComposer.create('1+2');

// Generate HTML audio element for direct embedding
const audioHtml = audioComposer.html('1+2');
console.log(audioHtml);

Constructor

The constructor accepts one optional parameter:

  • lang: Specifies the language of the audio files. Default is 'eng'. Available options are 'eng', 'ru', 'he'. The constructor throws an error if an unsupported language is specified, ensuring that only available languages are used.

Methods

create(expression)

  • Takes a string expression containing numbers and arithmetic operators.
  • Returns a Buffer of the generated audio.
  • Example: audioComposer.create('3*4')

html(expression)

  • Generates HTML string with a button and an audio element that plays the expression.
  • Useful for embedding directly into web pages.
  • Example: audioComposer.html('3/4')

cacheAll()

  • Preloads all necessary audio files for the specified language into the cache. This is useful for improving performance by loading all audio data into memory at startup.
  • Example: audioComposer.cacheAll()

Caching

als-math-audio-composer utilizes a caching mechanism to enhance performance. Once an audio file is read from the disk, it is stored in memory. Subsequent requests for the same audio file will use the cached version, reducing disk I/O and speeding up audio generation.

  • Caches are maintained separately for each supported language.
  • The cacheAll() method can be used at application startup to preload all necessary audio files into the cache.

Important Notes

  • Error Handling: The create method may throw an error if an audio file is missing or inaccessible. This is highly unlikely but could happen in extreme cases. Use try-catch to handle such scenarios.

  • Performance: On first run, readFileSync is used, which might block the Node.js event loop. This is generally imperceptible and only occurs at the start.

  • Security: The html method does not perform sanitization of the input expression. Ensure that user input is sanitized before passing it to prevent XSS vulnerabilities.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.