mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 适配无oicq&icqq;删除存储的azure语音
This commit is contained in:
parent
1bfb4d7d6b
commit
d5e3d52d43
2 changed files with 33 additions and 17 deletions
11
apps/chat.js
11
apps/chat.js
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue