mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 22:07:10 +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 SydneyAIClient from '../utils/SydneyAIClient.js'
|
||||||
import { PoeClient } from '../utils/poe/index.js'
|
import { PoeClient } from '../utils/poe/index.js'
|
||||||
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
||||||
|
import fs from 'fs'
|
||||||
import {
|
import {
|
||||||
render, renderUrl,
|
render, renderUrl,
|
||||||
getMessageById,
|
getMessageById,
|
||||||
|
|
@ -987,7 +988,7 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
let sendable = await uploadRecord(wav)
|
let sendable = await uploadRecord(wav, Config.ttsMode === 'azure')
|
||||||
if (sendable) {
|
if (sendable) {
|
||||||
await e.reply(sendable)
|
await e.reply(sendable)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1002,6 +1003,14 @@ export class chatgpt extends plugin {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
await this.reply('合成语音发生错误~')
|
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)) {
|
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
|
||||||
// todo use next api of chatgpt to complete incomplete respoonse
|
// todo use next api of chatgpt to complete incomplete respoonse
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,16 @@ let module
|
||||||
try {
|
try {
|
||||||
module = await import('oicq')
|
module = await import('oicq')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
try {
|
||||||
module = await import('icqq')
|
module = await import('icqq')
|
||||||
|
} catch (err1) {
|
||||||
|
// 可能是go-cqhttp之类的
|
||||||
}
|
}
|
||||||
const { core } = module
|
}
|
||||||
const Contactable = module.default
|
let pcm2slk, core, Contactable
|
||||||
// import { pcm2slk } from 'node-silk'
|
if (module) {
|
||||||
let errors = {}
|
core = module.core
|
||||||
let pcm2slk
|
Contactable = module.default
|
||||||
try {
|
try {
|
||||||
pcm2slk = (await import('node-silk')).pcm2slk
|
pcm2slk = (await import('node-silk')).pcm2slk
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -29,14 +32,18 @@ try {
|
||||||
logger.warn('未安装node-silk,如ffmpeg不支持amr编码请安装node-silk以支持语音模式')
|
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
|
let result
|
||||||
if (pcm2slk) {
|
if (pcm2slk) {
|
||||||
result = await getPttBuffer(recordUrl, Bot.config.ffmpeg_path)
|
result = await getPttBuffer(recordUrl, Bot.config.ffmpeg_path)
|
||||||
} else if (Config.cloudTranscode) {
|
} else if (Config.cloudTranscode) {
|
||||||
try {
|
try {
|
||||||
if (Config.cloudMode === 'file') {
|
if (forceFile || Config.cloudMode === 'file') {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
let buffer
|
let buffer
|
||||||
if (!recordUrl.startsWith('http')) {
|
if (!recordUrl.startsWith('http')) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue