Add suno cover stems concat (#165)
This commit is contained in:
1 parent
d3260816e2
commit
71434b50dc
42 files changed
+1386
-741
No files matched your search
@@ -76,7 +76,7 @@ export default defineComponent({
|
||||
if (!this.value) {
|
||||
this.value = undefined;
|
||||
}
|
||||
this.onSetVideoUrl();
|
||||
// this.onSetVideoUrl();
|
||||
},
|
||||
methods: {
|
||||
onExceed() {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<style-input v-if="config?.custom" class="mb-4" />
|
||||
<title-input v-if="config?.custom" class="mb-4" />
|
||||
<extend-from-input v-if="config?.action === 'extend'" class="mb-4" />
|
||||
<cover-from-input v-if="config?.action === 'cover'" class="mb-4" />
|
||||
<div class="actions">
|
||||
<el-button v-if="config?.action !== 'extend'" type="primary" class="btn w-full" round @click="onGenerate">
|
||||
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
|
||||
@@ -32,6 +33,7 @@ import LyricInput from './config/LyricInput.vue';
|
||||
import StyleInput from './config/StyleInput.vue';
|
||||
import TitleInput from './config/TitleInput.vue';
|
||||
import ExtendFromInput from './config/ExtendFromInput.vue';
|
||||
import CoverFromInput from './config/CoverFromInput.vue';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -43,6 +45,7 @@ export default defineComponent({
|
||||
StyleInput,
|
||||
TitleInput,
|
||||
ExtendFromInput,
|
||||
CoverFromInput,
|
||||
UploadAudio,
|
||||
FontAwesomeIcon,
|
||||
ElButton
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
<template>
|
||||
<div class="field">
|
||||
<div class="box">
|
||||
<h2 class="title">{{ $t('suno.name.cover') }}</h2>
|
||||
</div>
|
||||
<div class="task">
|
||||
<div class="audio" @click="onClick(audio)">
|
||||
<div v-loading="!audio?.audio_url || !audio?.video_url" class="left">
|
||||
<el-image :src="audio?.image_url" class="cover" fit="cover" />
|
||||
<div
|
||||
v-if="
|
||||
audio?.audio_url &&
|
||||
$store.state?.suno?.audio?.id === audio.id &&
|
||||
$store.state?.suno?.audio?.state === 'playing'
|
||||
"
|
||||
class="overlay"
|
||||
@click="onPause(audio)"
|
||||
>
|
||||
<el-icon><video-pause /></el-icon>
|
||||
</div>
|
||||
<div
|
||||
v-if="
|
||||
audio?.audio_url &&
|
||||
($store.state?.suno?.audio?.id !== audio.id ||
|
||||
($store.state?.suno?.audio?.id === audio.id && $store.state?.suno?.audio?.state === 'paused'))
|
||||
"
|
||||
class="overlay"
|
||||
@click="onPlay(audio)"
|
||||
>
|
||||
<el-icon><video-play /></el-icon>
|
||||
</div>
|
||||
<div v-if="audio?.duration" class="duration">
|
||||
{{ useFormatDuring(audio?.duration) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="info">
|
||||
<h2 class="title">{{ audio?.title }}</h2>
|
||||
<p class="style">{{ audio?.style }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useFormatDuring } from '@/utils/number';
|
||||
import { ISunoAudio } from '@/models';
|
||||
import { ElImage, ElIcon } from 'element-plus';
|
||||
import { VideoPlay, VideoPause } from '@element-plus/icons-vue';
|
||||
|
||||
export const DEFAULT_LYRIC = '';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CoverFromInput',
|
||||
components: {
|
||||
ElImage,
|
||||
ElIcon,
|
||||
VideoPlay,
|
||||
VideoPause
|
||||
},
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
computed: {
|
||||
// @ts-ignore
|
||||
audio() {
|
||||
// @ts-ignore
|
||||
return this.$store.state.suno?.config?.audio;
|
||||
},
|
||||
value: {
|
||||
get() {
|
||||
return this.$store.state.suno?.config?.continue_at;
|
||||
},
|
||||
set(val: string) {
|
||||
console.debug('set continue_at', val);
|
||||
this.$store.commit('suno/setConfig', {
|
||||
...this.$store.state.suno?.config,
|
||||
continue_at: val ? parseInt(val) : undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = undefined;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleChange(val: number) {
|
||||
if (val < 0) {
|
||||
this.value = 0;
|
||||
// @ts-ignore
|
||||
} else if (val > this.audio?.duration) {
|
||||
this.value = this.audio?.duration;
|
||||
} else {
|
||||
this.value = val;
|
||||
}
|
||||
},
|
||||
useFormatDuring,
|
||||
onPlay(audio: ISunoAudio) {
|
||||
this.$store.dispatch('suno/setAudio', {
|
||||
...this.$store.state.suno.audio,
|
||||
...audio,
|
||||
state: 'playing'
|
||||
});
|
||||
console.log('on play');
|
||||
},
|
||||
onPause(audio: ISunoAudio) {
|
||||
this.$store.dispatch('suno/setAudio', {
|
||||
...this.$store.state.suno.audio,
|
||||
...audio,
|
||||
state: 'paused'
|
||||
});
|
||||
console.log('on pause');
|
||||
},
|
||||
onClick(audio: ISunoAudio) {
|
||||
if (this.$store.state?.suno?.audio?.id !== audio.id) {
|
||||
this.onPlay({
|
||||
...audio,
|
||||
progress: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.field {
|
||||
.box {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between; // 添加这行
|
||||
position: relative;
|
||||
.title {
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.input-wrapper {
|
||||
width: 150px; // 根据需要调整宽度
|
||||
margin-left: 30px; // 增加左边距
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -66,6 +66,30 @@
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<el-dropdown>
|
||||
<span class="el-dropdown-link">
|
||||
<el-tooltip effect="dark" :content="$t('suno.button.more')" placement="top">
|
||||
<font-awesome-icon
|
||||
v-if="audio?.audio_url || audio?.video_url"
|
||||
icon="fa-solid fa-ellipsis"
|
||||
class="icon icon-ellipsis"
|
||||
/>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-if="audio?.video_url" @click="onGetStems($event, audio?.id)">
|
||||
{{ $t('suno.button.get_stems') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="audio?.action === 'extend'" @click="onCover($event, audio)">
|
||||
{{ $t('suno.button.cover_music') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="audio?.action === 'extend'" @click="onConcatMusic($event, audio?.id)">
|
||||
{{ $t('suno.button.concat_music') }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -75,10 +99,23 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { useFormatDuring } from '@/utils/number';
|
||||
import { ISunoAudio, ISunoTask } from '@/models';
|
||||
import { ElImage, ElIcon, ElTooltip, ElButton, ElDropdown, ElDropdownMenu, ElDropdownItem } from 'element-plus';
|
||||
import {
|
||||
ElImage,
|
||||
ElIcon,
|
||||
ElTooltip,
|
||||
ElButton,
|
||||
ElDropdown,
|
||||
ElDropdownMenu,
|
||||
ElDropdownItem,
|
||||
ElMessage
|
||||
} from 'element-plus';
|
||||
import { VideoPlay, VideoPause } from '@element-plus/icons-vue';
|
||||
import { ISunoAudioRequest, Status } from '@/models';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { sunoOperator } from '@/operators';
|
||||
|
||||
const CALLBACK_URL = 'https://webhook.acedata.cloud/suno';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'TaskPreview',
|
||||
@@ -104,14 +141,29 @@ export default defineComponent({
|
||||
return {};
|
||||
},
|
||||
computed: {
|
||||
loading() {
|
||||
return this.$store.state.suno?.status?.getApplications === Status.Request;
|
||||
},
|
||||
credential() {
|
||||
return this.$store.state.suno.credential;
|
||||
},
|
||||
config() {
|
||||
return this.$store.state.suno.config;
|
||||
},
|
||||
task() {
|
||||
return this.$store.state.suno?.tasks;
|
||||
},
|
||||
audios(): ISunoAudio[] {
|
||||
let result: ISunoAudio[] = [];
|
||||
// @ts-ignore
|
||||
const action = this.modelValue?.request?.action;
|
||||
if (Array.isArray(this.modelValue?.response?.data)) {
|
||||
this.modelValue?.response?.data?.forEach((item: any) => {
|
||||
let audio = item as ISunoAudio;
|
||||
// Add the action field to the audio object
|
||||
if (action) {
|
||||
audio.action = action;
|
||||
}
|
||||
result.push(audio);
|
||||
});
|
||||
}
|
||||
@@ -192,6 +244,79 @@ export default defineComponent({
|
||||
console.log('on preview', videoUrl);
|
||||
// preview url here
|
||||
window.open(videoUrl, '_blank');
|
||||
},
|
||||
async onGetStems(event: MouseEvent, audioId: string) {
|
||||
event.stopPropagation();
|
||||
console.log('on get stems', audioId);
|
||||
|
||||
await this.onGenerateAudioUrl('stems', audioId);
|
||||
},
|
||||
onCover(event: MouseEvent, audio: ISunoAudio) {
|
||||
event.stopPropagation();
|
||||
console.log('on cover');
|
||||
// download url here
|
||||
console.debug('set config', audio);
|
||||
this.$store.commit('suno/setConfig', {
|
||||
...this.$store.state.suno?.config,
|
||||
model: audio.model,
|
||||
custom: true,
|
||||
instrumental: false,
|
||||
style: audio.style,
|
||||
action: 'cover',
|
||||
audio: audio,
|
||||
audio_id: audio.id
|
||||
});
|
||||
},
|
||||
async onConcatMusic(event: MouseEvent, audioId: string) {
|
||||
event.stopPropagation();
|
||||
console.log('on get concat', audioId);
|
||||
await this.onGenerateAudioUrl('concat', audioId);
|
||||
},
|
||||
async onGenerateAudioUrl(action: string, audioId: string) {
|
||||
const request = {
|
||||
action,
|
||||
audio_id: audioId,
|
||||
callback_url: CALLBACK_URL
|
||||
} as ISunoAudioRequest;
|
||||
const token = this.credential?.token;
|
||||
if (!token) {
|
||||
console.error('no token specified');
|
||||
return;
|
||||
}
|
||||
ElMessage.info(this.$t('suno.message.startingTask'));
|
||||
sunoOperator
|
||||
.audio(request, {
|
||||
token
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success(this.$t('suno.message.startTaskSuccess'));
|
||||
})
|
||||
.catch((error) => {
|
||||
ElMessage.error(error?.response?.data?.error?.message || this.$t('suno.message.startTaskFailed'));
|
||||
})
|
||||
.finally(async () => {
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
});
|
||||
},
|
||||
async onScrollDown() {
|
||||
setTimeout(() => {
|
||||
// scroll to bottom for `.recent`
|
||||
const el = document.querySelector('.recent');
|
||||
if (el) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
async onGetTasks() {
|
||||
if (this.loading) {
|
||||
console.debug('loading');
|
||||
return;
|
||||
}
|
||||
await this.$store.dispatch('suno/getTasks', {
|
||||
limit: 30,
|
||||
offset: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user