mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
Merge branch 'v2' into v2
This commit is contained in:
commit
0daecc2edb
5 changed files with 68 additions and 64 deletions
|
|
@ -191,7 +191,7 @@ pnpm i
|
||||||
|
|
||||||
#### 设置相关
|
#### 设置相关
|
||||||
|
|
||||||
> #chat切换浏览器/API/API2/API3/Bing
|
> #chatgpt切换浏览器/API/API2/API3/Bing
|
||||||
>
|
>
|
||||||
> #chatgpt设置[必应]Token
|
> #chatgpt设置[必应]Token
|
||||||
>
|
>
|
||||||
|
|
|
||||||
15
apps/chat.js
15
apps/chat.js
|
|
@ -9,6 +9,7 @@ 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 VoiceVoxTTS from '../utils/tts/voicevox.js'
|
import VoiceVoxTTS from '../utils/tts/voicevox.js'
|
||||||
|
import fs from 'fs'
|
||||||
import {
|
import {
|
||||||
render, renderUrl,
|
render, renderUrl,
|
||||||
getMessageById,
|
getMessageById,
|
||||||
|
|
@ -119,11 +120,11 @@ export class chatgpt extends plugin {
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: '^#(chatgpt)?结束对话([sS]*)',
|
reg: '^#(chatgpt)?(结束|新开|摧毁|毁灭|完结)对话([sS]*)',
|
||||||
fnc: 'destroyConversations'
|
fnc: 'destroyConversations'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: '^#(chatgpt)?结束全部对话$',
|
reg: '^#(chatgpt)?(结束|新开|摧毁|毁灭|完结)全部对话$',
|
||||||
fnc: 'endAllConversations',
|
fnc: 'endAllConversations',
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
},
|
},
|
||||||
|
|
@ -1046,7 +1047,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 {
|
||||||
|
|
@ -1061,6 +1062,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 {
|
||||||
|
|
|
||||||
|
|
@ -38,17 +38,17 @@ let helpData = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'destroy',
|
icon: 'destroy',
|
||||||
title: '#结束对话',
|
title: '#(结束|新开|摧毁|毁灭|完结)对话',
|
||||||
desc: '结束自己当前对话,下次开启对话机器人将遗忘掉本次对话内容。'
|
desc: '结束自己当前对话,下次开启对话机器人将遗忘掉本次对话内容。'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'destroy',
|
icon: 'destroy',
|
||||||
title: '#结束全部对话',
|
title: '#(结束|新开|摧毁|毁灭|完结)全部对话',
|
||||||
desc: '结束正在与本机器人进行对话的全部用户的对话。'
|
desc: '结束正在与本机器人进行对话的全部用户的对话。'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'destroy-other',
|
icon: 'destroy-other',
|
||||||
title: '#结束对话 @某人',
|
title: '#(结束|新开|摧毁|毁灭|完结)对话 @某人',
|
||||||
desc: '结束该用户当前对话,下次开启对话机器人将遗忘掉本次对话内容。'
|
desc: '结束该用户当前对话,下次开启对话机器人将遗忘掉本次对话内容。'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -104,7 +104,7 @@ let helpData = [
|
||||||
{
|
{
|
||||||
icon: 'game',
|
icon: 'game',
|
||||||
title: '#chatgpt设置语音角色',
|
title: '#chatgpt设置语音角色',
|
||||||
desc: '设置语音模式下回复的角色音色'
|
desc: '设置语音模式下回复的角色音色。优先级高于默认语音角色'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'list',
|
icon: 'list',
|
||||||
|
|
|
||||||
|
|
@ -595,13 +595,13 @@ export function supportGuoba () {
|
||||||
{
|
{
|
||||||
field: 'cloudMode',
|
field: 'cloudMode',
|
||||||
label: '云转码API发送数据模式',
|
label: '云转码API发送数据模式',
|
||||||
bottomHelpMessage: '默认发送数据链接,如果你部署的是本地服务,请改为文件',
|
bottomHelpMessage: '默认发送数据链接,如果你部署的是本地vits服务或使用的是微软azure,请改为文件',
|
||||||
component: 'Select',
|
component: 'Select',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
options: [
|
options: [
|
||||||
{ label: '文件', value: 'file' },
|
{ label: '文件', value: 'file' },
|
||||||
{ label: '链接', value: 'url' },
|
{ label: '链接', value: 'url' }
|
||||||
{ label: '数据', value: 'buffer' }
|
// { label: '数据', value: 'buffer' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// import Contactable, { core } from 'oicq'
|
// import Contactable, { core } from 'oicq'
|
||||||
import querystring from 'querystring'
|
import querystring from 'querystring'
|
||||||
import fetch, { File } from 'node-fetch'
|
import fetch, { File, fileFromSync, FormData } from 'node-fetch'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import util from 'util'
|
import util from 'util'
|
||||||
|
|
@ -12,43 +12,55 @@ 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
|
let pcm2slk, core, Contactable
|
||||||
const Contactable = module.default
|
if (module) {
|
||||||
// import { pcm2slk } from 'node-silk'
|
core = module.core
|
||||||
let errors = {}
|
Contactable = module.default
|
||||||
let pcm2slk
|
try {
|
||||||
try {
|
|
||||||
pcm2slk = (await import('node-silk')).pcm2slk
|
pcm2slk = (await import('node-silk')).pcm2slk
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (Config.cloudTranscode) {
|
if (Config.cloudTranscode) {
|
||||||
logger.warn('未安装node-silk,将尝试使用云转码服务进行合成')
|
logger.warn('未安装node-silk,将尝试使用云转码服务进行合成')
|
||||||
} else {
|
} else {
|
||||||
Config.debug && logger.error(e)
|
Config.debug && logger.error(e)
|
||||||
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 === 'buffer' || Config.cloudMode === 'file') {
|
if (forceFile || Config.cloudMode === 'file') {
|
||||||
|
const formData = new FormData()
|
||||||
|
let buffer
|
||||||
|
if (!recordUrl.startsWith('http')) {
|
||||||
|
// 本地文件
|
||||||
|
formData.append('file', fileFromSync(recordUrl))
|
||||||
|
} else {
|
||||||
let response = await fetch(recordUrl, {
|
let response = await fetch(recordUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; MI 9 Build/SKQ1.211230.001)'
|
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; MI 9 Build/SKQ1.211230.001)'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (Config.cloudMode === 'file') {
|
|
||||||
const blob = await response.blob()
|
const blob = await response.blob()
|
||||||
const arrayBuffer = await blob.arrayBuffer()
|
const arrayBuffer = await blob.arrayBuffer()
|
||||||
const buffer = Buffer.from(arrayBuffer)
|
buffer = Buffer.from(arrayBuffer)
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('file', new File([buffer], 'audio.wav'))
|
formData.append('file', new File([buffer], 'audio.wav'))
|
||||||
|
}
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
|
|
@ -60,23 +72,6 @@ async function uploadRecord (recordUrl) {
|
||||||
logger.error(t)
|
logger.error(t)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const buf = Buffer.from(await response.arrayBuffer())
|
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ recordBuffer: buf })
|
|
||||||
})
|
|
||||||
let t = await resultres.text()
|
|
||||||
try {
|
|
||||||
result = JSON.parse(t)
|
|
||||||
} catch (e) {
|
|
||||||
logger.error(t)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue