fix & enhance

This commit is contained in:
MomentQYC 2024-10-06 21:20:40 +08:00
parent 309b259515
commit 915588a5bc
5 changed files with 104 additions and 104 deletions

View File

@ -18,10 +18,10 @@ export class TTSIntegration1724683962000 {
await queryRunner.query(`ALTER TABLE "meta" ADD "hfexampleLang" character varying(128)`); await queryRunner.query(`ALTER TABLE "meta" ADD "hfexampleLang" character varying(128)`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hfslice" character varying(128) DEFAULT 'Slice once every 4 sentences'`); await queryRunner.query(`ALTER TABLE "meta" ADD "hfslice" character varying(128) DEFAULT 'Slice once every 4 sentences'`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hftopK" INTEGER DEFAULT 15`); await queryRunner.query(`ALTER TABLE "meta" ADD "hftopK" INTEGER DEFAULT 15`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hftopP" NUMERIC(4, 2) DEFAULT 1.00`); await queryRunner.query(`ALTER TABLE "meta" ADD "hftopP" INTEGER DEFAULT 100`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hfTemperature" NUMERIC(4, 2) DEFAULT 1.00`); await queryRunner.query(`ALTER TABLE "meta" ADD "hfTemperature" INTEGER DEFAULT 100`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hfnrm" boolean NOT NULL DEFAULT false`); await queryRunner.query(`ALTER TABLE "meta" ADD "hfnrm" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hfSpeedRate" NUMERIC(4, 2) DEFAULT 1.25`); await queryRunner.query(`ALTER TABLE "meta" ADD "hfSpeedRate" INTEGER DEFAULT 125`);
await queryRunner.query(`ALTER TABLE "meta" ADD "hfdas" boolean NOT NULL DEFAULT false`); await queryRunner.query(`ALTER TABLE "meta" ADD "hfdas" boolean NOT NULL DEFAULT false`);
} }

View File

