PlayNoise.js
PlayNoise.js is a lightweight JavaScript library that enables music creation directly in the browser using Recorded Voices and YAML-based scores. It allows users to generate stereo audio and export it as WAV files, making it an excellent tool for web-based music and audio projects.
Features
- Voice-to-Instrument Conversion: Convert recorded voice audio into musical instrument tones for unique and creative sound generation.
- YAML-Based Scores: Write music effortlessly with simple YAML syntax.
- Browser-Compatible: Fully functional in modern web browsers.
- Stereo Audio: Supports stereo audio generation.
- WAV File Export: Export audio as downloadable WAV files.
- Customizable Sound Properties: Control tempo, frequency, amplitude, and more.
Installation
Add PlayNoise.js to your project via a <script>
tag.
-
Download the
dist/pn-library.js
file from the repository. -
Include it in your HTML:
<script type="module" src="path/to/pn-library.js"></script>
Usage
Example: Create a Simple Tone
-
Include the library in your project:
<!-- Include the pn-library.js script --> <script src="pn-library.js"></script> <script> // Wrap everything in an async function async function runPNExample() { console.log(PN); // This should print the PN object PN.instrument("Piano"); // Select the instrument // PN.setVolume(0.5); // Set volume (optional) // Wait for PN.singVoice to complete const song = await PN.singVoice("recording2.wav"); console.log("Song created:", song); console.log(PN.volume); // Logs the current volume setTimeout(() => { PN.save(); // Call save after the delay }, 8000); // Delay in milliseconds (5000ms = 5s) } // Run the function runPNExample(); </script>
-
Open the HTML file in your browser, and the WAV file will be generated and available for download.
Scripts
build
: Builds the library for the browser using Webpack.lint
: Runs ESLint to ensure code quality.lint-fix
: Automatically fixes code style issues.test
: Runs unit tests using Jest.docs
: Generates documentation using JSDoc.
Run these scripts using npm:
npm run <script-name>
Documentation
Generate the documentation using:
npm run docs
This will output documentation in the docs/
directory.
Contributing
Contributions are welcome! Here’s how you can contribute:
- Fork this repository.
- Create a feature branch:
git checkout -b feature-name
. - Commit your changes:
git commit -m "Add new feature"
. - Push to your branch:
git push origin feature-name
. - Submit a pull request.
Dependencies
PlayNoise.js relies on modern browser APIs and lightweight libraries to handle core functionality:
- js-yaml: Parse and serialize YAML.
- wav-encoder: Encode WAV files.
- fft-js: Fast Fourier Transform for audio processing.
- yinjs: A pitch detection library.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Developed by Forcha Pearl Fri.
Feel free to open an issue or submit a pull request if you have any questions or suggestions!
Happy Coding! 🎶