feat: 正式增加语音模式支持

This commit is contained in:
ikechan8370 2023-03-04 22:06:09 +08:00
parent 41ca23dc85
commit 5ddeebfcc0
6 changed files with 124 additions and 25 deletions

View file

@ -5,6 +5,7 @@ import lodash from 'lodash'
import fs from 'node:fs'
import path from 'node:path'
import puppeteer from '../../../lib/puppeteer/puppeteer.js'
import {Config} from "./config.js";
// export function markdownToText (markdown) {
// return remark()
// .use(stripMarkdown)
@ -287,3 +288,11 @@ export async function render (e, pluginKey, htmlPath, data = {}, renderCfg = {})
}
return renderCfg.retType === 'msgId' ? ret : true
}
export function getDefaultUserSetting () {
return {
usePicture: Config.defaultUsePicture,
useTTS: Config.defaultUseTTS,
ttsRole: Config.defaultTTSRole
}
}

View file

@ -1,12 +1,13 @@
import fs from 'fs'
import lodash from 'lodash'
import { execSync } from 'child_process'
const defaultConfig = {
blockWords: ['屏蔽词1', '屏蔽词b'],
promptBlockWords: ['屏蔽词1', '屏蔽词b'],
imgOcr: true,
defaultUsePicture: false,
defaultUseTTS: false,
defaultTTSRole: '纳西妲',
autoUsePicture: true,
autoUsePictureThreshold: 1200,
conversationPreserveTime: 0,
@ -43,7 +44,7 @@ const defaultConfig = {
noiseScale: 0.6,
noiseScaleW: 0.668,
lengthScale: 1.2,
version: 'v2.0.17'
version: 'v2.0.18'
}
const _path = process.cwd()
let config = {}

View file

@ -1,5 +1,6 @@
import { Config } from './config.js'
import fetch from 'node-fetch'
import random from 'random'
let proxy
if (Config.proxy) {
try {
@ -24,7 +25,22 @@ const newFetch = (url, options = {}) => {
return fetch(url, mergedOptions)
}
const space = Config.ttsSpace
export async function generateAudio (text, speaker = '琪亚娜', language = '中文', noiseScale = Config.noiseScale, noiseScaleW = Config.noiseScaleW, lengthScale = Config.lengthScale) {
function randomNum (minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10)
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
default:
return 0
}
}
export async function generateAudio (text, speaker = '随机', language = '中文', noiseScale = Config.noiseScale, noiseScaleW = Config.noiseScaleW, lengthScale = Config.lengthScale) {
if (!speaker || speaker === '随机') {
logger.info('随机角色!这次哪个角色这么幸运会被选到呢……')
speaker = speakers[randomNum(0, speakers.length)]
}
logger.info(`正在使用${speaker},基于文本:'${text}'生成语音`)
let body = {
data: [
@ -43,6 +59,9 @@ export async function generateAudio (text, speaker = '琪亚娜', language = '
if (Config.debug) {
logger.info(json)
}
if (response.status > 299) {
logger.info(json)
}
let [message, audioInfo, take] = json?.data
logger.info(message, take)
let audioLink = `${space}/file=${audioInfo.name}`