Spaces:
Running
Running
export const LENGTHS = [ | |
{ value: 5, label: "00:05" }, | |
{ value: 10, label: "00:10" }, | |
{ value: 15, label: "00:15" }, | |
{ value: 30, label: "00:30" }, | |
]; | |
export const STYLES = [{ | |
value: "none", | |
prompt: "", | |
label: "None", | |
},{ | |
value: "hiphop", | |
prompt: "Hip Hop and Rap track", | |
label: "Hip Hop", | |
image: "https://images.unsplash.com/photo-1601643157091-ce5c665179ab?q=80&w=2072&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", | |
}, { | |
value: "classic", | |
prompt: "Classic track", | |
label: "Classic", | |
image: "https://images.unsplash.com/photo-1519139270028-ab664cf42264?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "jazz", | |
prompt: "Jazz track", | |
label: "Jazz", | |
image: "https://images.unsplash.com/photo-1511192336575-5a79af67a629?q=80&w=2064&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "electro", | |
prompt: "Electronic and dance track", | |
label: "Electro & Dance", | |
image: "https://images.unsplash.com/photo-1622386010273-646e12d1c02f?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "rock", | |
prompt: "Rock'n'Roll track", | |
label: "Rock'N'Roll", | |
image: "https://plus.unsplash.com/premium_photo-1681876467464-33495108737c?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "funk", | |
prompt: "Funk track", | |
label: "Funk", | |
image: "https://plus.unsplash.com/premium_photo-1683129651802-1c7ba429a137?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "dubstep", | |
prompt: "Dubstep track", | |
label: "Dubstep", | |
image: "https://images.unsplash.com/photo-1578946956088-940c3b502864?q=80&w=2046&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "afrobeats", | |
prompt: "Afrobeats track", | |
label: "Afrobeats", | |
image: "https://plus.unsplash.com/premium_photo-1702220976033-50f47c7a58a6?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "orchestral", | |
prompt: "Orchestral track", | |
label: "Orchestral", | |
image: "https://plus.unsplash.com/premium_photo-1682098438728-fa774b584c18?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "pop", | |
prompt: "Pop track", | |
label: "Pop", | |
image: "https://images.unsplash.com/photo-1520872024865-3ff2805d8bb3?q=80&w=2104&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "reggae", | |
prompt: "Reggae track", | |
label: "Reggae", | |
image: "https://images.unsplash.com/photo-1538598450935-581f6a5fa7e0?q=80&w=2088&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "metal", | |
prompt: "Metal track", | |
label: "Metal", | |
image: "https://images.unsplash.com/photo-1506091403742-e3aa39518db5?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "country", | |
prompt: "Country track", | |
label: "Country", | |
image: "https://images.unsplash.com/photo-1525814230241-7f78c608c54c?q=80&w=1976&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "blues", | |
prompt: "Blues track", | |
label: "Blues", | |
image: "https://plus.unsplash.com/premium_photo-1661333454734-9184250f7226?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "soul", | |
prompt: "Soul track", | |
label: "Soul", | |
image: "https://images.unsplash.com/photo-1581297848080-c84ac0438210?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "rnb", | |
prompt: "R'n'B track", | |
label: "R&B", | |
image: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR3D-yMSiaEBtOOoxrKh8InCYzRqjn1UnYVHPhbDGkPrXH32k7i091MRvRTP7Nyts8dMJY&usqp=CAU" | |
}, { | |
value: "disco", | |
prompt: "Disco track", | |
label: "Disco", | |
image: "https://images.unsplash.com/photo-1559424452-eeb3a13ffe2b?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "trap", | |
prompt: "Trap track", | |
label: "Trap", | |
image: "https://images.unsplash.com/photo-1620281428428-bce2bf9ceee4?q=80&w=1970&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "ambient", | |
prompt: "Ambient track", | |
label: "Ambient", | |
image: "https://images.unsplash.com/photo-1616085290694-4b9cc5c97a12?q=80&w=2128&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}, { | |
value: "lofi", | |
prompt: "Lofi track", | |
label: "Lofi", | |
image: "https://miro.medium.com/v2/resize:fit:1358/0*FjF2hZ8cJQN9aBxk.jpg" | |
}, { | |
value: "chill", | |
prompt: "Chill track", | |
label: "Chill", | |
image: "https://images.unsplash.com/photo-1531574373289-ad0d66e39ba9?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" | |
}] | |
export const MOODS = [{ | |
value: "none", | |
label: "None", | |
prompt: "", | |
emoji: "" | |
},{ | |
value: "happy", | |
label: "Happy", | |
prompt: "with an happy vibe", | |
emoji: "😊" | |
}, { | |
value: "sad", | |
label: "Sad", | |
prompt: "with a sad vibe", | |
emoji: "😢" | |
}, { | |
value: "angry", | |
label: "Angry", | |
prompt: "with an angry vibe", | |
emoji: "😡" | |
}, { | |
value: "chill", | |
label: "Chill", | |
prompt: "with a chill vibe", | |
emoji: "😌" | |
}, { | |
value: "romantic", | |
label: "Romantic", | |
prompt: "with a romantic vibe", | |
emoji: "😍" | |
}, { | |
value: "epic", | |
label: "Epic", | |
prompt: "with an epic vibe", | |
emoji: "🚀" | |
}, { | |
value: "energetic", | |
label: "Energetic", | |
prompt: "with an energetic vibe", | |
emoji: "🔥" | |
}, { | |
value: "dreamy", | |
label: "Dreamy", | |
prompt: "with a dreamy vibe", | |
emoji: "🌌" | |
}, { | |
value: "mysterious", | |
label: "Mysterious", | |
prompt: "with a mysterious vibe", | |
emoji: "🕵️" | |
}, { | |
value: "relaxing", | |
label: "Relaxing", | |
prompt: "with a relaxing vibe", | |
emoji: "😴" | |
}, { | |
value: "dark", | |
label: "Dark", | |
prompt: "with a dark vibe", | |
emoji: "🖤" | |
}, { | |
value: "upbeat", | |
label: "Upbeat", | |
prompt: "with an upbeat vibe", | |
emoji: "🎉" | |
}, { | |
value: "motivational", | |
label: "Motivational", | |
prompt: "with a motivational vibe", | |
emoji: "💪" | |
}, { | |
value: "inspiring", | |
label: "Inspiring", | |
prompt: "with an inspiring vibe", | |
emoji: "🌟" | |
}, { | |
value: "nostalgic", | |
label: "Nostalgic", | |
prompt: "with a nostalgic vibe", | |
emoji: "📼" | |
}, { | |
value: "groovy", | |
label: "Groovy", | |
prompt: "with a groovy vibe", | |
emoji: "🕺" | |
}, { | |
value: "melancholic", | |
label: "Melancholic", | |
prompt: "with a melancholic vibe", | |
emoji: "😔" | |
}, { | |
value: "hopeful", | |
label: "Hopeful", | |
prompt: "with a hopeful vibe", | |
emoji: "🌈" | |
}] | |
export const MUSIC_PROMPTS = [ | |
'80s pop track with bassy drums and synth', | |
'90s rock song with loud guitars and heavy drums', | |
'a light and cheerly EDM track, with syncopated drums, aery pads, and strong emotions bpm: 130', | |
'A cheerful country song with acoustic guitars', | |
'lofi slow bpm electro chill with organic samples', | |
] | |
export function encodeWAV(samples: any[], sampleRate = 16000) { | |
let offset = 44; | |
const buffer = new ArrayBuffer(offset + samples.length * 4); | |
const view = new DataView(buffer); | |
/* RIFF identifier */ | |
writeString(view, 0, 'RIFF') | |
/* RIFF chunk length */ | |
view.setUint32(4, 36 + samples.length * 4, true) | |
/* RIFF type */ | |
writeString(view, 8, 'WAVE') | |
/* format chunk identifier */ | |
writeString(view, 12, 'fmt ') | |
/* format chunk length */ | |
view.setUint32(16, 16, true) | |
/* sample format (raw) */ | |
view.setUint16(20, 3, true) | |
/* channel count */ | |
view.setUint16(22, 1, true) | |
/* sample rate */ | |
view.setUint32(24, sampleRate, true) | |
/* byte rate (sample rate * block align) */ | |
view.setUint32(28, sampleRate * 4, true) | |
/* block align (channel count * bytes per sample) */ | |
view.setUint16(32, 4, true) | |
/* bits per sample */ | |
view.setUint16(34, 32, true) | |
/* data chunk identifier */ | |
writeString(view, 36, 'data') | |
/* data chunk length */ | |
view.setUint32(40, samples.length * 4, true) | |
for (let i = 0; i < samples.length; ++i, offset += 4) { | |
view.setFloat32(offset, samples[i], true) | |
} | |
return buffer | |
} | |
function writeString(view: any, offset: number, string: string) { | |
for (let i = 0; i < string.length; ++i) { | |
view.setUint8(offset + i, string.charCodeAt(i)) | |
} | |
} | |
export const MODEL_ID = 'Xenova/musicgen-small'; | |
export async function share(body: any, settings: Record<string, any>, results: Record<string, any>) { | |
const response = await fetch('https://huggingface.co/uploads', { method: 'POST', body }); | |
if (!response.ok) throw new Error(`Failed to upload audio: ${response.statusText}`); | |
const url = await response.text(); | |
const params = new URLSearchParams({ | |
title: `🎵 ${results.title}`, | |
description: `<audio controls src="${url}"></audio>\n${JSON.stringify(settings, null, 2)}`, | |
}); | |
const shareURL = `https://huggingface.co/spaces/enzostvs/ai-jukebox/discussions/new?${params.toString()}`; | |
window.open(shareURL, '_blank'); | |
} |