tomusic-ai
v1767493.965.194
Published
Professional integration for https://tomusic.ai/
Readme
tomusic-ai
A JavaScript library to programmatically interact with the tomusic.ai platform, enabling music generation and manipulation directly from your code. This package provides a simple and efficient way to integrate AI-powered music tools into your applications.
Installation
Install the package using npm: bash npm install tomusic-ai
Usage Examples
Here are a few examples demonstrating how to use the tomusic-ai package in your JavaScript applications:
1. Generate a Melody: javascript const tomusic = require('tomusic-ai');
async function generateMelody() { try { const melody = await tomusic.generateMelody({ style: 'Classical', tempo: 120, key: 'C Major', duration: 30 // seconds });
console.log('Generated Melody:', melody);
// You can then save or play the generated melody (e.g., as MIDI).} catch (error) { console.error('Error generating melody:', error); } }
generateMelody();
2. Harmonize an Existing Melody: javascript const tomusic = require('tomusic-ai');
async function harmonizeMelody(melodyData) { // melodyData should be a suitable format (e.g., MIDI data) try { const harmony = await tomusic.harmonizeMelody(melodyData, { style: 'Jazz', voiceCount: 4 });
console.log('Harmonized Melody:', harmony);
// Process the harmonized melody as needed.} catch (error) { console.error('Error harmonizing melody:', error); } }
// Example Usage (replace with actual melody data): const myMelody = { /* ... your melody data ... */ }; harmonizeMelody(myMelody);
3. Generate Music Based on Textual Description: javascript const tomusic = require('tomusic-ai');
async function generateFromText(description) { try { const music = await tomusic.generateFromText(description, { duration: 60, // seconds instrument: 'Piano' });
console.log('Generated Music from Text:', music);
// Save or stream the generated music.} catch (error) { console.error('Error generating music from text:', error); } }
generateFromText('A happy piano piece for a sunny day.');
4. Change the Tempo of a Song: javascript const tomusic = require('tomusic-ai');
async function changeTempo(songData, newTempo) { try { const modifiedSong = await tomusic.changeTempo(songData, newTempo);
console.log('Tempo changed:', modifiedSong);
// Play or save the modified song.} catch (error) { console.error('Error changing tempo:', error); } }
// Example Usage (replace with actual song data and new tempo): const mySong = { /* ... your song data ... */ }; const desiredTempo = 140; changeTempo(mySong, desiredTempo);
5. Generate Background Music for a Video: javascript const tomusic = require('tomusic-ai');
async function generateBackgroundMusic(videoDescription) { try { const backgroundMusic = await tomusic.generateBackgroundMusic(videoDescription, { duration: 120, // seconds style: 'Ambient', });
console.log('Generated background music:', backgroundMusic);
// Integrate the generated music with your video.} catch (error) { console.error('Error generating background music:', error); } }
generateBackgroundMusic('A nature documentary about rainforests.');
API Summary
generateMelody(options): Generates a melody based on the provided options (style, tempo, key, duration). Returns a promise that resolves with the melody data.harmonizeMelody(melodyData, options): Harmonizes an existing melody. Requires melody data and options such as style and voice count. Returns a promise resolving with the harmonized melody data.generateFromText(description, options): Generates music based on a textual description. Options include duration and instrument. Returns a promise resolving with the generated music data.changeTempo(songData, newTempo): Changes the tempo of a song. Requires song data and the desired new tempo. Returns a promise resolving with the modified song data.generateBackgroundMusic(videoDescription, options): Generates background music suitable for a video based on its description. Options include duration and style. Returns a promise resolving with the generated music data.
License
MIT
This package is part of the tomusic-ai ecosystem. For advanced features and enterprise-grade tools, visit: https://tomusic.ai/
