fix: 适配无oicq&icqq;删除存储的azure语音

This commit is contained in:
ikechan8370 2023-04-23 21:01:03 +08:00
parent 1bfb4d7d6b
commit d5e3d52d43
2 changed files with 33 additions and 17 deletions

View file

@ -8,6 +8,7 @@ import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
import SydneyAIClient from '../utils/SydneyAIClient.js'
import { PoeClient } from '../utils/poe/index.js'
import AzureTTS from '../utils/tts/microsoft-azure.js'
import fs from 'fs'
import {
render, renderUrl,
getMessageById,
@ -987,7 +988,7 @@ export class chatgpt extends plugin {
}
try {
try {
let sendable = await uploadRecord(wav)
let sendable = await uploadRecord(wav, Config.ttsMode === 'azure')
if (sendable) {
await e.reply(sendable)
} else {
@ -1002,6 +1003,14 @@ export class chatgpt extends plugin {
logger.error(err)
await this.reply('合成语音发生错误~')
}
if (Config.ttsMode === 'azure' && Config.azureTTSKey) {
// 清理文件
try {
fs.unlinkSync(wav)
} catch (err) {
logger.warn(err)
}
}
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
// todo use next api of chatgpt to complete incomplete respoonse
try {

View file

@ -12,31 +12,38 @@ let module
try {
module = await import('oicq')
} catch (err) {
module = await import('icqq')
try {
module = await import('icqq')
} catch (err1) {
// 可能是go-cqhttp之类的
}
}
const { core } = module
const Contactable = module.default
// import { pcm2slk } from 'node-silk'
let errors = {}
let pcm2slk
try {
pcm2slk = (await import('node-silk')).pcm2slk
} catch (e) {
if (Config.cloudTranscode) {
logger.warn('未安装node-silk将尝试使用云转码服务进行合成')
} else {
Config.debug && logger.error(e)
logger.warn('未安装node-silk如ffmpeg不支持amr编码请安装node-silk以支持语音模式')
let pcm2slk, core, Contactable
if (module) {
core = module.core
Contactable = module.default
try {
pcm2slk = (await import('node-silk')).pcm2slk
} catch (e) {
if (Config.cloudTranscode) {
logger.warn('未安装node-silk将尝试使用云转码服务进行合成')
} else {
Config.debug && logger.error(e)
logger.warn('未安装node-silk如ffmpeg不支持amr编码请安装node-silk以支持语音模式')
}
}
}
async function uploadRecord (recordUrl) {
// import { pcm2slk } from 'node-silk'
let errors = {}
async function uploadRecord (recordUrl, forceFile) {
let result
if (pcm2slk) {
result = await getPttBuffer(recordUrl, Bot.config.ffmpeg_path)
} else if (Config.cloudTranscode) {
try {
if (Config.cloudMode === 'file') {
if (forceFile || Config.cloudMode === 'file') {
const formData = new FormData()
let buffer
if (!recordUrl.startsWith('http')) {