From 49af9dad80d04201c5048845f69032d5234c8a06 Mon Sep 17 00:00:00 2001 From: Xcating <82816129+Xcating@users.noreply.github.com> Date: Sun, 23 Apr 2023 13:58:35 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=96=B9=E5=BC=8F=20(#382)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9191ac..dc95ae9 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ pnpm i #### 设置相关 -> #chat切换浏览器/API/API2/API3/Bing +> #chatgpt切换浏览器/API/API2/API3/Bing > > #chatgpt设置[必应]Token > From 2cafdcaa82a174761a9f6782548c150c838b928d Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 23 Apr 2023 14:51:02 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20azure=E4=B8=8B=E4=BA=91=E8=BD=AC?= =?UTF-8?q?=E7=A0=81=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- guoba.support.js | 2 +- utils/uploadRecord.js | 40 +++++++++++++++------------------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/guoba.support.js b/guoba.support.js index f577e76..2fed161 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -577,7 +577,7 @@ export function supportGuoba () { options: [ { label: '文件', value: 'file' }, { label: '链接', value: 'url' }, - { label: '数据', value: 'buffer' } + // { label: '数据', value: 'buffer' } ] } }, diff --git a/utils/uploadRecord.js b/utils/uploadRecord.js index 6b3972d..9db7f39 100644 --- a/utils/uploadRecord.js +++ b/utils/uploadRecord.js @@ -1,6 +1,6 @@ // import Contactable, { core } from 'oicq' import querystring from 'querystring' -import fetch, { File } from 'node-fetch' +import fetch, { File, FormData } from 'node-fetch' import fs from 'fs' import os from 'os' import util from 'util' @@ -37,16 +37,22 @@ async function uploadRecord (recordUrl) { } else if (Config.cloudTranscode) { try { if (Config.cloudMode === 'buffer' || Config.cloudMode === 'file') { - let response = await fetch(recordUrl, { - method: 'GET', - headers: { - 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; MI 9 Build/SKQ1.211230.001)' - } - }) - if (Config.cloudMode === 'file') { + let buffer + if (!recordUrl.startsWith('http')) { + // 本地文件 + buffer = fs.readFileSync(recordUrl) + } else { + let response = await fetch(recordUrl, { + method: 'GET', + headers: { + 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; MI 9 Build/SKQ1.211230.001)' + } + }) const blob = await response.blob() const arrayBuffer = await blob.arrayBuffer() - const buffer = Buffer.from(arrayBuffer) + buffer = Buffer.from(arrayBuffer) + } + if (Config.cloudMode === 'file') { const formData = new FormData() formData.append('file', new File([buffer], 'audio.wav')) const resultres = await fetch(`${Config.cloudTranscode}/audio`, { @@ -60,22 +66,6 @@ async function uploadRecord (recordUrl) { logger.error(t) 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 { const resultres = await fetch(`${Config.cloudTranscode}/audio`, { From 1f50e1b7a572b8c524710104d2ad14f2573efadd Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 23 Apr 2023 15:26:15 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20azure=E8=AF=AD=E9=9F=B3=E4=BA=91?= =?UTF-8?q?=E8=BD=AC=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/uploadRecord.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/utils/uploadRecord.js b/utils/uploadRecord.js index 9db7f39..e1f90b7 100644 --- a/utils/uploadRecord.js +++ b/utils/uploadRecord.js @@ -1,6 +1,6 @@ // import Contactable, { core } from 'oicq' import querystring from 'querystring' -import fetch, { File, FormData } from 'node-fetch' +import fetch, { File, fileFromSync, FormData } from 'node-fetch' import fs from 'fs' import os from 'os' import util from 'util' @@ -36,11 +36,12 @@ async function uploadRecord (recordUrl) { result = await getPttBuffer(recordUrl, Bot.config.ffmpeg_path) } else if (Config.cloudTranscode) { try { - if (Config.cloudMode === 'buffer' || Config.cloudMode === 'file') { + if (Config.cloudMode === 'file') { + const formData = new FormData() let buffer if (!recordUrl.startsWith('http')) { // 本地文件 - buffer = fs.readFileSync(recordUrl) + formData.append('file', fileFromSync(recordUrl)) } else { let response = await fetch(recordUrl, { method: 'GET', @@ -51,21 +52,18 @@ async function uploadRecord (recordUrl) { const blob = await response.blob() const arrayBuffer = await blob.arrayBuffer() buffer = Buffer.from(arrayBuffer) - } - if (Config.cloudMode === 'file') { - const formData = new FormData() formData.append('file', new File([buffer], 'audio.wav')) - const resultres = await fetch(`${Config.cloudTranscode}/audio`, { - method: 'POST', - body: formData - }) - let t = await resultres.text() - try { - result = JSON.parse(t) - } catch (e) { - logger.error(t) - throw e - } + } + const resultres = await fetch(`${Config.cloudTranscode}/audio`, { + method: 'POST', + body: formData + }) + let t = await resultres.text() + try { + result = JSON.parse(t) + } catch (e) { + logger.error(t) + throw e } } else { const resultres = await fetch(`${Config.cloudTranscode}/audio`, { From 1bfb4d7d6b8b08d1b3860e2323165ca38eb41dec Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 23 Apr 2023 15:34:21 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E9=94=85=E5=B7=B4?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- guoba.support.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guoba.support.js b/guoba.support.js index 2fed161..cb66235 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -571,12 +571,12 @@ export function supportGuoba () { { field: 'cloudMode', label: '云转码API发送数据模式', - bottomHelpMessage: '默认发送数据链接,如果你部署的是本地服务,请改为文件', + bottomHelpMessage: '默认发送数据链接,如果你部署的是本地vits服务或使用的是微软azure,请改为文件', component: 'Select', componentProps: { options: [ { label: '文件', value: 'file' }, - { label: '链接', value: 'url' }, + { label: '链接', value: 'url' } // { label: '数据', value: 'buffer' } ] } From d5e3d52d43ff1d1e5358336a6715953bf5e41908 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 23 Apr 2023 21:01:03 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8D=E6=97=A0oicq&icqq?= =?UTF-8?q?=EF=BC=9B=E5=88=A0=E9=99=A4=E5=AD=98=E5=82=A8=E7=9A=84azure?= =?UTF-8?q?=E8=AF=AD=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 11 ++++++++++- utils/uploadRecord.js | 39 +++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index c6f7a3c..4051674 100644 --- a/apps/chat.js +++ b/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 { diff --git a/utils/uploadRecord.js b/utils/uploadRecord.js index e1f90b7..421d6a1 100644 --- a/utils/uploadRecord.js +++ b/utils/uploadRecord.js @@ -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')) { From 9e4049181ad839a0450914eb87ee9985f0f7778c Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 23 Apr 2023 21:09:11 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=E7=BB=93=E6=9D=9F=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E6=94=B9=E4=B8=BA(=E7=BB=93=E6=9D=9F|?= =?UTF-8?q?=E6=96=B0=E5=BC=80|=E6=91=A7=E6=AF=81|=E6=AF=81=E7=81=AD|?= =?UTF-8?q?=E5=AE=8C=E7=BB=93)=E5=AF=B9=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 4 ++-- apps/help.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index 4051674..e9f3e82 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -119,11 +119,11 @@ export class chatgpt extends plugin { permission: 'master' }, { - reg: '^#(chatgpt)?结束对话([sS]*)', + reg: '^#(chatgpt)?(结束|新开|摧毁|毁灭|完结)对话([sS]*)', fnc: 'destroyConversations' }, { - reg: '^#(chatgpt)?结束全部对话$', + reg: '^#(chatgpt)?(结束|新开|摧毁|毁灭|完结)全部对话$', fnc: 'endAllConversations', permission: 'master' }, diff --git a/apps/help.js b/apps/help.js index 23707ef..610b80b 100644 --- a/apps/help.js +++ b/apps/help.js @@ -38,17 +38,17 @@ let helpData = [ }, { icon: 'destroy', - title: '#结束对话', + title: '#(结束|新开|摧毁|毁灭|完结)对话', desc: '结束自己当前对话,下次开启对话机器人将遗忘掉本次对话内容。' }, { icon: 'destroy', - title: '#结束全部对话', + title: '#(结束|新开|摧毁|毁灭|完结)全部对话', desc: '结束正在与本机器人进行对话的全部用户的对话。' }, { icon: 'destroy-other', - title: '#结束对话 @某人', + title: '#(结束|新开|摧毁|毁灭|完结)对话 @某人', desc: '结束该用户当前对话,下次开启对话机器人将遗忘掉本次对话内容。' }, { @@ -104,7 +104,7 @@ let helpData = [ { icon: 'game', title: '#chatgpt设置语音角色', - desc: '设置语音模式下回复的角色音色' + desc: '设置语音模式下回复的角色音色。优先级高于默认语音角色' }, { icon: 'list',