@ -370,7 +370,7 @@ export class MiMeta {
length: 1024, length: 1024,
nullable: true, nullable: true,
}) })
public hfexampleAudioURL: string; public hfexampleAudioURL: string | null;
@Column('varchar', { @Column('varchar', {
length: 1024, length: 1024,
@ -382,41 +382,41 @@ export class MiMeta {
length: 1024, length: 1024,
nullable: true, nullable: true,
}) })
public hfexampleLang: string; public hfexampleLang: string | null;
@Column('varchar', { @Column('varchar', {
length: 1024, length: 1024,
default: 'Slice once every 4 sentences', default: 'Slice once every 4 sentences',
nullable: true, nullable: true,
}) })
public hfslice: string; public hfslice: string | null;
@Column('varchar', { @Column('integer', {
default: 15, default: 15,
}) })
public hftopK: number; public hftopK: number;
@Column('varchar', { @Column('integer', {
default: 1.00, default: 100,
}) })
public hftopP: number; public hftopP: number;
@Column('varchar', { @Column('integer', {
default: 1.00, default: 100,
}) })
public hfTemperature: number; public hfTemperature: number;
@Column('varchar', { @Column('boolean', {
default: false, default: false,
}) })
public hfnrm: boolean; public hfnrm: boolean;
@Column('varchar', { @Column('integer', {
default: 1.25, default: 125,
}) })
public hfSpeedRate: number; public hfSpeedRate: number;
@Column('varchar', { @Column('boolean', {
default: false, default: false,
}) })
public hfdas: boolean; public hfdas: boolean;

View File

@ -94,16 +94,16 @@ export const paramDef = {
deeplIsPro: { type: 'boolean' }, deeplIsPro: { type: 'boolean' },
hfAuthKey: { type: 'string', nullable: true }, hfAuthKey: { type: 'string', nullable: true },
hfSpace: { type: 'boolean', default: false }, hfSpace: { type: 'boolean', default: false },
hfSpaceName: { type: 'string', length: 1024, nullable: true }, hfSpaceName: { type: 'string', nullable: true },
hfexampleAudioURL: { type: 'string', length: 1024, nullable: true }, hfexampleAudioURL: { type: 'string', nullable: true },
hfexampleText: { type: 'string', length: 1024, nullable: true }, hfexampleText: { type: 'string', nullable: true },
hfexampleLang: { type: 'string', length: 1024, nullable: true }, hfexampleLang: { type: 'string', nullable: true },
hfslice: { type: 'string', length: 1024, default: 'Slice once every 4 sentences', nullable: true }, hfslice: { type: 'string', default: 'Slice once every 4 sentences', nullable: true },
hftopK: { type: 'integer', default: 15 }, hftopK: { type: 'integer', default: 15 },
hftopP: { type: 'numeric', precision: 4, scale: 2, default: 1.00 }, hftopP: { type: 'integer', default: 100 },
hfTemperature: { type: 'numeric', precision: 4, scale: 2, default: 1.00 }, hfTemperature: { type: 'integer', default: 100 },
hfnrm: { type: 'boolean', default: false }, hfnrm: { type: 'boolean', default: false },
hfSpeedRate: { type: 'numeric', precision: 4, scale: 2, default: 1.25 }, hfSpeedRate: { type: 'integer', default: 125 },
hfdas: { type: 'boolean', default: false }, hfdas: { type: 'boolean', default: false },
enableEmail: { type: 'boolean' }, enableEmail: { type: 'boolean' },
email: { type: 'string', nullable: true }, email: { type: 'string', nullable: true },

View File

@ -91,6 +91,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.unavailable); throw new ApiError(meta.errors.unavailable);
} }
let outofQuota;
if (instance.hfSpace) { if (instance.hfSpace) {
const langlist = ['Chinese', 'English', 'Japanese', 'Yue', 'Korean', 'Chinese-English Mixed', 'Japanese-English Mixed', 'Yue-English Mixed', 'Korean-English Mixed', 'Multilingual Mixed', 'Multilingual Mixed(Yue)']; const langlist = ['Chinese', 'English', 'Japanese', 'Yue', 'Korean', 'Chinese-English Mixed', 'Japanese-English Mixed', 'Yue-English Mixed', 'Korean-English Mixed', 'Multilingual Mixed', 'Multilingual Mixed(Yue)'];
const slicelist = ['No slice', 'Slice once every 4 sentences', 'Slice per 50 characters', 'Slice by Chinese punct', 'Slice by English punct', 'Slice by every punct']; const slicelist = ['No slice', 'Slice once every 4 sentences', 'Slice per 50 characters', 'Slice by Chinese punct', 'Slice by English punct', 'Slice by every punct'];
@ -98,13 +100,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
let app; let app;
try { try {
const example = await fetch(instance.hfexampleAudioURL); const example = await fetch(instance.hfexampleAudioURL || '');
exampleAudio = await example.blob(); exampleAudio = await example.blob();
} catch { } catch {
throw new ApiError(meta.errors.unavailable); throw new ApiError(meta.errors.unavailable);
} }
if (((!instance.hfnrm) && (!instance.hfexampleText)) || (!langlist.includes(instance.hfexampleLang)) || (!slicelist.includes(instance.hfslice)) || (!instance.hfSpaceName) || (!(instance.hfSpeedRate >= 0.6 && instance.hfSpeedRate <= 1.65)) || (!(instance.hfTemperature >= 0 && instance.hfTemperature <= 1)) || (!(instance.hftopK >= 0 && instance.hftopK <= 100)) || (!(instance.hftopP >= 0 && instance.hftopP <= 1))) { if (((!instance.hfnrm) && (!instance.hfexampleText)) || (!langlist.includes(instance.hfexampleLang || '')) || (!slicelist.includes(instance.hfslice || '')) || (!instance.hfSpaceName) || (!(instance.hfSpeedRate >= 60 && instance.hfSpeedRate <= 165)) || (!(instance.hfTemperature >= 0 && instance.hfTemperature <= 100)) || (!(instance.hftopK >= 0 && instance.hftopK <= 100)) || (!(instance.hftopP >= 0 && instance.hftopP <= 100))) {
throw new ApiError(meta.errors.incorrectconfig); throw new ApiError(meta.errors.incorrectconfig);
} }
@ -114,39 +116,60 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.unavailable); throw new ApiError(meta.errors.unavailable);
} }
const result = await app.predict("/get_tts_wav", [ let result;
exampleAudio, let notcontinue;
instance.hfexampleText,
instance.hfexampleLang,
note.text,
"Multilingual Mixed",
instance.hfslice,
instance.hftopK,
instance.hftopP,
instance.hfTemperature,
instance.hfnrm,
instance.hfSpeedRate,
instance.hfdas,
]);
let resurl = JSON.parse(result)[0].url; try {
result = await app.predict("/get_tts_wav", [
exampleAudio,
instance.hfexampleText,
instance.hfexampleLang,
note.text,
"Multilingual Mixed",
instance.hfslice,
instance.hftopK,
instance.hftopP / 100,
instance.hfTemperature / 100,
instance.hfnrm,
instance.hfSpeedRate / 100,
instance.hfdas,
]);
} catch (e) {
console.error("An error occurred during prediction:", e);
const res = await this.httpRequestService.send(resurl, { const responseMessage = (e as any).message || ((e as any).original_msg && (e as any).original_msg.message);
method: 'POST',
headers: {
'Authorization': 'Bearer ' + instance.hfAuthKey,
},
timeout: 60000,
});
let contentType = res.headers.get('Content-Type') || 'application/octet-stream'; if (responseMessage && responseMessage.includes('You have exceeded your GPU quota')) {
outofQuota = true;
if (contentType === 'audio/flac') { console.log("Fallback to Inference API");
return res.body; }
} else { notcontinue = true;
throw new ApiError(meta.errors.unavailable);
} }
} else {
if (!notcontinue) {
let resurl = result.data[0].url;
const res = await this.httpRequestService.send(resurl, {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + instance.hfAuthKey,
},
timeout: 60000,
});
let contentType = res.headers.get('Content-Type') || 'application/octet-stream';
console.log(contentType);
if (contentType === 'audio/x-wav') {
return res.body;
} else {
throw new ApiError(meta.errors.unavailable);
}
}
}
if ((!instance.hfSpace) || ((instance.hfSpace) && (outofQuota))) {
const endpoint = 'https://api-inference.huggingface.co/models/suno/bark'; const endpoint = 'https://api-inference.huggingface.co/models/suno/bark';
const res = await this.httpRequestService.send(endpoint, { const res = await this.httpRequestService.send(endpoint, {

View File

@ -40,16 +40,18 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkInput v-model="hfexampleAudioURL"> <MkInput v-model="hfexampleAudioURL">
<template #label>Example Audio URL</template> <template #label>Example Audio URL</template>
</MkInput> </MkInput>
<br />
<MkSwitch v-model="hfnrm"> <MkSwitch v-model="hfnrm">
<template #label>Enable no reference mode</template> <template #label>Enable no reference mode</template>
</MkSwitch> </MkSwitch>
<br />
<div v-if="!hfnrm"> <div v-if="!hfnrm">
<MkInput v-model="hfexampleText"> <MkInput v-model="hfexampleText">
<template #label>Example Text</template> <template #label>Example Text</template>
</MkInput> </MkInput>
</div> </div>
<label for="exampleLanguage">Example Language</label> <MkSelect v-model="hfexampleLang">
<select v-model="hfexampleLang" id="exampleLanguage"> <template #label>Example Language</template>
<option value="" disabled> </option> <option value="" disabled> </option>
<option value="Chinese">中文</option> <option value="Chinese">中文</option>
<option value="English">English</option> <option value="English">English</option>
@ -62,12 +64,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<option value="Korean-English Mixed">한국어 - English</option> <option value="Korean-English Mixed">한국어 - English</option>
<option value="Multilingual Mixed">Multilingual Mixed</option> <option value="Multilingual Mixed">Multilingual Mixed</option>
<option value="Multilingual Mixed(Yue)">Multilingual Mixed (Yue)</option> <option value="Multilingual Mixed(Yue)">Multilingual Mixed (Yue)</option>
</select> </MkSelect>
<br />
<MkSwitch v-model="hfdas"> <MkSwitch v-model="hfdas">
<template #label>Whether to directly adjust the speech rate and timebre of the last synthesis result to prevent randomness</template> <template #label>Whether to directly adjust the speech rate and timebre of the last synthesis result to prevent randomness</template>
</MkSwitch> </MkSwitch>
<label for="ttsslice">Slice</label> <br />
<select v-model="hfslice" id="ttsslice"> <MkSelect v-model="hfslice">
<template #label>Slice</template>
<option value="" disabled> </option> <option value="" disabled> </option>
<option value="No slice">No slice</option> <option value="No slice">No slice</option>
<option value="Slice once every 4 sentences">Slice once every 4 sentences</option> <option value="Slice once every 4 sentences">Slice once every 4 sentences</option>
@ -75,47 +79,19 @@ SPDX-License-Identifier: AGPL-3.0-only
<option value="Slice by Chinese punct">Slice by Chinese punct</option> <option value="Slice by Chinese punct">Slice by Chinese punct</option>
<option value="Slice by English punct">Slice by English punct</option> <option value="Slice by English punct">Slice by English punct</option>
<option value="Slice by every punct">Slice by every punct</option> <option value="Slice by every punct">Slice by every punct</option>
</select> </MkSelect>
<label>Set top_k Value: {{ value }}</label> <MkInput type="range" v-model.number="hftopK" :min="0" :max="100" :step="1">
<input <template #label>Set top_k Value: {{ hftopK }}</template>
type="range" </MkInput>
v-model="hftopK" <MkInput type="range" v-model.number="hftopP" :min="0" :max="100" :step="5">
:value="value = 15" <template #label>Set top_p Value: {{ hftopP }}</template>
:min="0" </MkInput>
:max="100" <MkInput type="range" v-model.number="hfTemperature" :min="0" :max="100" :step="5">
:step="1" <template #label>Set Temperature Value: {{ hfTemperature }}</template>
@input="value" </MkInput>
/> <MkInput type="range" v-model.number="hfSpeedRate" :min="60" :max="165" :step="5">
<label>Set top_p Value: {{ value.toFixed(2) }}</label> <template #label>Set Speed Rate Value: {{ hfSpeedRate }}</template>
<input </MkInput>
type="range"
v-model="hftopP"
:value="value = 1"
:min="0"
:max="1"
:step="0.05"
@input="value = (Math.round(event.target.value / step) * step).toFixed(2)"
/>
<label>Set Temperature Value: {{ value.toFixed(2) }}</label>
<input
type="range"
v-model="hfTemperature"
:value="value = 1"
:min="0"
:max="1"
:step="0.05"
@input="value = (Math.round(event.target.value / step) * step).toFixed(2)"
/>
<label>Set Speed Rate Value: {{ value.toFixed(2) }}</label>
<input
type="range"
v-model="hfSpeedRate"
:value="value = 1.2"
:min="0.6"
:max="1.65"
:step="0.05"
@input="value = (Math.round(event.target.value / step) * step).toFixed(2)"
/>
</div> </div>
<MkButton primary @click="save_tts">Save</MkButton> <MkButton primary @click="save_tts">Save</MkButton>
</div> </div>
@ -130,6 +106,7 @@ import { ref, computed } from 'vue';
import XHeader from './_header_.vue'; import XHeader from './_header_.vue';
import MkInput from '@/components/MkInput.vue'; import MkInput from '@/components/MkInput.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import MkSelect from '@/components/MkSelect.vue';
import MkSwitch from '@/components/MkSwitch.vue'; import MkSwitch from '@/components/MkSwitch.vue';
import FormSuspense from '@/components/form/suspense.vue'; import FormSuspense from '@/components/form/suspense.vue';
import * as os from '@/os.js'; import * as os from '@/os.js';
@ -149,10 +126,10 @@ const hfexampleText = ref<string | null>(null);
const hfexampleLang = ref<string | null>(null); const hfexampleLang = ref<string | null>(null);
const hfslice = ref<string | null>('Slice once every 4 sentences'); const hfslice = ref<string | null>('Slice once every 4 sentences');
const hftopK = ref<number>(15); const hftopK = ref<number>(15);
const hftopP = ref<number>(1.00); const hftopP = ref<number>(100);
const hfTemperature = ref<number>(1.00); const hfTemperature = ref<number>(100);
const hfnrm = ref<boolean>(false); const hfnrm = ref<boolean>(false);
const hfSpeedRate = ref<number>(1.25); const hfSpeedRate = ref<number>(125);
const hfdas = ref<boolean>(false); const hfdas = ref<boolean>(false);
@ -172,7 +149,7 @@ async function init() {
hfTemperature.value = meta.hfTemperature, hfTemperature.value = meta.hfTemperature,
hfnrm.value = meta.hfnrm, hfnrm.value = meta.hfnrm,
hfSpeedRate.value = meta.hfSpeedRate, hfSpeedRate.value = meta.hfSpeedRate,
hfdas.value = meta.hfdas, hfdas.value = meta.hfdas
} }
function save_deepl() { function save_deepl() {