feat
This commit is contained in:
parent
4ff47f5cf2
commit
309b259515
20 changed files with 600 additions and 92 deletions
|
|
@ -93,6 +93,18 @@ export const paramDef = {
|
|||
deeplAuthKey: { type: 'string', nullable: true },
|
||||
deeplIsPro: { type: 'boolean' },
|
||||
hfAuthKey: { type: 'string', nullable: true },
|
||||
hfSpace: { type: 'boolean', default: false },
|
||||
hfSpaceName: { type: 'string', length: 1024, nullable: true },
|
||||
hfexampleAudioURL: { type: 'string', length: 1024, nullable: true },
|
||||
hfexampleText: { type: 'string', length: 1024, nullable: true },
|
||||
hfexampleLang: { type: 'string', length: 1024, nullable: true },
|
||||
hfslice: { type: 'string', length: 1024, default: 'Slice once every 4 sentences', nullable: true },
|
||||
hftopK: { type: 'integer', default: 15 },
|
||||
hftopP: { type: 'numeric', precision: 4, scale: 2, default: 1.00 },
|
||||
hfTemperature: { type: 'numeric', precision: 4, scale: 2, default: 1.00 },
|
||||
hfnrm: { type: 'boolean', default: false },
|
||||
hfSpeedRate: { type: 'numeric', precision: 4, scale: 2, default: 1.25 },
|
||||
hfdas: { type: 'boolean', default: false },
|
||||
enableEmail: { type: 'boolean' },
|
||||
email: { type: 'string', nullable: true },
|
||||
smtpSecure: { type: 'boolean' },
|
||||
|
|
@ -525,6 +537,74 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
set.hfAuthKey = ps.hfAuthKey;
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.hfSpace !== undefined) {
|
||||
set.hfSpace = ps.hfSpace;
|
||||
}
|
||||
|
||||
if (ps.hfSpaceName !== undefined) {
|
||||
if (ps.hfSpaceName === '') {
|
||||
set.hfSpaceName = null;
|
||||
} else {
|
||||
set.hfSpaceName = ps.hfSpaceName;
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.hfexampleAudioURL !== undefined) {
|
||||
if (ps.hfexampleAudioURL === '') {
|
||||
set.hfexampleAudioURL = null;
|
||||
} else {
|
||||
set.hfexampleAudioURL = ps.hfexampleAudioURL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.hfexampleText !== undefined) {
|
||||
if (ps.hfexampleText === '') {
|
||||
set.hfexampleText = null;
|
||||
} else {
|
||||
set.hfexampleText = ps.hfexampleText;
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.hfexampleLang !== undefined) {
|
||||
if (ps.hfexampleLang === '') {
|
||||
set.hfexampleLang = null;
|
||||
} else {
|
||||
set.hfexampleLang = ps.hfexampleLang;
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.hfslice !== undefined) {
|
||||
if (ps.hfslice === '') {
|
||||
set.hfslice = null;
|
||||
} else {
|
||||
set.hfslice = ps.hfslice;
|
||||
}
|
||||
}
|
||||
|
||||
if (ps.hftopK !== undefined) {
|
||||
set.hftopK = ps.hftopK;
|
||||
}
|
||||
|
||||
if (ps.hftopP !== undefined) {
|
||||
set.hftopP = ps.hftopP;
|
||||
}
|
||||
|
||||
if (ps.hfTemperature !== undefined) {
|
||||
set.hfTemperature = ps.hfTemperature;
|
||||
}
|
||||
|
||||
if (ps.hfnrm !== undefined) {
|
||||
set.hfnrm = ps.hfnrm;
|
||||
}
|
||||
|
||||
if (ps.hfSpeedRate !== undefined) {
|
||||
set.hfSpeedRate = ps.hfSpeedRate;
|
||||
}
|
||||
|
||||
if (ps.hfdas !== undefined) {
|
||||
set.hfdas = ps.hfdas;
|
||||
}
|
||||
|
||||
if (ps.enableIpLogging !== undefined) {
|
||||
set.enableIpLogging = ps.enableIpLogging;
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ export const paramDef = {
|
|||
preventAiLearning: { type: 'boolean' },
|
||||
isBot: { type: 'boolean' },
|
||||
isCat: { type: 'boolean' },
|
||||
isVI: { type: 'boolean' },
|
||||
injectFeaturedNote: { type: 'boolean' },
|
||||
receiveAnnouncementEmail: { type: 'boolean' },
|
||||
alwaysMarkNsfw: { type: 'boolean' },
|
||||
|
|
@ -323,6 +324,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (typeof ps.noCrawle === 'boolean') profileUpdates.noCrawle = ps.noCrawle;
|
||||
if (typeof ps.preventAiLearning === 'boolean') profileUpdates.preventAiLearning = ps.preventAiLearning;
|
||||
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
|
||||
if (typeof ps.isVI === 'boolean') updates.isVI = ps.isVI;
|
||||
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
|
||||
if (typeof ps.receiveAnnouncementEmail === 'boolean') profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
|
||||
if (typeof ps.alwaysMarkNsfw === 'boolean') {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Client } from "@gradio/client";
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||
import { MetaService } from '@/core/MetaService.js';
|
||||
|
|
@ -25,6 +26,11 @@ export const meta = {
|
|||
},
|
||||
|
||||
errors: {
|
||||
incorrectconfig: {
|
||||
message: 'Incorrect configuration.',
|
||||
code: 'INCORRECT_CONFIG',
|
||||
id: '8d171e60-83b8-11ef-b98c-a7506d6c1de4',
|
||||
},
|
||||
unavailable: {
|
||||
message: 'Convert of notes unavailable.',
|
||||
code: 'UNAVAILABLE',
|
||||
|
|
@ -85,29 +91,85 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw new ApiError(meta.errors.unavailable);
|
||||
}
|
||||
|
||||
const endpoint = 'https://api-inference.huggingface.co/models/suno/bark';
|
||||
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 slicelist = ['No slice', 'Slice once every 4 sentences', 'Slice per 50 characters', 'Slice by Chinese punct', 'Slice by English punct', 'Slice by every punct'];
|
||||
let exampleAudio;
|
||||
let app;
|
||||
|
||||
const res = await this.httpRequestService.send(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + instance.hfAuthKey,
|
||||
Accept: 'audio/flac, */*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
inputs: note.text,
|
||||
}),
|
||||
timeout: 60000,
|
||||
});
|
||||
try {
|
||||
const example = await fetch(instance.hfexampleAudioURL);
|
||||
exampleAudio = await example.blob();
|
||||
} catch {
|
||||
throw new ApiError(meta.errors.unavailable);
|
||||
}
|
||||
|
||||
let contentType = res.headers.get('Content-Type') || 'application/octet-stream';
|
||||
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))) {
|
||||
throw new ApiError(meta.errors.incorrectconfig);
|
||||
}
|
||||
|
||||
if (contentType === 'audio/flac') {
|
||||
return res.body;
|
||||
try {
|
||||
app = await Client.connect(instance.hfSpaceName, { hf_token: instance.hfAuthKey });
|
||||
} catch {
|
||||
throw new ApiError(meta.errors.unavailable);
|
||||
}
|
||||
|
||||
const result = await app.predict("/get_tts_wav", [
|
||||
exampleAudio,
|
||||
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;
|
||||
|
||||
const res = await this.httpRequestService.send(resurl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + instance.hfAuthKey,
|
||||
},
|
||||
timeout: 60000,
|
||||
});
|
||||
|
||||
let contentType = res.headers.get('Content-Type') || 'application/octet-stream';
|
||||
|
||||
if (contentType === 'audio/flac') {
|
||||
return res.body;
|
||||
} else {
|
||||
throw new ApiError(meta.errors.unavailable);
|
||||
}
|
||||
} else {
|
||||
throw new ApiError(meta.errors.unavailable);
|
||||
const endpoint = 'https://api-inference.huggingface.co/models/suno/bark';
|
||||
|
||||
const res = await this.httpRequestService.send(endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + instance.hfAuthKey,
|
||||
Accept: 'audio/flac, */*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
inputs: note.text,
|
||||
}),
|
||||
timeout: 60000,
|
||||
});
|
||||
|
||||
let contentType = res.headers.get('Content-Type') || 'application/octet-stream';
|
||||
|
||||
if (contentType === 'audio/flac') {
|
||||
return res.body;
|
||||
} else {
|
||||
throw new ApiError(meta.errors.unavailable);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue