ai-jukebox / utils /index.ts
enzostvs's picture
enzostvs HF staff
music generation
b162b24
raw
history blame
No virus
8.91 kB
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: "hiphop",
prompt: "hip hop track with a chill vibe",
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 with a chill vibe",
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 with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
label: "R&B",
image: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR3D-yMSiaEBtOOoxrKh8InCYzRqjn1UnYVHPhbDGkPrXH32k7i091MRvRTP7Nyts8dMJY&usqp=CAU"
}, {
value: "disco",
prompt: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
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: "jazz track with a chill vibe",
label: "Lofi",
image: "https://miro.medium.com/v2/resize:fit:1358/0*FjF2hZ8cJQN9aBxk.jpg"
}, {
value: "chill",
prompt: "jazz track with a chill vibe",
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: "happy",
label: "Happy",
prompt: "happy track with a chill vibe",
emoji: "😊"
}, {
value: "sad",
label: "Sad",
prompt: "sad track with a chill vibe",
emoji: "😢"
}, {
value: "angry",
label: "Angry",
prompt: "angry track with a chill vibe",
emoji: "😡"
}, {
value: "chill",
label: "Chill",
prompt: "chill track with a chill vibe",
emoji: "😌"
}, {
value: "romantic",
label: "Romantic",
prompt: "romantic track with a chill vibe",
emoji: "😍"
}, {
value: "epic",
label: "Epic",
prompt: "epic track with a chill vibe",
emoji: "🚀"
}, {
value: "energetic",
label: "Energetic",
prompt: "energetic track with a chill vibe",
emoji: "🔥"
}, {
value: "dreamy",
label: "Dreamy",
prompt: "dreamy track with a chill vibe",
emoji: "🌌"
}, {
value: "mysterious",
label: "Mysterious",
prompt: "mysterious track with a chill vibe",
emoji: "🕵️"
}, {
value: "relaxing",
label: "Relaxing",
prompt: "relaxing track with a chill vibe",
emoji: "😴"
}, {
value: "dark",
label: "Dark",
prompt: "dark track with a chill vibe",
emoji: "🖤"
}, {
value: "upbeat",
label: "Upbeat",
prompt: "upbeat track with a chill vibe",
emoji: "🎉"
}, {
value: "motivational",
label: "Motivational",
prompt: "motivational track with a chill vibe",
emoji: "💪"
}, {
value: "inspiring",
label: "Inspiring",
prompt: "inspiring track with a chill vibe",
emoji: "🌟"
}, {
value: "nostalgic",
label: "Nostalgic",
prompt: "nostalgic track with a chill vibe",
emoji: "📼"
}, {
value: "groovy",
label: "Groovy",
prompt: "groovy track with a chill vibe",
emoji: "🕺"
}, {
value: "melancholic",
label: "Melancholic",
prompt: "melancholic track with a chill vibe",
emoji: "😔"
}, {
value: "hopeful",
label: "Hopeful",
prompt: "hopeful track with a chill vibe",
emoji: "🌈"
}]
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';