fix: 支持huggingface的反代

This commit is contained in:
ikechan8370 2023-03-11 13:59:38 +08:00
parent 85809385c8
commit f0c43ca3cb
3 changed files with 22 additions and 3 deletions

View file

@ -344,6 +344,12 @@ export function supportGuoba () {
bottomHelpMessage: '前往duplicate空间https://huggingface.co/spaces/ikechan8370/vits-uma-genshin-honkai后查看api地址',
component: 'Input'
},
{
field: 'huggingFaceReverseProxy',
label: '语音转换huggingface反代',
bottomHelpMessage: '没有就空着',
component: 'Input'
},
{
field: 'noiseScale',
label: 'noiseScale',

View file

@ -51,11 +51,13 @@ const defaultConfig = {
defaultTimeoutMs: 120000,
chromeTimeoutMS: 120000,
ttsSpace: '',
// https://114514.201666.xyz
huggingFaceReverseProxy: '',
noiseScale: 0.6,
noiseScaleW: 0.668,
lengthScale: 1.2,
initiativeChatGroups: [],
version: 'v2.1.3'
version: 'v2.1.4'
}
const _path = process.cwd()
let config = {}

View file

@ -58,8 +58,12 @@ export async function generateAudio (text, speaker = '随机', language = '中
logger.warn(`vits api 当前为${space},已校正为${trimmedSpace}`)
space = trimmedSpace
}
logger.info(`正在使用接口${space}/api/generate`)
let response = await newFetch(`${space}/api/generate`, {
let url = `${space}/api/generate`
if (Config.huggingFaceReverseProxy) {
url = `${Config.huggingFaceReverseProxy}/api/generate?space=${_.trimStart(space, 'https://')}`
}
logger.info(`正在使用接口${url}`)
let response = await newFetch(url, {
method: 'POST',
body: JSON.stringify(body),
headers: {
@ -79,6 +83,13 @@ export async function generateAudio (text, speaker = '随机', language = '中
let [message, audioInfo, take] = json?.data
logger.info(message, take)
let audioLink = `${space}/file=${audioInfo.name}`
if (Config.huggingFaceReverseProxy) {
if (Config.debug) {
logger.info('使用huggingface加速反代下载生成音频' + Config.huggingFaceReverseProxy)
}
let spaceHost = _.trimStart(space, 'https://')
audioLink = `${Config.huggingFaceReverseProxy}/file=${audioInfo.name}?space=${spaceHost}`
}
return audioLink
} catch (err) {
logger.error('生成语音api发生错误请检查是否配置了正确的api且仓库是否开放为public', response.status)